sim.char: simulate character evolution

Description Usage Arguments Details Value Author(s) Examples

View source: R/simulation.R

Description

simulating evolution of discrete or continuous characters on a phylogenetic tree

Usage

1
sim.char(phy, par, nsim = 1, model = c("BM", "speciational", "discrete"), root = 1)

Arguments

phy

a phylogenetic tree of class 'phylo'

par

matrix describing model (either vcv matrix or Q matrix)

nsim

number of simulations to run

model

a model from which to simulate data

root

starting state (value) at root

Details

This function simulates either discrete or continuous data on a phylogenetic tree. The model variable determines the type of simulation to be run. There are three options: discrete, which evolves characters under a continuous time Markov model, and two continuous models, BM and speciational. The BM model is a constant rate Brownian-motion model, while speciational is a Brownian model on a tree where all branches have the same length. The model.matrix parameter gives the structure of the model, and should be either a transition matrix, Q, for the discrete model, or a trait variance-covariance matrix for BM or speciational models. For discrete models, multiple characters may be simulated if model.matrix is given as a list of Q matrices (see Examples). For continuous models, multivariate characters can be simulated, with their evolution goverened by a covariance matrix specified in the model.matrix.

Value

An array of simulated data, either two or three-dimensional, is returned. The first dimension is the number of taxa, the second the number of characters, and the third the number of simulated data sets.

Author(s)

LJ Harmon

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
geo <- get(data(geospiza))

## Continuous character -- univariate
usims <- sim.char(geo$phy, 0.02, 100)

## Use a simulated dataset in fitContinuous()
fitC <- fitContinuous(geo$phy, usims[,,1], model="BM", control=list(niter=10), ncores=2)

## Continuous character -- multivariate
s <- ratematrix(geo$phy, geo$dat)
csims <- sim.char(geo$phy, s, 100)

## Discrete character -- univariate
q <- list(rbind(c(-.5, .5), c(.5, -.5)))
dsims <- sim.char(geo$phy, q, model="discrete", n=10)

## Use a simulated dataset in fitDiscrete()
fitD <- fitDiscrete(geo$phy, dsims[,,1], model="ER", niter=10, ncores=2)

## Discrete character -- multivariate
qq <- list(rbind(c(-.5, .5), c(.5, -.5)), rbind(c(-.05, .05), c(.05, -.05)))
msims <- sim.char(geo$phy, qq, model="discrete", n=10)

  

geiger documentation built on July 8, 2020, 7:12 p.m.