| other_mort | R Documentation |
Besides the rates that mizer calculates itself, a model can carry extra
contributions to the mortality rate and to the encounter rate. Each
contribution is an R function, registered here by name, that mizer calls at
every time step: getMort() adds the result of every function listed in
other_mort(params) to the mortality rate and getEncounter() adds the
result of every function listed in other_encounter(params) to the encounter
rate.
other_mort(params)
other_mort(params) <- value
other_encounter(params)
other_encounter(params) <- value
params |
A MizerParams object |
value |
A named list of function names, or |
Use these when the extra contribution depends on the state of the model, as
a starvation mortality or a density-dependent mortality does. A contribution
that is simply a fixed array is better set with ext_mort() or
ext_encounter(), which is what mizer's own external mortality and external
encounter use.
Assigning NULL to an entry removes that contribution:
other_mort(params)[["starvation"]] <- NULL
A named list with the names of the functions contributing to the rate, excluding any that belong to a component.
Each registered function is called as
fun(params, n, n_pp, n_other, t, component, ...)
and has to return an array with the same dimensions as the rate it
contributes to, that is species x size. The component argument holds the
name under which the function is registered, so a single implementation can
serve several entries. Always give your function a ... argument so that it
tolerates being passed arguments it does not use.
Make sure the function depends continuously on the abundances, for the
reasons set out in setRateFunction().
A component set up with setComponent() can contribute to these rates
through that function's mort_fun and encounter_fun arguments. Such an
entry belongs to its component: setComponent() sets it, removeComponent()
removes it and getComponent() reports it. The accessors here therefore
leave those entries alone. other_mort() and other_encounter() list only
the contributions that do not belong to a component, and assigning through
them preserves the ones that do. This mirrors other_params(), which
likewise hides the parameters belonging to a component, and it makes it
impossible to wipe out a component's contribution by assigning a whole list.
setComponent(), other_params(), ext_mort(), ext_encounter()
Other extension tools:
NOther(),
coerceToExtensionClass(),
initialNOther<-(),
recordExtension(),
setComponent(),
setRateFunction()
# An extra mortality that grows with the total biomass in the community.
# Like any custom rate function it has to live in the global environment
# or in a package, so that mizer can find it by name.
crowdingMort <- function(params, n, n_pp, n_other, t, component, ...) {
biomass <- sum(n %*% (params@w * params@dw))
# Same dimensions as the mortality rate: species x size
0 * params@mu_b + 1e-14 * biomass
}
params <- NS_params
other_mort(params)[["crowding"]] <- "crowdingMort"
other_mort(params)
# The contribution is included in the mortality rate
range(getMort(params) - getMort(NS_params))
# and can be removed again
other_mort(params)[["crowding"]] <- NULL
other_mort(params)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.