define_impl {ipmr} | R Documentation |
Helpers for IPM construction
Description
Helpers for IPM construction
Usage
define_impl(proto_ipm, kernel_impl_list)
make_impl_args_list(kernel_names, int_rule, state_start, state_end)
define_domains(proto_ipm, ...)
define_pop_state(proto_ipm, ..., pop_vectors = list())
define_env_state(proto_ipm, ..., data_list = list())
discretize_pop_vector(
trait_values,
n_mesh,
pad_low = NULL,
pad_high = NULL,
normalize = TRUE,
na.rm = TRUE
)
Arguments
proto_ipm |
The name of the model. |
kernel_impl_list |
A named list. Names correspond to kernel names. Each
kernel should have 3 slots defined - the |
kernel_names |
A character vector with the names of the kernels that parameters are being defined for. |
int_rule |
The integration rule to be used for the kernel. The default is "midpoint". "b2b" (bin to bin) and "cdf" (cumulative density functions) will be implemented as well. |
state_start |
The name of the state variable for the kernel that the kernel acts on at time t. |
state_end |
The name of the state variable that the kernel produces at time t+1. |
... |
Named expressions. See Details for more information on their usage in
each |
pop_vectors |
If the population vectors are already pre-defined (i.e. are
not defined by a function passed to |
data_list |
A list of named values that contain data used in the expressions
in |
trait_values |
A numeric vector of trait values. |
n_mesh |
The number of meshpoints to use when integrating the trait distribution. |
pad_low |
The amount to pad the smallest value by, expressed as a proportion. For example, 0.8 would shrink the smallest value by 20%. |
pad_high |
The amount to pad the largest value by, expressed as a proportion. For example, 1.2 would increase the largest value by 20%. |
normalize |
A logical indicating whether to normalize the result to sum to 1. |
na.rm |
A logical indicating whether to remove |
Details
These are helper functions to define IPMs. They are used after defining the kernels,
but before calling make_ipm()
They are meant to be called in the
following order:
-
define_impl()
-
define_domains()
-
define_pop_state()
-
define_env_state()
The order requirement is so that information is correctly matched to each kernel. Below are specific details on the way each works.
define_impl
This has two arguments - proto_ipm
(the model object you wish to work with),
and the kernel_impl_list
. The format of the kernel_impl_list
is:
names of the list should be kernel names, and each kernel should have 3 entries:
int_rule
, state_start
, and state_end
. See examples.
define_domains
If the int_rule = "midpoint"
, the ...
entries are vectors of
length 3 where the name corresponds to the
state variable, the first entry is the lower bound of the domain, the second
is the upper bound of the domain, and the third entry is the number of
meshpoints. Other int_rule
s are not yet implemented, so for now this is the
only format they can take. See examples.
define_pop_state
This takes either calls to functions in the ...
, or a pre-generated
list of vectors in the pop_vectors
. The names used
for each entry in ...
and/or for the pop_vectors
should be
n_<state_variable>
. See examples.
define_env_state
Takes expressions that generate values for environmental covariates at each
iteration of the model in ...
. The data_list
should contain any
parameters that the function uses, as well as the function itself. The
functions should return named lists. Names in that list can be referenced in
vital rate expressions and/or kernel formulas.
discretize_pop_vec
This takes a numeric vector of a trait distribution and computes the relative
frequency of trait values. By default, it integrates the kernel density estimate
of the trait using the midpoint rule with n_mesh
mesh points.
This is helpful for creating an initial population state vector that
corresponds to an observed trait distribution.
Value
All define_*
functions return a proto_ipm. make_impl_args_list
returns a list, and so must be used within a call to define_impl
or
before initiating the model creation procedure.
Examples
# Example with kernels named "P" and "F", and a domain "z"
kernel_impl_list <- list(P = list(int_rule = "midpoint",
state_start = "z",
state_end = "z"),
F = list(int_rule = "midpoint",
state_start = "z",
state_end = "z"))
# an equivalent version using make_impl_args_list
kernel_impl_list <- make_impl_args_list(
kernel_names = c("P", "F"),
int_rule = c("midpoint", "midpoint"),
state_start = c("z", "z"),
state_end = c("z", "z")
)
data(sim_di_det_ex)
proto_ipm <- sim_di_det_ex$proto_ipm
# define_domains
lower_bound <- 1
upper_bound <- 100
n_meshpoints <- 50
define_domains(proto_ipm, c(lower_bound, upper_bound, n_meshpoints))
# define_pop_state with a state variable named "z". Note that "n_" is prefixed
# to denote that it is a population state function!
define_pop_state(proto_ipm, n_z = runif(100))
# alternative, we can make a list before starting to make the IPM
pop_vecs <- list(n_z = runif(100))
define_pop_state(proto_ipm, pop_vectors = pop_vecs)
# define_env_state. Generates a random draw from a known distribution
# of temperatures.
env_sampler <- function(env_pars) {
temp <- rnorm(1, env_pars$temp_mean, env_pars$temp_sd)
return(list(temp = temp))
}
env_pars <- list(temp_mean = 12, temp_sd = 2)
define_env_state(
proto_ipm,
env_values = env_sampler(env_pars),
data_list = list(env_sampler = env_sampler,
env_pars = env_pars)
)
data(iceplant_ex)
z <- c(iceplant_ex$log_size, iceplant_ex$log_size_next)
pop_vecs <- discretize_pop_vector(z,
n_mesh = 100,
pad_low = 1.2,
pad_high = 1.2)