To run a simulation, we need to know where the species lives, how it disperses, and how it reproduces and dies. Given a demographic model of this sort, we then keep track of the numbers of various genotypes across the species range.
These are divided among different objects as follows:
population
Class population:
habitat
a Raster with values that can be used in other computations.
accessible
vector of indices of cells in habitat
that migrants will attempt to go to
habitable
vector of indices of cells in habitat
that may have positive population
genotypes
character vector of the genotypes
N
matrix indexed by (habitable cells) x (genotypes) giving the number of each genotype in each habitable cell
Set-up:
This can be initiated with make_population()
by specifying the following:
habitat
The path to the file where the raster is stored.
inaccessible.value
The values in the raster that should be marked as inaccessible.
uninhabitable.value
The values in the raster that should be marked as not habitable.
genotypes
A character vector of genotypes.
Example:
pop <- make_population(
habitat = system.file("extdata/test_raster.gri",package="landsim"),
inaccessible.value = "NA",
uninhabitable.value = 0.0,
genotypes = c( "aa", "aA", "AA" )
)
migration
One structure we use several times is the setup for smoothing (with migrate
); for this we need to know:
Class migration:
kern
function that gives weights for neighboring cells as a function of Euclidean distance
sigma
scaling factor on distance before being passed to kern
radius
maximum range of the smoother
normalize
normalization factor applied to the smoother
Example:
migr <- migration(
kern = "gaussian",
sigma = 100,
radius = 1000,
normalize = 1.0
)
A migration.matrix
object extends a migration
object, in that it has a precomputed migration matrix, and hence is tied to a particular population
setup (although this is not included). This has additional entries
Class migration.matrix:
M
The pre-computed migration matrix.
Example:
This is added with the function setup_migration()
.
migr <- setup_migration( migr, population=pop )
vital_rate
Vital rates may be numbers or vectors but may also be functions, to allow them to depend on the current state of the system. We would like to have the parameters in these visible, changeable, and carried around with them. To this end, we define vital
objects by specifying a function and auxialliary parameters that will be kept along with the function.
Simple example:
This class allows assigning and accessing things directly from the environment of the function, without having them clutter up the global environment.
f <- vital( function (N,...) { N+x }, x=3 )
f(10)
## [1] 13
f$x
## [1] 3
f$x <- 12
f(10)
## [1] 22
Example:
germ.vital <- vital(
function (N, ...) {
out <- r0 / ( 1 + migrate(rowSums(N),competition)/carrying.capacity )
return( cbind( aa=out, aA=s*out, AA=s^2*out ) )
},
r0 = 0.01, # one in ten seeds will germinate at low densities
s = 1.5, # multiplicative selective benefit of the A allele
carrying.capacity = 10,
competition = migration(
kern="gaussian",
sigma=100,
radius=300,
normalize=1
)
)
Note that this also has a migration
object as part of its definition. This needs to be set up also:
germ.vital <- setup_vital(germ.vital,pop)
demography
Several of the base demographic parameters we might want to specify (as a fixed number or a layer), or compute (as a function of the current population state). Such parameters can be either something numeric or else a function that is applied to N
to get the result.
To do a single generation we need to know:
Class demography:
prob.seed
parameter
object for probability of seeding per individual per year
fecundity
parameter
object for mean number of seeds per seeding individual per year
prob.germination
parameter
object for probability of germination
prob.survival
parameter
object for probability of survival of already existing individuals
pollen.migration
migration
object for pollen dispersal (normalized to total pollen production)
seed.migration
migration
object for seed dispersal (normalized to 1)
genotypes
vector of names of the genotypes represented by the layers
mating
genotype x genotype x genotype tensor, with entry [i,j,k]
the probability that genotypes i
and j
combine to make offspring genotype k
Example:
demog <- demography(
prob.seed = 0.2,
fecundity = 100,
prob.germination = germ.vital,
prob.survival = 0.9,
seed.migration = migr,
pollen.migration = migration(
kern="gaussian",
sigma=300,
radius=900,
normalize=10
),
genotypes = c("aa", "aA", "AA")
)
This can be set up for use with a population with setup_demography
, which sets up all the associated migration and vital objects.
demog <- setup_demography(demog,pop)