make_4pl_formula: Build the brms formula for the joint Bayesian 4PL

View source: R/fit_4pl.R

make_4pl_formulaR Documentation

Build the brms formula for the joint Bayesian 4PL

Description

Constructs the joint 4PL with the disjoint-bounds reparameterisation on the asymptotes (low, up) and a positivity reparam on k. All four 4PL sub-parameters (lowraw, upraw, logk, mid) get a temp_c slope — the model assumes temperature can affect every aspect of the dose-response curve. Random intercepts (if any) attach to mid.

Usage

make_4pl_formula(
  random_effects = NULL,
  bounds = NULL,
  family = brms::beta_binomial(link = "identity"),
  response_var = "survival",
  temp_effects = c("low", "up", "k", "mid"),
  ctmax = NULL,
  z = NULL,
  up = NULL,
  low = NULL,
  k = NULL,
  mid = NULL,
  by = NULL,
  threshold = c("relative", "absolute"),
  p = 0.5,
  log10_tref = 0,
  lower = 0,
  upper = 1,
  censored = FALSE
)

Arguments

random_effects

Optional character vector of grouping variables for random intercepts on mid.

bounds

Length-2 numeric c(lower, upper) giving the response-scale asymptote interval. Defaults to c(lower, upper). Preferred over the separate lower/upper (which it supersedes — see those).

family

brms family. Default beta_binomial(link = "identity"). Pass binomial(link = "identity") for the simpler no-overdispersion case, or brms::Beta(link = "identity") for a continuous proportion response. The count families (binomial, beta_binomial) require link = "identity" — the 4PL produces a probability directly, so any other link would double-transform it (an error is thrown). A known family name passed as a string (e.g. "binomial") is coerced to its identity-link constructor.

response_var

Response column name for a Beta (continuous proportion) fit. Ignored for count families. Default "survival" (the column standardize_data() writes for a proportion response).

temp_effects

Character vector naming which 4PL sub-parameters carry a temp_c slope: any subset of c("low", "up", "k", "mid"). Default is all four — temperature can affect every aspect of the dose-response curve. "mid" must always be present (its slope is -1/z, the core TDT quantity). Restricting to "mid" gives the classical constant-shape TDT model (asymptotes and slope shared across temperature), which is the right choice for sparse designs where the richer all-four model over-fits. Ignored in the direct CTmax/z parameterisation.

ctmax, z

One-sided formulas for the direct parameterisation. Supplying either switches make_4pl_formula() to fit CTmax (as CTmaxdev = CTmax - mean(temp)) and z (as logz) directly as nonlinear parameters, with mid reconstructed from them. Carry the fixed and random effects for tolerance and sensitivity, e.g. ~ life_stage + (1 | Date). Omit z for a single pooled z (logz ~ 1).

up, low, k

Optional one-sided formulas for the asymptote and steepness sub-parameters. In direct mode, when omitted they inherit the ctmax/z fixed effects crossed with temp_c (random effects are not inherited); intercept-only ctmax/z gives ~ temp_c. In midpoint mode they default to the temp_effects structure (or by, see below); an explicit formula always overrides.

mid

Midpoint mode only. Optional one-sided formula for the midpoint sub-parameter (whose temp_c slope is -1/z). Must carry temp_c. Defaults to the temp_effects/by structure. Errors in direct mode (where mid is reconstructed from ctmax/z).

by

Midpoint mode only. Optional character vector of moderator column(s). A shortcut that fits ~ temp_c * by on all four sub-parameters (low/up/k/mid) at once – i.e. every aspect of the curve, plus the midpoint's temperature slope (-1/z), varies by group. by is the more specific instruction, so it overrides temp_effects. Equivalent to writing the four ~ temp_c * by formulas by hand; use explicit formulas for finer per-parameter control. Errors in direct mode (group there via ⁠ctmax = ~ 0 + <moderator>⁠).

threshold

"relative" (default) fits the midpoint backbone so CTmax/z are the relative-threshold quantities; "absolute" bakes the asymmetry correction C(T) = (1/k)\log((up-p)/(p-low)) into mid so they are the absolute (p-survival) quantities. The disjoint-bounds reparam splits the asymptotes at the bounds' midpoint, so "absolute" is only well defined for p near that midpoint (with the default bounds ⁠[0, 1]⁠ the achievable range is roughly ⁠(0.499, 0.501)⁠); other LTx values (LT60, LT90, ...) must be obtained from a "relative" fit plus tls() with ⁠target_surv = ⁠, which inverts the fitted surface post hoc for any p.

p

Survival fraction defining the absolute threshold. Default 0.5. Only meaningful when threshold = "absolute", and (see threshold) only achievable for p near the bounds' midpoint – use the relative threshold + target_surv for any other LTx.

log10_tref

log10 of the reference exposure (in the model's time unit) at which CTmax is defined. Default 0 (one time unit). fit_4pl() derives this from t_ref and the data's duration unit.

lower, upper

Response-scale bounds for the asymptotes. Default ⁠0, 1⁠ for proportion data; set narrower for sublethal data whose response sits well above 0.

censored

Logical. TRUE adds brms's censoring term to a Beta response, ⁠<response_var> | cens(censored)⁠, so rows flagged "left"/"right" in a censored column enter the likelihood as the probability of lying beyond their limit. Default FALSE. fit_4pl() and the other fitters set it from the data when standardize_data() was given a detection_limit. Errors for the count families.

Details

The response term depends on the family:

  • Count families (binomial, beta_binomial): the response is ⁠n_surv | trials(n_total) ~ <4PL>⁠.

  • Beta family (continuous proportion): the response is ⁠<response_var> ~ <4PL>⁠ with no trials() term. With link = "identity" the 4PL value is the mean directly (safe because the reparam keeps it in ⁠(0, 1)⁠); with link = "logit" the 4PL is wrapped in logit() so the mean is still the 4PL value. With censored = TRUE the response becomes ⁠<response_var> | cens(censored) ~ <4PL>⁠: rows flagged "left" or "right" in a censored column contribute the probability of lying below or above their recorded limit instead of a density (see the detection_limit argument of standardize_data()).

If a parameter has no real temperature effect, its temp_c slope shrinks toward zero under the prior and the fit reduces cleanly to the simpler case.

Value

A brmsformula object.

Examples

make_4pl_formula()
make_4pl_formula(family = binomial(link = "identity"))
make_4pl_formula(temp_effects = "mid")            # constant-shape TDT
make_4pl_formula(family = brms::Beta(link = "identity"),
                 response_var = "survival")
make_4pl_formula(family = brms::Beta(link = "identity"),
                 censored = TRUE)           # censored readings
make_4pl_formula(ctmax = ~ life_stage, z = ~ life_stage)  # direct CTmax/z

bayesTLS documentation built on Nov. 29, 2026, 1:06 a.m.