Working on my lecture for the Evolutionary Quantitative Genetics Workshop at NESCent. Here is some really simple code to perform discrete-time (non-phylogenetic) Brownian motion simulation:
# discrete time BM simulation
n<-100; t<-100; sig2<-1/t # set parameters
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=range(Y),xlab="time",ylab="phenotype", type="l")
apply(Y,2,lines,x=time)
And here is the result:
No comments:
Post a Comment
Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.