| fit_4pl | R Documentation |
Wraps make_4pl_formula() + make_4pl_priors() + brms::brm(). Returns
a workflow object containing the fit, data, formula, prior, and metadata
that downstream helpers (e.g. tls()) read from.
fit_4pl(
data,
random_effects = NULL,
temp_effects = c("low", "up", "k", "mid"),
lower = 0,
upper = 1,
family = NULL,
prior = NULL,
chains = 4,
iter = 4000,
warmup = floor(iter/2),
cores = chains,
seed = 123,
backend = "cmdstanr",
control = list(adapt_delta = 0.95, max_treedepth = 12),
init = 0,
file = NULL,
file_refit = "on_change",
fit = TRUE,
bounds = NULL,
ctmax = NULL,
z = NULL,
up = NULL,
low = NULL,
k = NULL,
mid = NULL,
by = NULL,
threshold = c("relative", "absolute"),
p = 0.5,
t_ref = 60,
data2 = NULL,
fix_asymptotes = NULL,
...
)
data |
Output of |
random_effects |
Optional character vector of grouping variables for
random intercepts on |
temp_effects |
Which 4PL sub-parameters carry a |
lower, upper |
Response-scale bounds for the asymptotes. Default
|
family |
brms family. |
prior |
Optional |
chains, iter, warmup, cores, seed |
Sampling arguments passed to |
backend |
Either |
control |
List of HMC control parameters. |
init |
Initial values for the sampler. Default |
file |
Optional path (without extension) to cache the fit. |
file_refit |
Passed to |
fit |
Logical. If |
bounds |
Length-2 |
ctmax, z, up, low, k |
One-sided formulas selecting the direct CTmax/z
parameterisation (see |
mid, by |
Midpoint parameterisation only (see
|
threshold |
|
p |
Survival fraction for the |
t_ref |
Reference exposure for CTmax, in minutes (default 60,
i.e. one hour). Converted to the model's log10-time scale
via the data's |
data2 |
Named list of objects referenced by the model
formulas but not part of |
fix_asymptotes |
Pin one or both asymptotes instead of estimating them.
Default |
... |
Further arguments passed to |
By default all four 4PL sub-parameters get a temp_c slope, and random
intercepts attach to mid only. Use temp_effects = "mid" for the classical
constant-shape TDT model (recommended for sparse designs — see temp_effects).
To fit separate categories (life stages, species, populations), filter data
per category and call this function once per subset.
Censored readings: if standardize_data() was given a detection_limit
(a continuous-proportion response whose instrument cannot resolve values
beyond a limit), the fit adds brms's cens() term to the response so those
readings contribute the probability of lying beyond the limit. Only the
response side of the formula changes (survival | cens(censored)); the
4PL, the priors and every downstream reader of the curve are the same.
Because censored readings then score as probabilities in log_lik(),
loo() and waic(), compare such a fit only with fits to the same data
and the same detection_limit.
A list of class "bayes_tls" with elements fit, data,
formula, prior, meta. See print.bayes_tls(),
summary.bayes_tls(), and plot.bayes_tls() for the available
methods.
## Not run:
d <- standardize_data(raw, ...)
wf <- fit_4pl(d, fit = FALSE) # inspect spec only
wf <- fit_4pl(d, file = "output/models/my_fit")
wf <- fit_4pl(d, lower = 0.85) # sublethal data
# Phylogenetic model: species-level CTmax/z with a phylogenetic
# correlation matrix (issue #12).
A <- ape::vcv(phy, corr = TRUE) # unit-diagonal correlation matrix
wf <- fit_4pl(d,
ctmax = ~ 1 + (1 | gr(species, cov = A)),
z = ~ 1 + (1 | gr(species, cov = A)),
t_ref = 60, data2 = list(A = A))
tls(wf, by = "species") # per-species z / CTmax (shrunk via A)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.