fit_tls: Fit a single-stage thermal-load-sensitivity model by maximum...

View source: R/fit_tls.R

fit_tlsR Documentation

Fit a single-stage thermal-load-sensitivity model by maximum likelihood

Description

fit_tls() fits a descending thermal-survival model to binomial or beta-binomial counts, or to continuous proportions with the Beta family. The default mean curve is the four-parameter log-logistic curve; log-normal and two Weibull curves are opt-in alternatives. The model uses CTmax (the critical thermal maximum at reference time tref) and z (thermal sensitivity, degrees Celsius per decade of duration) as direct coordinates, so both headline quantities can be profiled. Survival is a function of log10(duration), with its midpoint moving through CTmax and z. The default curve preserves the matched bayesTLS benchmark; optional curves use curve-specific steepness scales k (see vignette("model-math")). The thermal-load-sensitivity modelling framework was introduced by Daniel W. A. Noble, Pieter A. Arnold, Shinichi Nakagawa, and Patrice Pottier in bayesTLS.

Usage

fit_tls(
  x,
  y,
  n,
  time,
  temp,
  group = NULL,
  family = c("beta_binomial", "binomial", "beta"),
  tref = NULL,
  start = NULL,
  control = list(),
  trace = FALSE,
  quiet = FALSE,
  data = NULL,
  left_censored = NULL,
  censor_limit = NULL,
  bounds = c(0, 1),
  fixed_low = NULL,
  fixed_up = NULL,
  curve = "loglogistic"
)

Arguments

x

Either a data frame (column interface) or a tls_formula from tls_bf() (formula interface). For back-compatibility the first argument is still positional, so fit_tls(my_data, y = survived, ...) continues to work.

y

<data-masked> Column of successes (survivors), or, for the beta family, the response proportion in ⁠(0, 1)⁠.

n

<data-masked> Column of trials (total individuals). Required for the binomial and beta-binomial families; omit it for the beta family, whose response is already a proportion.

time

<data-masked> Column of exposure durations in minutes; used as log10(duration) internally.

temp

<data-masked> Column of assay temperatures (degrees C).

group

<data-masked> Optional grouping column. When supplied, each group gets its own direct, profile-able CTmax and z with shared low, up, and k. Defaults to NULL (a single ungrouped fit).

family

One of "beta_binomial" (default), "binomial", or "beta" (a continuous proportion in ⁠(0, 1)⁠), or a tls_family object from beta_binomial_tls() / binomial_tls() / beta_tls().

tref

Reference time at which CTmax is defined, in minutes. When NULL (the default), it is 60 minutes (one hour). Use standardize_data() to convert a raw duration column before fitting; bare formula/column data must already use minutes.

start

Optional named list of starting values on the internal (unconstrained) scale, overriding the defaults. Names must match the parameters in src/profile_tls.cpp (beta_low, beta_up, beta_logk, beta_CT, beta_logz, log_phi).

control

List of optimiser controls; optimizer is passed to stats::nlminb()'s control, and trace toggles optimiser output. Optimizer settings must be finite numeric values in their valid ranges; scale may be a positive numeric vector and is passed to nlminb(); scale.init is one positive scalar, and abs.tol = 0 disables the absolute convergence check. Integer controls must fit R's integer range. Unrecognised controls and Bayesian HMC settings such as adapt_delta and max_treedepth are rejected.

trace

Logical scalar; print optimiser progress. NA and non-logical values are rejected. TRUE also enables control$trace.

quiet

Logical; if TRUE, suppress freqTLS's own data-adequacy and identifiability diagnostic warnings and messages (the few-groups, beta boundary-clamp, and same-grouping notes). Genuine errors and optimiser warnings still surface, and check_tls() reports the diagnostics on demand. Default FALSE.

data

Used only in the formula interface: the data frame the tls_bf() columns are resolved against. Ignored in the column interface (where the data frame is x).

left_censored

Optional non-missing logical vector marking Beta observations known only to lie below a detection limit. Supply it together with censor_limit; zero responses are never treated as censored automatically. On flagged rows y is a finite placeholder and the fit uses the probability below the limit.

censor_limit

Numeric scalar or one value per observation giving the explicit lower detection limit for left_censored Beta observations. Values must be finite and strictly between 0 and 1.

bounds

Finite ordered lower and upper limits for the asymptotes. Defaults to c(0, 1).

fixed_low

Optional exact natural-scale value for the constant lower asymptote. It must stay below the estimated upper band.

fixed_up

Optional exact natural-scale value for the constant upper asymptote. It must stay above the estimated lower band. Fix both for a 2PL.

curve

Mean-survival curve: "loglogistic" (default), "lognormal", "weibull1", or "weibull2". This selects the curve shape independently of the response family. All curves use mid for the halfway point between low and up, so CTmax and z retain their relative-midpoint meaning.

Details

There are two equivalent interfaces. In the column interface, columns are referenced with tidy evaluation: pass the bare column names of data (as in dplyr), not strings. In the formula interface, pass a tls_bf() object as x and the data frame as data; the brms/drmTMB-style grammar names the response, the two axes, and the CTmax / log_z predictors. Both interfaces feed the same likelihood engine, so a grouped formula fit and the matching ⁠group =⁠ column fit are numerically identical.

Value

An object of class c("profile_tls", "tls_fit"): a list with the call, the resolved family, tref, group_levels, a data_summary, the internal-scale MLE par, an estimates data frame of natural-scale parameters with standard errors, the vcov of the internal coordinates, the logLik, residual df, AIC, a convergence list (code/pdHess/message), the name_map, and the underlying TMB obj, optimiser opt, and sdreport. ⁠$curve⁠ records the selected mean curve.

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() on the fitted object. Its help page maps every data-adequacy warning to a concrete design or analysis response. vignette("profile-likelihood") explains open profiles and their method- specific fallbacks: bootstrap for fixed-effects fits and Wald for random- effects fits.

See Also

check_tls(), confint.profile_tls()

Examples

d <- simulate_tls(family = "binomial", times = c(30, 60, 120, 240, 480),
                  CTmax = 36, z = 4, tref = 60, seed = 1)
fit <- fit_tls(d, y = survived, n = total, time = duration, temp = temp,
               family = "binomial", tref = 60)
fit$estimates

# The same fit through the formula interface:
fit2 <- fit_tls(
  tls_bf(survived | trials(total) ~ time(duration) + temp(temp)),
  data = d, family = "binomial", tref = 60
)


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