link.traits {treats} | R Documentation |
link.traits
Description
Linking traits objects together to simulate simulate them sequentially.
Usage
link.traits(base.trait, next.trait, link.type, link.args, trait.name)
Arguments
base.trait |
One or more |
next.trait |
One or more |
link.type |
The type of link between the traits. Can be |
link.args |
Optional arguments to interpret the link between the objects (based on the |
trait.name |
Optional, a |
Details
This function allows to link several traits together in the simulations. The current link types implemented are:
"conditional": this allows to link the
next.trait
traits conditionally to thebase.trait
one. For example ifbase.trait
is adiscrete.process
with two states0
and1
andnext.trait
is a list of two traits with two different processesOU.process
andBM.process
. The simulations generates a first trait usingbase.trait
and then a second one using one of the two processes innext.trait
depending on the results ofbase.trait
. The link argumentslink.args
must be a list of logical functions to interpretx1
, the results of thebase.trait
. For example,list(function(x1){x1 == 0}, function(x1){x1 == 1})
will generate a trait using the firstnext.trait
ifx1
is equal to0
or using the secondnext.trait
ifx1
is equal to1
.
Value
This function outputs a treats
object that is a named list of elements handled internally by the treats
function.
Author(s)
Thomas Guillerme
See Also
treats
trait.process
make.traits
Examples
## Setting up a discrete trait
discrete_trait <- make.traits(discrete.process,
process.args = list(transitions = matrix(c(3, 0.2, 0.05, 3), 2, 2)),
trait.names = "discrete")
## Setting up one dummy trait (always outputs 1)
always_one <- make.traits(process = function(x0 = 0, edge.length = 1) {return(1)},
trait.names = "one")
## Setting up a Brownian motion trait
BM_trait <- make.traits(trait.names = "BM")
## Setting a condition list to link all traits
## (if discrete trait is 0, simulate a BM trait)
## (if discrete trait is 1, simulate the always one trait)
conditions <- list("choose.BM" = function(x1) {x1 == 0},
"choose.one" = function(x1) {x1 == 1})
## Creating the linked trait
conditional <- link.traits(base.trait = discrete_trait,
next.trait = list(BM_trait, always_one),
link.type = "conditional",
link.args = conditions)
## Simulating a tree using this trait
treats(stop.rule = list(max.living = 200),
traits = conditional)