Last data update: 2014.03.03

R: Simulate data on a phylogeny under a (multivariate) Brownian...
simulBMProcPhylTreeR Documentation

Simulate data on a phylogeny under a (multivariate) Brownian motion model

Description

Simulate data on a phylogeny under a (multivariate) Brownian motion model

Usage

simulBMProcPhylTree(phyltree, X0, Sigma, dropInternal = TRUE, M.error=NULL, 
fullTrajectory=FALSE, jumpsetup=NULL)

Arguments

phyltree

The phylogeny in ouch format. All of the internal nodes have to be uniquely named. The tree can be obtained from e.g. a nexus file by the read.nexus function from the ape package and converted into the ouch format by ouch's ape2ouch function. See the example of how to correct the internal nodes.

X0

The ancestral, root state.

Sigma

The diffusion matrix of the Brownian motion.

dropInternal

Logical whether the simulated values at the internal nodes be changed to NA or not.

M.error

An optional measurement error covariance matrix. The program tries to recognizes the structure of matrix passed and accepts the following possibilities :

  • a single number that will be on the diagonal of the covariance matrix

  • a m element vector with each value corresponding to a variable and the covariance matrix will have that vector repeated on its diagonal,

  • a nxm element vector a diagonal matrix with this vector on the diagonal,

  • a m x m ((number of variables) x (number of variables)) matrix it is assumed that the measurement errors are independent between observations so the resulting covariance structure is block diagonal,

  • a list of length m (number of variables), each list element is the covariance structure for the appropriate variable, either a single number (each observations has same variance), vector (of length n for each observation), or full matrix,

  • matrix of size mn x mn (m - number of variables, n - number of observations) the measurement error covaraince provided as is,

  • NULL no measurement error

fullTrajectory

Should the full realization of the process or only node and tip values be returned

jumpsetup

Either NULL or list describing the jump at speciation. In the second case:

  • jumptypeIn what way does the jump take place. Possible values are "ForBoth" the jump occurs at speciation and is common to both daughter lineages, "RandomLineage" the jump occurs just after speciation affecting exactly one daughter lineage, both desceding branches have the same chance of being affected, "JumpWithProb" the jump occurs with probability jumpprob just after speciation independently on each daughter lineage independently.

  • jumpprobA value in [0,1] indictating the probability of a jump taking place, only matters if jumptype is "JumpWithProb" or "JumpWithProb".

  • jumpdistribThe distribution of the jump, currently only can take value "Normal".

  • vMeanThe expected value of the jump, a vector of appropriate length if the trait is multivariate.

  • mCovThe variance of the jump, a matrix of appropriate dimensions if the trait is multivariate.

Value

If fullTrajectory is FALSE then returns a data.frame with each row corresponding to a tree node and each column to a trait. Otherwise returns a more complex object describing the full realization of the process on the tree. If dropInternal is TRUE then the entries for the internal nodes are changed to NAs.

Author(s)

Krzysztof Bartoszek

References

Bartoszek, K. (2014) Quantifying the effects of anagenetic and cladogenetic evolution. Mathematical Biosciences 254:42-57.

Bartoszek, K. and Pienaar, J. and Mostad. P. and Andersson, S. and Hansen, T. F. (2012) A phylogenetic comparative method for studying multivariate adaptation. Journal of Theoretical Biology 314:204-215.

Butler, M.A. and A.A. King (2004) Phylogenetic comparative analysis: a modeling approach for adaptive evolution. American Naturalist 164:683-695.

Felsenstein, J. (1985) Phylogenies and the comparative method. American Naturalist 125:1-15.

Hansen, T.F. and Bartoszek, K. (2012) Interpreting the evolutionary regression: the interplay between observational and biological errors in phylogenetic comparative studies. Systematic Biology 61(3):413-425.

Pienaar et al (in prep) An overview of comparative methods for testing adaptation to external environments.

See Also

BrownianMotionModel, SummarizeBM

Examples

## Not run:  ##It takes too long to run this
### We will first simulate a small phylogenetic tree using functions from ape and ouch.
### For simulating the tree one could also use alternative functions, eg. sim.bd.taxa 
### from the TreeSim package
phyltree<-ape2ouch(rtree(5))

### Correct the names of the internal node labels.
phyltree@nodelabels[1:(phyltree@nnodes-phyltree@nterm)]<-as.character(
1:(phyltree@nnodes-phyltree@nterm))

### Define Brownian motion parameters to be able to simulate data 
### under the Brownian motion model.
BMparameters<-list(vX0=matrix(0,nrow=3,ncol=1),
Sxx=rbind(c(1,0,0),c(0.2,1,0),c(0.3,0.25,1)))

### Now simulate the data and remove the values corresponding to the internal nodes.
jumpobj<-list(jumptype="RandomLineage",jumpprob=0.5,jumpdistrib="Normal",
vMean=rep(0,3),mCov=diag(1,3,3))
BMdata<-simulBMProcPhylTree(phyltree,X0=BMparameters$vX0,Sigma=BMparameters$Sxx,jumpsetup=jumpobj)

## End(Not run)	

Results