Get a predefined discount function or create a custom discount function.
Usage
td_fn(
predefined = c("hyperbolic", "exponential", "inverse-q-exponential",
"nonlinear-time-hyperbolic", "scaled-exponential", "dual-systems-exponential",
"nonlinear-time-exponential", "model-free", "constant"),
name = NULL,
fn = NULL,
par_starts = NULL,
par_lims = NULL,
ED50 = NULL,
par_chk = NULL
)
Arguments
- predefined
A string specifying one of the pre-defined discount functions.
- name
Name of custom discount function.
- fn
Function that takes a data.frame and a vector of named parameters and returns a vector of values between 0 and 1.
- par_starts
A named list of vectors, each specifying possible starting values for a parameter to try when running optimization.
- par_lims
A named list of vectors, each specifying the bounds to impose of a parameters. Any parameter for which bounds are unspecified are assumed to be unbounded.
- ED50
A function which, given a named vector of parameters
p
and optionally a value ofdel_val
, computes the ED50. If there is no closed-form solution, this should return the string "non-analytic". If the ED50 is not well-defined, this should return the string "none".- par_chk
Optionally, this is a function that checks the parameters to ensure they meet some criteria. E.g., for the dual-systems-exponential discount function, we require k1 < k2.
Examples
if (FALSE) { # \dontrun{
data("td_bc_single_ptpt")
mod <- td_bcnm(td_bc_single_ptpt, discount_function = "hyperbolic", fixed_ends = T)
# Custom discount function
custom_discount_function <- td_fn(
name = 'custom',
fn = function(data, p) (1 - p['b'])*exp(-p['k']*data$del) + p['b'],
par_starts = list(k = c(0.001, 0.1), b = c(0.001, 0.1)),
par_lims = list(k = c(0, Inf), b = c(0, 1)),
ED50 = function(...) 'non-analytic'
)
mod <- td_bcnm(td_bc_single_ptpt, discount_function = custom_discount_function, fit_err_rate = T)
} # }