Calculate expected population size for a simulate object based on generic functions (ExPS)
Source: R/summarise.R
exps.RdCalculate expected population size for a
simulate object based on
generic functions (ExPS)
Arguments
- sims
an object returned from
simulate- subset
integervector denoting the population classes to include in calculation of population abundance. Defaults to all classes- times
integervector specifying generations to include in calculation of extinction risk. Defaults to all simulated generations- fun_within
functionused to summarise a single trajectory. Must return a single value. Defaults tomean- fun_among
functionused to summarise over all replicate trajectories. Defaults tomean. Alternatives might includemedianormin- ...
additional arguments passed to
fun_withinandfun_among. If these conflict, a wrapper function could be used to define expected arguments for each function
Value
a single value representing the expected statistic applied
to the population sizes generated with simulate
Details
Expected population size (ExPS) is a highly
flexible generalisation of emps and
represents a two-level summary that first summarises
individual population trajectories and then summarises
these values over all replicates. Abundances
can be specified for all population classes or for a subset
of classes.
Examples
# 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)
#> [1] 96.072
# calculate expected population size for 4 and 5 year
# olds only
exps(sims, subset = 4:5)
#> [1] 4.860821
# calculate expected population size but ignore first 10 years
exps(sims, times = 11:51)
#> [1] 79.90515
# calculate expected population size based on median
exps(sims, fun_among = median)
#> [1] 95.3747
# calculate expected maximum population size based on median
exps(sims, fun_within = max, fun_among = median)
#> [1] 322.7
# 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
)
#> 75%
#> 60.7253