link.traits: link.traits

View source: R/link.traits.R

link.traitsR 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 "treats" "traits" object(s) to be considered first.

next.trait

One or more "treats" "traits" object(s) to be considered sequentially.

link.type

The type of link between the traits. Can be "conditional".

link.args

Optional arguments to interpret the link between the objects (based on the link.type).

trait.name

Optional, a character, the name the resulting trait.

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 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.

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)


treats documentation built on June 8, 2025, 1:43 p.m.

Related to link.traits in treats...