parent.traits: Get parent traits

View source: R/utilities.R

parent.traitsR Documentation

Get parent traits

Description

An internal utility function for modifiers, traits or events to access the value(s) of the parent traits in the treats algorithm

Usage

parent.traits(trait.values, lineage, current = TRUE)

Arguments

trait.values

The internal table of trait values

lineage

The internal lineage data list

current

Whether to consider only the current lineage (TRUE - default) or all the living lineages (FALSE).

Details

This function is designed to be used internally in treats to help modifiers, traits or events objects to access the parent traits of the lineages simulated through the internal birth death algorithm.

Value

Returns one or more "numeric" values.

Author(s)

Thomas Guillerme

See Also

treats make.modifiers

Examples

## Speciation event is more likely if lineage's ancestor is further away from the mean trait value
distance.modify <- function(x, trait.values, lineage) {
     ## Distance to the parent's trait
     parent_trait_val <- parent.traits(trait.values, lineage)[1]
     mean_trait_val <- mean(trait.values[, 1])
     distance <- abs(parent_trait_val - mean_trait_val)
     ## Scales x with the distance
     return(x + x * distance)
}

## Make a distance modifier (speciation more likely with distance)
distance.speciation <- make.modifiers(speciation = speciation,
                                      modify = distance.modify)


treats documentation built on Nov. 24, 2023, 5:08 p.m.

Related to parent.traits in treats...