make_tdt_formula: Build the brms formula for a joint Bayesian four-parameter...

View source: R/fit_4pl.R

make_tdt_formulaR Documentation

Build the brms formula for a joint Bayesian four-parameter dose-response model

Description

Model-generic twin of make_4pl_formula(): the same construction with the curve chosen by model. make_4pl_formula() is make_tdt_formula(model = "log-logistic") and keeps meaning the log-logistic.

Usage

make_tdt_formula(
  model = "log-logistic",
  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

model

Dose-response curve: "log-logistic" (the 4PL), "log-normal" (probit), "weibull1" (Weibull type 1, the Gompertz-shaped curve on log time) or "weibull2" (Weibull type 2). Every model is written in its midpoint form, so mid, the TDT line, z and CTmax mean the same thing for all of them; only the shape of the curve and the absolute-threshold correction differ.

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) or "absolute", as in make_4pl_formula(), except that "absolute" bakes the chosen model's correction into mid: (1/k)\log((up-p)/(p-low)) for the log-logistic, and the log-normal and Weibull models' own closed forms otherwise.

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.

Value

A brmsformula object.

Examples

make_tdt_formula(model = "log-normal")
make_tdt_formula(model = "weibull1", ctmax = ~ 1, z = ~ 1)

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