| link.traits | R Documentation |
Linking traits objects together to simulate simulate them sequentially.
link.traits(base.trait, next.trait, link.type, link.args, trait.name)
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 |
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 the base.trait one. For example if base.trait is a discrete.process with two states 0 and 1 and next.trait is a list of two traits with two different processes OU.process and BM.process. The simulations generates a first trait using base.trait and then a second one using one of the two processes in next.trait depending on the results of base.trait. The link arguments link.args must be a list of logical functions to interpret x1, the results of the base.trait. For example, list(function(x1){x1 == 0}, function(x1){x1 == 1}) will generate a trait using the first next.trait if x1 is equal to 0 or using the second next.trait if x1 is equal to 1.
This function outputs a treats object that is a named list of elements handled internally by the treats function.
Thomas Guillerme
treats trait.process make.traits
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.