Skip to content

Example 1: Getting Started

Eric W. Goolsby edited this page May 11, 2016 · 4 revisions

Multivariate Brownian motion with missing data (no within-species variation)

First we demonstrate fitting a simple Brownian motion model on a dataset with 20 species and 3 traits, simulated with the simtraits function. We simulate trait evolution with covariance stored in the variable trait_cov and phylogenetic tree stored in the variable tree. We also simulate randomly missing data by removing 10 values at random by setting nmissing = 10.

library(phytools) # for simulating pure-birth phylogenies
set.seed(21) # Set the seed for reproducible results
trait_cov <- matrix(c(4,2,2.2,2,3,1.5,2.2,1.5,2.5),nrow = 3,ncol = 3)
trait_cov # Phylogenetic trait covariance
tree <- pbtree(n = 20)
sim_data <- simtraits(v = trait_cov,tree = tree,nmissing = 10)

The function simtraits returns a list with 4 elements: trait_data (a data frame with species names in the first column, and trait values in the remaining columns), tree (the phylogenetic tree), sim_tree (the phylogenetic tree transformed according to the evolutionary model on which simulations were performed; if model="BM", sim_tree and tree are identical), and original_X (the original species trait values, prior to removing any observations).

sim_data$trait_data # Note that 10 observations are missing completely at random

The simtraits function automatically generates a pure-birth phylogeny with ntaxa species (via the pbtree function in phytools) if the tree argument is left empty. Likewise, simtraits also automatically simulates Brownian motion evolution under random covariance among ntaxa traits if the argument v is left empty.

Finally, fit the multivariate Brownian motion model using the phylopars function:

p_BM <- phylopars(trait_data = sim_data$trait_data,tree = sim_data$tree)
p_BM # Estimated trait covariance
trait_cov # Simulated trait covariance

We can see that the trait covariance estimated by phylopars is reasonably close to our simulation parameters (trait_cov).

Proceed to Example 2: Missing Data Imputation and Ancestral State Reconstruction.


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.