Download presentation
Presentation is loading. Please wait.
Published byKeila Boyington Modified over 9 years ago
1
Testing methods & comparing models using continuous and discrete character simulation Liam J. Revell
2
Motivating example: phylogenetic error and comparative analyses Phylogenetic comparative analyses often (but not always) assume that the tree & data are known without error. (An alternative assumption is that the sampling distribution obtained from repeating the analysis on a sample of trees from their Bayesian posterior distribution will give a unbiased estimate of the parameter’s sampling distribution.) To test this, I simulated trees & data, and then mutated the trees via NNI.
3
Dissolve internal branches Reattach Felsenstein 2004 Nearest neighbor interchange:
4
Topological error: σ 2 Simulation 2
5
Topological error: model selection 5152535455565758595 OU lambda BM random NNIs selected model (%) 0 20 40 60 80 100 Simulation 1
6
Motivating example: phylogenetic error and comparative analyses This result shows that topological error introduces non- random error (bias) into parameter estimation. It also suggests that averaging a posterior sample is also biased – and perhaps from some problems a global ML or MCC estimate might be better (although I have not simulated this). Finally, topological error can cause us to prefer more complex models of evolution.
7
Outline Discrete vs. continuous time simulation: – Example 1: Brownian motion simulation. – Example 2: Discrete character evolution. Alternative methods for quantitative character simulation. Visualizing the results of numerical simulations: – Projecting the phylogeny into phenotype space. – Mapping discrete characters on the tree. Uses of simulation in comparative biology. – Stochastic character mapping. – Phylogenetic Monte Carlo. – Testing comparative methods. Conclusions.
8
Discrete time simulations Note that discrete & continuous time have nothing at all to do with whether the simulated traits are discrete or continuous. In discrete time, we simulate evolution as the result of changes additively accumulated over many individual timesteps. Timesteps may be (but are not necessarily – depending on our purposes) organismal generations.
9
Example: Brownian motion In Brownian motion, changes in a phenotypic trait are drawn from a normal distribution, centered on 0.0, with a variance proportional to the time elapsed x the rate. In a discrete time simulation of Brownian motion, every “generation” is simulated by a draw from a random normal with variance σ 2 dt (or σ 2 t i for the ith generation).
10
Example: Brownian motion We can simulate Brownian evolution for a single or multiple lineages. n<-1; t<-100; sig2<-0.1 time<-0:t X<-rbind(rep(0,n),matrix(rnorm(n*t,sd=sqrt(sig2)),t,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2))))
11
Example: Brownian motion We can simulate Brownian evolution for a single or multiple lineages. n<-1; t<-100; sig2<-0.1 time<-0:t X<-rbind(rep(0,n),matrix(rnorm(n*t,sd=sqrt(sig2)),t,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2))))
12
Example: Brownian motion We can simulate Brownian evolution for a single or multiple lineages. n<-100; t<-100; sig2<-0.01 time<-0:t X<-rbind(rep(0,n),matrix(rnorm(n*t,sd=sqrt(sig2)),t,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2))))
13
Example: Brownian motion We can simulate Brownian evolution for a single or multiple lineages. n<-100; t<-100; sig2<-0.05 time<-0:t X<-rbind(rep(0,n),matrix(rnorm(n*t,sd=sqrt(sig2)),t,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2))))
14
Example: Brownian motion We can simulate Brownian evolution for a single or multiple lineages. n<-100; t<-100; sig2<-0.1 time<-0:t X<-rbind(rep(0,n),matrix(rnorm(n*t,sd=sqrt(sig2)),t,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2))))
15
Example: Brownian motion We can simulate Brownian evolution for a single or multiple lineages. The expected variance on the outcome is just: (due to the additivity of variances) Does this mean that if we were just interested in the end product of Brownian evolution we could simulate ? Yes.
16
Example: Brownian motion Discrete time. n<-100; t<-100; sig2<-0.1 time<-0:t X<-rbind(rep(0,n),matrix(rnorm(n*t,sd=sqrt(sig2)),t,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2))))
17
Example: Brownian motion One big step.... n<-100; t<-100; sig2<-0.1 time<-c(0,t) X<-rbind(rep(0,n),matrix(rnorm(n,sd=sqrt(sig2*t)),1,n)) Y<-apply(X,2,cumsum) plot(time,Y[,1],ylim=c(-10,10),xlab="time",ylab="phenotype",type="l") apply(Y,2,lines,x=time) text(0.95*t,9,bquote(paste(sigma^2,"=",.(sig2)))) this is a continuous time simulation.
18
Example: Discrete character We can also simulate changes in a discrete character through time as a discrete-time Markov process or Markov chain. This is just a way of saying that the process is memoryless – i.e., its future state is only dependent on the present state of the chain, and not at all on what happened in the past. When we simulate the evolution of a discrete character, we need a probability for change per step in the chain. Imagine a character with initial state “blue” that changes to “yellow” (and back again) with a probability of 0.2. t = 1234567 8 91011 12
19
Example: Discrete character We can look at the average properties of discrete time Markov chains using simulation as well: n<-100; t<-100; p<-0.1; x<-list(); x[[1]]<-rep(0,n) for(i in 1+1:t){ x[[i]]<-x[[i-1]]; z<-runif(n)<p x[[i]][intersect(which(x[[i-1]]==0),which(z))]<-1 x[[i]][intersect(which(x[[i-1]]==1),which(z))]<-0 } y<-sapply(x,mean) barplot(rbind(y,1-y),col=c("blue","yellow"),xlab="time") 020406080100
20
Example: Discrete character We can look at the average properties of discrete time Markov chains using simulation as well: n<-100; t<-100; p<-0.01; x<-list(); x[[1]]<-rep(0,n) for(i in 1+1:t){ x[[i]]<-x[[i-1]]; z<-runif(n)<p x[[i]][intersect(which(x[[i-1]]==0),which(z))]<-1 x[[i]][intersect(which(x[[i-1]]==1),which(z))]<-0 } y<-sapply(x,mean) barplot(rbind(1-y,y),col=c("blue","yellow"),xlab="time") 020406080100
21
Example: Discrete character For continuous time discrete character simulation, the probability distribution for x is found by matrix exponentiation of the instantaneous transition matrix Q, i.e.: Thus, to simulate the state at time t given the state at time 0, we first compute the right product (a vector) and assign the state randomly with the probabilities given by p t. We can do this and compare to our replicated discrete time simulations.
22
Example: Discrete character Here’s our discrete time simulation, replicated 1000 times: n<-1000; t<-100; p<-0.01; x<-list(); x[[1]]<-rep(0,n) for(i in 1+1:t){ x[[i]]<-x[[i-1]]; z<-runif(n)<p x[[i]][intersect(which(x[[i-1]]==0),which(z))]<-1 x[[i]][intersect(which(x[[i-1]]==1),which(z))]<-0 } y<-sapply(x,mean) barplot(rbind(1-y,y),col=c("blue","yellow"),xlab="time") 020406080100
23
Example: Discrete character Here’s our continuous time probability function, overlain: p0<-c(1,0) Q<-matrix(c(-p,p,p,-p),2,2) time<-matrix(0:t) y<-apply(time,1,function(x,Q,p0) expm(Q*x)%*%p0,Q=Q,p0=p0) plot(time,y[1,],ylim=c(0,1),type="l") 020406080100
24
Example: Discrete character What about the wait times to character change? Well, under a continuous time Markov process the waiting times are exponentially distributed with rate –q ii. We can compare our discrete time simulation wait times to the expected distribution of waiting times in a continuous time Markov.
25
First, compute (first) waiting times from our simulation of earlier: Example: Discrete character wait<-vector() X<-sapply(x,rbind) for(i in 1:nrow(X)){ if(any(X[i,]==1)) wait[i]<-min(which(X[i,]==1)) else wait[i]<-t } hist(wait,main=NULL,xlab="First waiting time (generations)")->temp
26
Example: Discrete character z<-vector() for(i in 2:(length(temp$breaks))) z[i-1]<-(pexp(temp$breaks[i],p)-pexp(temp$breaks[i-1],p))*n lines(temp$mids,z,type="o") Now, compute and overlay the exponential densities:
27
Methods for quantitative character simulation on a tree We have discussed simulating characters along single lineages. To simulate character data on a tree we have multiple choices. We can draw changes along edges of the tree from the root to any tip: t1 t3 t2 0.00 +0.36 0.36 +0.84 0.84 -0.29 0.55 +0.33 1.17
28
Methods for quantitative character simulation on a tree An alternative approach utilizes the fact that shared history of related species creates covariances between tip species. If we simulated data with this covariance, then it will be as if we had simulated up the tree from root to tips. t1 t3 t2
29
Covariances between species? A useful way to think about the covariance between species under BM is just the (long run) covariance of the tip values of related species from many replicates of the evolutionary process. We can explore this concept by simulation (naturally). t1 t3 t2
30
Covariance depends on the relative shared history of species. t1 t3 t2 50% t1 t2 t3 Covariances between species? X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist)
31
Covariances between species? X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist) Covariance depends on the relative shared history of species. t1 t3 t2 50%
32
Covariances between species? tree$edge.length<-c(0.9,1,0.1,0.1) X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist) t1 t3 t2 90% Covariance depends on the relative shared history of species. t1 t2 t3
33
Covariances between species? tree$edge.length<-c(0.9,1,0.1,0.1) X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist) t1 t3 t2 90% Covariance depends on the relative shared history of species.
34
Covariances between species? tree$edge.length<-c(0.1,1,0.9,0.9) X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist) Covariance depends on the relative shared history of species. t1 t2 t3 t1 t3 t2 10%
35
Covariances between species? tree$edge.length<-c(0.1,1,0.9,0.9) X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist) t1 t3 t2 10% Covariance depends on the relative shared history of species.
36
Covariances between species? This gives an alternative means of simulating under BM: we can just draw a vector of correlated values from the multivariate distribution expected for the tips. In particular, for: and we simulate from: What does this look like? t1 t3 t2 1.0 0.9 0.1
37
Covariances between species? X<-t(fastBM(tree,nsim=1000)) pairs(X,diag.panel=panel.hist) X<-matrix(rnorm(3000),1000,3)%*%chol(C) pairs(X,diag.panel=panel.hist) t1 t3 t2
38
Visualization tree<-pbtree(n=6,scale=1) tree<-read.tree(text=write.tree(tree)) X<-t(fastBM(tree,nsim=1000)) for(i in length(tree$tip)+1:tree$Nnode) tree<-rotate(tree,i) plotTree(tree,pts=F,fsize=1.5) pairs(X,diag.panel=panel.hist)
39
Visualization We have many options for visualizing phenotypic evolution on the tree (simulated or reconstructed). One method is via so-called “traitgrams,” in which we project our tree into a phenotype/time space. We can use known or estimated ancestral phenotypic values. Traitgrams are plotted by drawing lines between ancestors and descendants that obtain their vertical dimension from known or estimated trait values; and their horizontal dimension from the tree.
40
Visualization Traitgram for one trait with known ancestral values: tree<-pbtree(n=20,scale=100) x<-fastBM(tree,internal=TRUE) phenogram(tree,x)
41
Visualization Traitgram for one trait with estimated ancestral values: tree<-pbtree(n=20,scale=100) x<-fastBM(tree,internal=TRUE) phenogram(tree,x) phenogram(tree,x[1:length(tree$tip)])
42
3D traitgram We can also plot a traitgram in two phenotypic dimensions, with time represented as a third dimension. tree<-pbtree(n=40,scale=100) X<-sim.corrs(tree,matrix(c(1,0.8,0.8,1),2,2)) fancyTree(tree,type="traitgram3d",X=X,control=list(box=FALSE)) movie3d(spin3d(axis=c(0,0,1),rpm=10),duration=10,dir="traitgram3d.movie",convert=FALSE)
43
3D traitgram
44
“Phylomorphospace” Another technique we can use to visualize multivariate evolution is by projecting the tree into 2 or 3D morphospace (defined only by the trait axes). This has been called a “phylomorphospace” projection (Sidlauskas 2008).
45
“Phylomorphospace” phylomorphospace(tree,X) 2D phylomorpho- space for correlated characters.
46
“Phylomorphospace” phylomorphospace(tree,X) X<-cbind(X,fastBM(tree)) phylomorphospace3d(tree,X) movie3d(spin3d(axis=c(1,1,1),rpm=10),duration=10,dir="phylomorphospace.movie",convert=FALSE) 3D phylomorpho- space.
47
Discrete character evolution We can simulate discrete character evolution too. One way to do this is to draw wait times from their expected distribution, and then change states with probabilities given by Q. We can not only record the outcome of this simulation, but also the character history on the tree.
48
Discrete character evolution Let’s try: tree<-pbtree(n=100,scale=1) tree<-sim.history(tree,Q=matrix(c(-1,1,1,-1),2,2),anc=1) cols<-c("blue","red"); names(cols)<-c(1,2) plotSimmap(tree,cols,pts=FALSE,ftype="off")
49
Trait dependent evolution Finally, we can simulate the rate or process of evolution in a continuous trait as a function of the state for a discrete character. This works the same way as our previous Brownian motion simulations, except that in this case the instantaneous variance differs on different branches & branch segments.
50
Trait dependent evolution Let’s simulate this and then visualize it using a traitgram. – First a phylogeny with an encoded discrete character history: tree<-sim.history(pbtree(n=30,scale=1),Q=matrix(c(-1,1,1,-1),2,2),anc=1) cols<-c("blue","red"); names(cols)<-c(1,2) plotSimmap(tree,cols,pts=F,ftype="i",fsize=0.75)
51
Trait dependent evolution Let’s simulate this and then visualize it using a traitgram. – Next, simulate a continuous character evolving with two rates & plot: tree<-sim.history(pbtree(n=30,scale=1),Q=matrix(c(-1,1,1,-1),2,2),anc=1) cols<-c("blue","red"); names(cols)<-c(1,2) plotSimmap(tree,cols,pts=F,ftype="i",fsize=0.75) x<-sim.rates(tree,c(1,10)) phenogram(tree,x,fsize=0.75,colors=cols)
52
Simulations in comparative biology Simulations have both considerable history & extensive present use in phylogenetic comparative biology. A comprehensive study of all the uses of simulation would be impossible. Three uses I will discuss today are as follows: – Sampling discrete character histories using stochastic character mapping. – Simulating null distributions: the “phylogenetic Monte Carlo.” – Testing the performance & robustness of phylogenetic methods.
53
Stochastic mapping Stochastic character mapping is a procedure originally devised by Neilsen (2002; Huelsenbeck et al. 2003). In this procedure, we first sample (or estimate*) Q conditioned on an evolutionary process. We then compute the conditional probabilities of all states of our trait for all nodes of the tree. Next, we sample a character history that is consistent with these probabilities & our evolutionary process. (We do this by starting at the root node and then sampling up the tree conditioned on the parent state.) With the nodes set, we sample character history by drawing wait times from an exponential distribution.
54
Stochastic mapping tree<-sim.history(pbtree(n=30,scale=2),Q=matrix(c(-1,1,1,-1),2,2),anc=1) x<-tree$states plotTree(tree,ftype=“off”,pts=FALSE)
55
Stochastic mapping tree<-sim.history(pbtree(n=30,scale=2),Q=matrix(c(-1,1,1,-1),2,2),anc=1) x<-tree$states plotTree(tree,ftype=“off”,pts=FALSE) mtrees<-make.simmap(tree,x,nsim=100) plotSimmap(mtree,cols,pts=FALSE,ftype=“off”)
56
Stochastic mapping tree<-sim.history(pbtree(n=30,scale=2),Q=matrix(c(-1,1,1,-1),2,2),anc=1) x<-tree$states plotTree(tree,ftype=“off”,pts=FALSE) mtrees<-make.simmap(tree,x,nsim=100) plotSimmap(mtrees,cols,pts=FALSE,ftype=“off”)
57
Stochastic mapping What is stochastic mapping good for? For one thing it can be used to model the effects of a discrete character on the evolution of quantitative traits.
58
Stochastic mapping x<-tree$states mtrees<-make.simmap(tree,x,nsim=200) y<-sim.rates(tree,c(1,10)) foo<-function(x,y){ temp<-brownieREML(x,y) temp$sig2.multiple["2"]/temp$sig2.multiple["1"] } z<-sapply(mtrees,foo,y=y)
59
Stochastic mapping x<-tree$states mtrees<-make.simmap(tree,x,nsim=500) foo<-function(x,y){ temp<-brownieREML(x,y) c(temp$sig2.multiple["1"],temp$sig2.multiple["2"]) } Z<-sapply(mtrees,foo,y=y) σ 2 (1) Frequency 0.00.51.01.52.0 0 50 100 150 200 Frequency 0510152025 0 20 40 60 80 100 σ 2 (2)
60
Phylogenetic Monte Carlo One of the first uses of simulation in phylogenetic comparative biology was in generating a null distribution for hypothesis testing. This general approach was originally devised for statistical problems in which phylogenetic autocorrelation meant that parametric statistical methods were inappropriate. For example, Garland et al. (1993) devised the phylogenetic ANOVA, in which a regular ANOVA was conducted – but then rather than compare the F-statistic to a parametric F distribution, the authors generated a null distribution via Brownian simulation on the tree.
61
Phylogenetic Monte Carlo X<-fastBM(tree,nsim=500) LR<-vector() for(i in 1:100){ temp<-brownie.lite(tree,X[,i]) LR[i]<--2*(temp$logL1-temp$logL.multiple) } temp<-hist(LR) plot(temp$mids,temp$density,type="l"); Psum LR)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.