simulation {pop} | R Documentation |
Stochastic Simulation
Description
Simulate a population dynamic model in discrete time, recording the number of individuals in each state at each time point.
Usage
simulation(dynamic, population, timesteps = 1, replicates = 1,
ncores = NULL)
is.simulation(x)
## S3 method for class 'simulation'
plot(x, states = NULL, patches = 1, ...)
Arguments
dynamic |
a population dynamic model of class |
population |
a dataframe or named vector of positive integers, giving
the number of individuals in each state of |
timesteps |
a positive integer giving the number of time steps (iterations) over which to simulate the model |
replicates |
a positive integer giving the number of independent time series to simulate |
ncores |
an optional positive integer giving the number of cpu cores to
use when running simulations. By default (when |
x |
a |
states |
a character vector naming the states in the |
patches |
vector of positive integers identifying the patches for which to plot the simulations. By default only projections for the first patch are plotted. |
... |
further arguments passed to or from other methods. |
Details
The order of the dynamics in the simulation is defined by the order
in which the transitions were passed to dynamic
. I.e. if the stasis
probability of a life stage (e.g. fraction surviving and remaining in the
stage) was specified before the reproduction rate, then only those staying
in the state will reproduce. Conversely, if reproduction was given first,
individuals will reproduce before the stasis probability is applied.
Value
an object of class simulation
Examples
# set up a three-stage model
stasis_egg <- tr(egg ~ egg, p(0.6))
stasis_larva <- tr(larva ~ larva, p(0.4))
stasis_adult <- tr(adult ~ adult, p(0.9))
hatching <- tr(larva ~ egg, p(0.35))
fecundity <- tr(egg ~ adult, r(20))
pupation <- tr(adult ~ larva, p(0.2))
pd <- dynamic(stasis_egg,
stasis_larva,
stasis_adult,
hatching,
pupation,
fecundity)
population <- data.frame(egg = 1200, larva = 250, adult = 50)
# simulate for 50 timesteps, 30 times
sim <- simulation(dynamic = pd,
population = population,
timesteps = 50,
replicates = 30,
ncores = 1)
is.simulation(sim)
par(mfrow = c(3, 1))
plot(sim)