View source: R/simulate_ou_model.R
simulate_ou_model | R Documentation |
Given a rooted phylogenetic tree and an Ornstein-Uhlenbeck (OU) model for the evolution of a continuous (numeric) trait, simulate random outcomes of the model on all nodes and/or tips of the tree. The function traverses nodes from root to tips and randomly assigns a state to each node or tip based on its parent's previously assigned state and the specified model parameters. The generated states have joint distributions consistent with the OU model. Optionally, multiple independent simulations can be performed using the same model.
simulate_ou_model(tree, stationary_mean, stationary_std, decay_rate,
include_tips=TRUE, include_nodes=TRUE,
Nsimulations=1, drop_dims=TRUE)
tree |
A rooted tree of class "phylo". The root is assumed to be the unique node with no incoming edge. |
stationary_mean |
Numeric. The mean (center) of the stationary distribution of the OU model. |
stationary_std |
Positive numeric. The standard deviation of the stationary distribution of the OU model. |
decay_rate |
Positive numeric. Exponential decay rate (stabilization rate) of the OU model (in units 1/edge_length_units). |
include_tips |
Include random states for the tips. If |
include_nodes |
Include random states for the nodes. If |
Nsimulations |
Number of random independent simulations to perform. For each node and/or tip, there will be |
drop_dims |
Logical, specifying whether the returned |
For each simulation, the state of the root is picked randomly from the stationary distribution of the OU model, i.e. from a normal distribution with mean = stationary_mean
and standard deviation = stationary_std
.
If tree$edge.length
is missing, each edge in the tree is assumed to have length 1. The tree may include multi-furcations (i.e. nodes with more than 2 children) as well as mono-furcations (i.e. nodes with only one child). The asymptotic time complexity of this function is O(Nedges*Nsimulations), where Nedges is the number of edges in the tree.
A list with the following elements:
tip_states |
Either |
node_states |
Either |
Stilianos Louca
simulate_bm_model
, simulate_mk_model
, simulate_rou_model
# generate a random tree
tree = generate_random_tree(list(birth_rate_intercept=1),max_tips=10000)$tree
# simulate evolution of a continuous trait
tip_states = simulate_ou_model( tree,
stationary_mean = 10,
stationary_std = 1,
decay_rate = 0.1)$tip_states
# plot histogram of simulated tip states
hist(tip_states, breaks=20, xlab="state", main="Trait probability distribution", prob=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.