Skip to content

Instantly share code, notes, and snippets.

@sckott
Created November 6, 2012 19:52
Show Gist options
  • Save sckott/4027059 to your computer and use it in GitHub Desktop.
Save sckott/4027059 to your computer and use it in GitHub Desktop.
Visual comparison of trait evol models.
require(ggplot2); require(reshape2); require(grid); library(gsl); library(wrightscape)
theme_set(theme_bw())
plot.path_sim <- function(x, ...) ggplot(x) + geom_line(aes(time,
value, group = rep), alpha = 0.05)
reps <- 500
X <- bm_path_sim(reps = reps)
Y <- ou_path_sim(reps = reps, alpha = 6)
W <- brownie_path_sim(reps = reps, sigma = 0.3, sigma2 = 1.2, release_frac = 0.7) # has 1/release_frac time = 2
px <- plot.path_sim(X) + opts(title = "Brownian Motion") +
coord_cartesian(ylim = c(-2, 2)) + ylab("trait value")
py <- plot.path_sim(Y) + opts(title = "Ornstein-Uhlenbeck") +
coord_cartesian(ylim = c(-2, 2)) + ylab("trait value")
pw <- plot.path_sim(W) + opts(title = "Accelerated Evolution") +
coord_cartesian(ylim = c(-2, 2)) + ylab("trait value")
grid.newpage()
pushViewport(viewport(layout = grid.layout(3, 1)))
vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
print(px, vp = vplayout(1, 1))
print(py, vp = vplayout(2, 1))
print(pw, vp = vplayout(3, 1))
See the figure here:
http://figshare.com/articles/compare_trait_evol_models/97221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment