# define a basic population
nstage <- 5
popmat <- matrix(0, nrow = nstage, ncol = nstage)
popmat[reproduction(popmat, dims = 4:5)] <- c(10, 20)
popmat[transition(popmat)] <- c(0.25, 0.3, 0.5, 0.65)
# define a dynamics object
dyn <- dynamics(popmat)
# simulate with the default updater
sims <- simulate(dyn, nsim = 1000)
# calculate expected population size
exps(sims)
# calculate expected population size for 4 and 5 year
# olds only
exps(sims, subset = 4:5)
# calculate expected population size but ignore first 10 years
exps(sims, times = 11:51)
# calculate expected population size based on median
exps(sims, fun_among = median)
# calculate expected maximum population size based on median
exps(sims, fun_within = max, fun_among = median)
# calculate exps with conflicting quantile functions, handling
# conflicting arguments with wrapper functions
quant1 <- function(x, p1, ...) {
quantile(x, prob = p1)
}
quant2 <- function(x, p2, ...) {
quantile(x, prob = p2)
}
exps(
sims,
fun_within = quant1, fun_among = quant2, p1 = 0.25, p2 = 0.75
)
Run the code above in your browser using DataLab