fit_4pl: Fit the 4PL thermal-load-sensitivity model by maximum...

View source: R/fit_4pl.R

fit_4plR Documentation

Fit the 4PL thermal-load-sensitivity model by maximum likelihood (TMB)

Description

The frequentist analogue of bayesTLS::fit_4pl(). Consumes standardize_data() output and fits the single-stage 4PL thermal-load-sensitivity model, parameterised directly in CTmax and thermal sensitivity (z), via the freqTLS TMB engine. Returns a freq_tls workflow object; uncertainty (Wald / profile / bootstrap) is computed on demand by the quantity analogues (tls(), confint()).

Usage

fit_4pl(
  data,
  ctmax = NULL,
  z = NULL,
  up = NULL,
  low = NULL,
  k = NULL,
  by = NULL,
  threshold = c("relative", "absolute"),
  p = 0.5,
  t_ref = NULL,
  bounds = c(0, 1),
  family = NULL,
  method = c("profile", "wald", "bootstrap"),
  start = NULL,
  control = list(),
  trace = FALSE,
  quiet = FALSE,
  ...,
  fixed_low = NULL,
  fixed_up = NULL,
  fix_asymptotes = NULL,
  lower = NULL,
  upper = NULL
)

Arguments

data

Output of standardize_data(). The current function records input units there; for data created by an older release with a non-minute standardized-unit marker, fit_4pl() converts durations to minutes and reports the conversion.

ctmax, z, up, low, k, by

Direct-mode formula interface; see make_4pl_formula(). by gives fixed cell means for both ctmax and z. When ctmax and z are both supplied, their fixed-effect right-hand sides must produce the same model-matrix columns; their optional random-intercept terms may differ.

threshold

"relative" (default; CTmax/z at the curve midpoint) or "absolute" (at the p-survival level). The fitting backbone currently accepts only "relative"; obtain absolute-threshold quantities post fit with extract_tdt() and target_surv = "absolute".

p

Survival level for the absolute threshold (default 0.5).

t_ref

Positive reference exposure time at which CTmax is reported, in minutes. When NULL (the default), it is 60 minutes (one hour). standardize_data() converts the input duration to minutes; supply a numeric value such as 240 for a non-hour reference.

bounds

Finite ordered range for estimated asymptotes, contained in ⁠[0, 1]⁠. Defaults to c(0, 1). The bayesTLS aliases lower and upper can set either endpoint separately; they cannot be combined with a custom bounds value.

family

"beta_binomial" (default for counts), "binomial", or "beta". NULL picks beta for a proportion response, else beta-binomial.

method

Default interval method for downstream extraction ("profile", "wald", or "bootstrap"); stored in the object.

start

Initial values passed to the engine fit_tls().

control

A list containing optional optimizer controls for stats::nlminb() and an optional logical trace flag. Optimizer settings must be finite numeric values in their valid ranges; scale may be a positive numeric vector passed to nlminb(), while scale.init is a scalar. abs.tol = 0 disables the absolute convergence check. Integer controls must fit R's integer range. Bayesian HMC controls such as adapt_delta and max_treedepth are rejected because freqTLS does not run a sampler.

trace

Logical scalar; print optimiser progress. NA and non-logical values are rejected.

quiet

Logical; suppress diagnostic messages and warnings from the underlying fit when TRUE.

...

Recognized bayesTLS-only fitting arguments are rejected with guidance because freqTLS does not run Bayesian sampling. Use formulas for random-intercept structure and start, control, and quiet for the maximum-likelihood optimizer.

fixed_low

Optional exact value for the constant lower asymptote. It must lie in bounds and remain below the estimated upper band. This and the other asymptote controls are trailing named arguments, preserving the existing positional interface.

fixed_up

Optional exact value for the constant upper asymptote. It must lie in bounds and remain above the estimated lower band. Fix both to fit a two-parameter logistic curve.

fix_asymptotes

Bayesian-style asymptote pinning. TRUE fixes both to the padded edges of the disjoint bands; "low" or "up" fixes one, and a named numeric vector fixes selected values within their bands.

lower, upper

Optional bayesTLS-compatible aliases for the lower and upper endpoints of bounds; omitted endpoints retain 0 and 1. These aliases cannot be combined with a non-default bounds value.

Value

A freq_tls object: a list with ⁠$fit⁠ (the engine fit), ⁠$data⁠, ⁠$formula⁠, and ⁠$meta⁠ (threshold, t_ref, bounds, temp_mean, response_type, family, grouped, moderators, method).

Experimental software

Use freqTLS at your own risk. Results and APIs may be incorrect or change. Users are responsible for checking their data, design, model specification, convergence, identifiability, diagnostics, and interpretation. Important analyses should be independently refitted and cross-checked with bayesTLS (source repository). Agreement is a cross-check, not proof of correctness; shared data or model errors can make both packages agree.

Before interpretation

Run check_tls() before interpreting the fit. It gives a concrete recovery action for each data-adequacy warning; vignette("profile-likelihood") explains open profiles and the fit-specific bootstrap / Wald fallback.

See Also

standardize_data(), make_4pl_formula(), fit_tls(), check_tls()

Examples

raw <- simulate_tls(family = "binomial", times = c(30, 60, 120, 240, 480),
                    CTmax = 36, z = 4, tref = 60, seed = 1)
dat <- standardize_data(
  raw, temp = "temp", duration = "duration",
  n_total = "total", n_surv = "survived", duration_unit = "minutes"
)
fit <- fit_4pl(
  dat, family = "binomial", t_ref = 60, method = "wald", quiet = TRUE
)
coef(fit)
fit_2pl <- fit_4pl(
  dat, family = "binomial", t_ref = 60, fixed_low = 0, fixed_up = 1,
  quiet = TRUE
)

freqTLS documentation built on Dec. 4, 2026, 5:11 p.m.