###Discrete-time Ornstein-Uhlenbeck model of trait evolution. There are seven arguments needed for the # simulation. They are the number of species (NumSP), the number of time steps (nsteps), the standard #deviation (SD –which controls the spread), the strength of selection (alph –which when zero is a Brownian #motion model), the trait optimum (theta), line colour (colr) and line width (wid). ##by Marc Cadotte ##Oct 2010 OUM<-function(NumSp,nsteps,SD=1,alph=0.5,theta=100,colr="red",wid=1.2){ plot(0,0,ylim=c(-100,100),xlim=c(0,nsteps),type="n", ylab="Trait value",xlab="Time") x<-c(0:nsteps) for (i in 1:NumSp){ devs<-rnorm(nsteps,sd=SD) for (i in 1:nsteps) { x[i+1] <- x[i] + alph*(theta-x[i]) + devs[i] lines(i:(i+1), x[i:(i+1)], col=colr,lwd=wid) } } }