if (FALSE) {
# Initial community composed of 10 species each including 10 individuals
initial1 <- rep(as.character(1:10), each = 10)
# Simulation of speciation and drift dynamics over 100 time steps
final1 <- forward(initial = initial1, prob = 0.1, gens = 1000)
# The final community includes new species (by default names begins with "new")
final1$com$sp # includes new species generated by speciation events
# A regional pool including 100 species each including 10 individuals
pool <- rep(as.character(1:100), each = 10)
# Simulation of migration and drift dynamics over 1000 time steps
final2 <- forward(initial = initial1, prob = 0.1, gens = 1000, pool = pool)
# The final community includes species that have immigrated from the pool
final2$com$sp # includes new species that immigrated from the pool
# Initial community composed of 10 species each including 10 individuals,
# with trait information for niche-based dynamics
initial2 <- data.frame(sp = rep(as.character(1:10), each = 10),
trait = runif(100))
# Simulation of stabilizing hab. filtering around t = 0.5, over 1000 time steps
sigm <- 0.1
filt_gaussian <- function(t,x) exp(-(x - t)^2/(2*sigm^2))
final3 <- forward(initial = initial2, prob = 0.1, gens = 1000, pool = pool,
filt = function(x) filt_gaussian(0.5,x))
plot_comm(final3) # trait distribution in final community
# With higher immigration
final4 <- forward(initial = initial2, prob = 0.8, gens = 1000, pool = pool,
filt = function(x) filt_gaussian(0.5,x))
plot_comm(final4) # should be closer to 0.5
# Simulation of limiting similarity, over 1000 time steps
final5 <- forward(initial = initial2, prob = 0.1, gens = 1000, pool = pool,
limit.sim = TRUE)
plot_comm(final5)
# Stronger limiting similarity
final6 <- forward(initial = initial2, prob = 0.1, gens = 1000, pool = pool,
limit.sim = TRUE, coeff.lim.sim = 20)
plot_comm(final6) # the distribution will be more even
# Variation of community richness with time
final7 <- forward(initial = initial2, prob = 0.1, gens = 1000, pool = pool,
limit.sim = TRUE, keep = TRUE, plot_gens = TRUE)
# Check stationarity
plot(unlist(lapply(final7$com_t, function(x) length(unique(x[, 2])))),
xlab = "Time step", ylab = "Community richness")
# Index of limiting similarity over time
plot(final7$dist.t, xlab = "Time step", ylab = "Limiting similarity")
}
Run the code above in your browser using DataLab