Skip to contents

Function to simulate continuous trait value histories on a phylogeny.

Usage

simulate_traits(
  phy,
  rate_model = c("continuous", "discrete"),
  temp_trend_rates = 0,
  rate_change,
  rates = NULL,
  anc = c(`1` = 0),
  internal = FALSE,
  nsim = 1,
  pos_strat = c("none", "log", "add_const"),
  temp_trend_mean = 0
)

Arguments

phy

A phylogenetic tree (phylo object) on which to simulate traits

rate_model

The type of rate model for how rates of evolution evolve on the phylogeny: "continuous" for continuous Brownian motion evolution of rates, or "discrete" for evolution of rate "classes" across the phylogeny, using an mk model.

temp_trend_rates

What temporal trend in rates should there be? A positive number for an increase, and negative number for a decrease with the magnitude controlling the strength of linear change. This trend is added to rates simulated under the rate_model.

rate_change

If rate_model is "continuous", this should be a single positive number controlling how fast rates change continuously along the tree. If rate_model is "discrete", this should be a transition matrix for the rate classes. Or, if rate_model is "discrete", and this can be a length 2 numeric vector specifying

rates

Only used if rate_model is "discrete", in which case this should be a named vector whose values are the rates in each rate class, and whose names are the rate class states (e.g. c("1" = 3, "2" = 10)). See sim.history, for more detail on how the discrete model works. Or, if an unnamed numeric vector of length two, a mean and standard deviation parameterizing a normal distribution from which to draw rates for each rate class. If NULL, rates will be drawn from a normals distribution with mean = 0 and sd = 1.

anc

Value of the trait at the root ancestor. For rate_model = "discrete", can be a length 1 named vector where the name is the ancestral state, and the value is the trait starting value. For rate_model = "continuous", any names are ignored, but should be length 2, where the first element is the ancestral trait value and the second element is the ancestral rate of evolution.

internal

Logical value. If TRUE return trait states at internal nodes.

nsim

Number of simulation to run.

pos_strat

?

temp_trend_mean

A temporal trend in rates.

Value

A vector or matrix (for nsim > 1) containing simulated trait values for each tip if internal = FALSE, or for each node if internal = TRUE