tls: Thermal load sensitivity summaries from any fitted 4PL model

View source: R/tls.R

tlsR Documentation

Thermal load sensitivity summaries from any fitted 4PL model

Description

One call that derives the classical TDT quantities — thermal sensitivity z, CTmax, and (for lethal endpoints) T_crit — per moderator group from a fitted joint 4PL, including hand-written brms models with moderators (sex, life stage, clone, ...) on any sub-parameter. The four sub-parameters are evaluated at a moderator x temperature grid with brms::posterior_linpred(), then z, CTmax and T_crit are derived from the same posterior draws (so they are mutually consistent and T_crit pairs CTmax and z per draw).

Usage

tls(
  object,
  by = NULL,
  params = "all",
  target_surv = "relative",
  t_ref = NULL,
  time_multiplier = NULL,
  lethal = FALSE,
  TC_rate_range = c(0.1, 1),
  temp = "temp_c",
  temp_mean = NULL,
  temp_grid = NULL,
  re_formula = NA,
  lower = 0,
  upper = 1,
  nlpars = c("lowraw", "upraw", "logk", "mid"),
  ndraws = NULL,
  newdata = NULL,
  probs = c(0.025, 0.5, 0.975),
  seed = NULL,
  mode = NULL,
  p = NULL
)

tls_z(object, ...)

tls_ctmax(object, ...)

tls_tcrit(object, ...)

Arguments

object

A fitted bayes_tls workflow or a brmsfit 4PL whose non-linear parameters are the (reparameterised) asymptotes, steepness and midpoint. The dose-response model is read from the workflow; a bare brmsfit is recognised from its formula, and a hand-written formula is treated as the log-logistic.

by

Character vector of moderator columns defining the groups reported separately (e.g. "sex"). NULL (default) uses the fit's own groups, as the other readers do: a bayes_tls workflow fitted with a moderator (e.g. ctmax = ~ 0 + recovery, or ⁠by =⁠ in fit_4pl()) is reported per group, and a single-condition fit as one group. A bare brmsfit whose CTmax/z (or midpoint) vary by a moderator needs by given explicitly (an error says so). With a user-supplied newdata grid, NULL treats the whole grid as one group.

params

Quantities to return: "all" (z, CTmax, and T_crit when lethal = TRUE), or a subset of c("z", "ctmax", "tcrit").

target_surv

Survival threshold the LT curve is read at: "relative" (default; the per-draw midpoint (low + up)/2), "absolute" (literal LT50), or a numeric p in ⁠(0, 1)⁠ for an absolute LTp.

t_ref

Reference exposure duration for CTmax, in minutes. If NULL (default), inherit the fit's own reference exposure (meta$t_ref) and report it via a message; a raw brmsfit with no recorded reference falls back to 60. Converted to the model's time scale via time_multiplier.

time_multiplier

Multiplier from the model's time unit to minutes. NULL (default) derives it from a bayes_tls workflow's duration_unit (e.g. 60 for an hours model); a raw brmsfit with no metadata defaults to 1, so t_ref is then in the model's own time units.

lethal

Logical; with TRUE, T_crit (rate-multiplier) is available. T_crit is meaningful only for damage-accumulation (lethal) endpoints.

TC_rate_range

Length-2 HI-rate floor range (% per hour) for T_crit.

temp

Name of the centred temperature column. Default "temp_c".

temp_mean

Centring constant mapping temp back to temperature, needed for CTmax/T_crit. Taken from a bayes_tls workflow's metadata when available; supply it for a raw brmsfit.

temp_grid

Temperatures on the centred temp scale (temperature minus temp_mean, unlike the derive_*() readers, which take degrees C) at which the LT curve is evaluated. z is the local z(T) pooled over this grid. CTmax (and the 1-hour anchor of T_crit) is exact when the LT curve is a straight line in temperature; when it bends (see Details) it is inverted on this grid, refined first so that neighbouring points are at most 0.05 degrees apart (each interval is split into at most 20 equal steps, so a grid coarser than 1 degree is refined to a twentieth of its spacing), by linear interpolation between the refined points. Draws that do not cross on it are searched outward, beyond each end by the data's temperature range or the grid's own width, whichever is larger. Draws left without a crossing are reported in a warning. Default: 11 points over the observed range. A grid lying entirely outside the observed temperatures, or reaching more than the data's own temperature range beyond them, warns, since that is what a grid given in degrees C usually looks like (the check cannot tell the scales apart for data near 0 degrees C).

re_formula

Passed to brms::posterior_linpred(); default NA (fixed effects only) – EXCEPT when a by variable enters the model only as a random-effect grouping factor (e.g. a phylogenetic (1 | gr(species, cov = A)) term): the default then auto-includes exactly the matching random-effect term(s), with a message, so per-level estimates do not silently collapse to the population mean. Passing re_formula explicitly (even NA) always overrides the auto-rule. (population level). Include group-level terms (e.g. clone) for per-group draws.

lower, upper

Response bounds of the disjoint-bounds reparameterisation. Read from a bayes_tls workflow (the bounds it was fitted with); supply them for a bare brmsfit fitted with non-default bounds, or to override.

nlpars

Non-linear parameter names, ordered low / up / k / mid (raw scale).

ndraws

Optional number of posterior draws to subsample: one subsample, shared by all four sub-parameters. A value at least the posterior size uses all draws.

newdata

Optional explicit moderator x temperature grid; overrides the by/temp_grid construction.

probs

Summary quantiles (lower, median, upper). Default c(.025,.5,.975).

seed

Optional integer seeding the draw subsample (ndraws) and the T_crit rate draws for reproducibility. NULL (default) leaves the RNG alone.

mode, p

Deprecated, superseded by target_surv. If supplied, mode = "relative" maps to target_surv = "relative" and mode = "absolute" (with p) to target_surv = p. Kept for back-compat.

...

Additional arguments passed on to tls() (used by the tls_z(), tls_ctmax() and tls_tcrit() convenience wrappers).

Details

tls() derives z, CTmax and T_crit from the same posterior draws, so on a common temperature grid they are mutually consistent for every threshold. z is the central-difference local z(T) (negative reciprocal of the local slope of log10(LT) on temperature) pooled over temp_grid; CTmax is the per-draw temperature at which the fitted LT curve crosses t_ref: from the exact closed form whenever log10(LT) is a straight line in temperature (checked on the evaluated curve, for every draw), and by per-draw inversion of the bent curve otherwise. Under target_surv = "relative" (the default) log10(LT) = mid(T) is linear for midpoint and direct fits alike, so z is constant in temperature and equals -1 / b_mid_temp_c, and CTmax is exact even far outside the data; an absolute threshold is linear too when the asymptotes and steepness do not change with temperature. With temperature effects on the asymptotes or steepness, an absolute threshold bends the curve: the local z(T) follows it, and CTmax is the curve's crossing of t_ref, interpolated linearly between the points of the refined grid (see temp_grid). The crossing taken is the one where the LT shortens through t_ref as temperature rises; a draw with none, or more than one, has no CTmax. Near an asymptote the LT at an absolute p can be undefined at some temperatures (p outside the fitted asymptotes there); it is then treated as zero (upper asymptote at or below p) or infinite (lower asymptote at or above p), so a crossing next to such a temperature is still found.

Value

A tls object: ⁠$summary⁠ (per-group, per-quantity median + interval), ⁠$draws⁠ (per-group, per-quantity posterior draws), and ⁠$meta⁠.

Examples

## Not run: 
tls(joint_sex_fit, by = "sex", lethal = TRUE, temp_mean = 36.1)  # z, CTmax, T_crit per sex
tls(wf_leaf, params = "z")                                       # z only, workflow

## End(Not run)

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