as.transfun {pop} | R Documentation |
create a transition function
Description
A utility function to enable users to create bespoke transition
functions (transfun
objects) for use in transition
s.
Usage
as.transfun(fun, param, type = c("probability", "rate", "dispersal"))
Arguments
fun |
an R function describing the transition. This must take only one
argument: |
param |
a named list of the parameters of |
type |
what type of transition this function represents, a probability or a rate |
Details
fun
must take only one argument, landscape
, an object
of class landscape
. landscape
objects contain three
elements which may be used in the function: population
, a dataframe
giving the number of individuals of each stage (columns) in each patch
(rows); area
; a numeric vector giving the area of each patch in
square kilometres; and features
, a dataframe containing
miscellaneous features (columns) of each habitat patch (rows), such as
measures of patch quality or environmental variables. See examples for an
illustration of how to these objects. Parameters of the transfun should be
passed to as.transfun
as a named list. These can then be used in
fun
by accessing them from this list. Note that param
isn't
an argument to fun
, instead it's modified directly in the function's
envirnment (because reasons).
Examples
# a very simple (and unnecessary, see ?p) transfun
fun <- function(landscape) param$prob
prob <- as.transfun(fun, param = c(prob = 0.3), type = 'probability')
# a density-dependent probability
dd_fun <- function (landscape) {
adult_density <- population(landscape, 'adult') / area(landscape)
param$p * exp(- adult_density/param$range)
}
dd_prob <- as.transfun(dd_fun,
param = list(p = 0.8,
range = 10),
type = 'probability')