Getting started with freqTLS

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4,
  dpi = 96
)

freqTLS fits single-stage thermal-load-sensitivity (TLS) / thermal death-time models by maximum likelihood, parameterised directly in CTmax (the critical thermal maximum at the reference time tref) and z (thermal sensitivity, degrees Celsius per order-of-magnitude change in exposure duration). It returns prior-free frequentist confidence intervals — Wald, profile-likelihood (asymmetry-respecting, the default), and bootstrap. It is the likelihood complement to the Bayesian bayesTLS package. The default is the log-logistic 4PL used for the matched bayesTLS benchmark; fit_tls() also supports log-normal and two midpoint-centred Weibull curves (see vignette("model-math")). The thermal-load-sensitivity modelling framework was introduced by Daniel W. A. Noble, Pieter A. Arnold, and Patrice Pottier; see vignette("comparing-to-bayesTLS") for the comparison boundary.

This vignette walks through the core loop: simulate → fit → confidence intervals → plot. It runs end to end with a small simulation and needs no Stan, no MCMC, and no internet.

library(freqTLS)

Simulate a dataset

simulate_tls() draws survival counts from the locked data-generating process: a factorial grid of assay temperatures and exposure durations, with the 4PL evaluated at the supplied true CTmax, z, and shape parameters. We use the overdispersed beta-binomial family here; phi is its precision parameter — larger phi means less overdispersion, approaching the ordinary binomial as phi grows.

set.seed(1)
dat <- simulate_tls(
  temps  = seq(30, 42, by = 2),
  times  = c(30, 60, 120, 240, 480),
  reps   = 3,
  n      = 20,
  CTmax  = 36,
  z      = 4,
  phi    = 50,
  family = "beta_binomial",
  tref   = 60,
  seed   = 1
)
head(dat)

Each row is one temperature-by-duration cell: survived out of total individuals survived the exposure. The true parameters used to generate the data are kept as an attribute, which is handy for checking recovery:

attr(dat, "truth")[c("CTmax", "z", "phi")]

Standardise and fit the model

freqTLS mirrors the bayesTLS workflow. First standardize_data() names the temperature, duration, and survival-count columns and records the data contract; then fit_4pl() fits the 4PL by maximum likelihood and returns a freq_tls workflow object. t_ref is the reference time at which CTmax is defined, in minutes. standardize_data() converts recognised input duration units to minutes, so the omitted default is one hour (t_ref = 60). A supplied numeric reference is never converted: t_ref = 1 deliberately means CTmax at one minute. Bare formula/column data must already use minutes.

std <- standardize_data(
  dat,
  temp     = "temp",
  duration = "duration",
  n_total  = "total",
  n_surv   = "survived",
  duration_unit = "minutes"
)
fit <- fit_4pl(std, family = "beta_binomial")
fit

Formula interface

For the supported moderators, fit_4pl() takes a similar direct interface to bayesTLS — ctmax =, z =, or the by = shorthand (for example, by = "population"). The engine also exposes the explicit 4PL formula grammar through tls_bf(): the response is survival counts, time() identifies duration, and temp() identifies assay temperature. The following formula fits the default log-logistic 4PL rather than an ordinary linear model; it matches the preceding fit:

fit_f <- fit_tls(
  tls_bf(survived | trials(total) ~ time(duration) + temp(temp)),
  data   = dat,
  family = "beta_binomial",
  tref   = 60
)
stopifnot(isTRUE(all.equal(coef(fit_f), coef(fit), tolerance = 1e-8)))

The grammar also supports fixed effects on each model coordinate. Independent random intercepts are available for CTmax, log_z, low, and log_k; only CTmax accepts multiple additive grouping terms. up supports fixed effects but not random effects. See Going further below for the exact boundaries.

Printing fit reports the data, family, reference time, fitted formulas, and convergence status. summary(fit) reports the parameter estimates and Wald tests; it marks continuous shape coefficients on their link scale and adds the log-likelihood:

summary(fit)

Continuous proportions with a detection limit

For continuous survival proportions, the beta family can account for an assay that records only that survival fell below a known lower detection limit. Supply an explicit logical censor flag and the limit; freqTLS uses the Beta probability below that limit for flagged rows. It never infers censoring from a zero. This example creates thresholded observations from a simulated Beta dataset and reports the censor count and limit range in the fitted-model printout.

beta_raw <- simulate_tls(
  family = "beta", times = c(30, 60, 120, 240, 480), reps = 5,
  CTmax = 36, z = 4, phi = 35, tref = 60, seed = 22
)
detection_limit <- 0.02
beta_raw$limit <- detection_limit
beta_raw$below_limit <- beta_raw$prop <= detection_limit
beta_raw$recorded_prop <- ifelse(beta_raw$below_limit, detection_limit,
                                 beta_raw$prop)
stopifnot(any(beta_raw$below_limit))

beta_std <- standardize_data(
  beta_raw, temp = "temp", duration = "duration", proportion = "recorded_prop",
  left_censored = "below_limit", censor_limit = "limit",
  duration_unit = "minutes"
)
beta_fit <- fit_4pl(beta_std, family = "beta", t_ref = 60, quiet = TRUE)
beta_fit

The likelihood uses exact Beta densities for uncensored proportions and the lower-tail probability for flagged rows. Use the fit diagnostics to check that the censoring pattern still identifies the thermal curve; if the profile does not close, inspect the assay limit and use a bootstrap interval as a sensitivity check.

A tidy, broom-style table reports constant and cell-mean shapes on the natural scale, while general shape coefficients and their Wald limits remain on the fitted link scale. Its scale column describes the displayed estimate and confidence limits: it says natural for response-scale estimates and names the link for general shape coefficients. Covariate-model z rows are exponentiated multipliers on the natural scale. Dedicated extractors are useful when a later analysis needs only the headline quantities:

tidy_parameters(fit)
get_ctmax(fit)
get_z(fit)

Profile-likelihood confidence intervals

The reason for the direct CTmax/z parameterisation is that both headline quantities are model parameters, so they can be profiled directly. confint() with method = "profile" (the default) inverts the likelihood-ratio test: the interval is the set of values whose deviance from the maximum stays below the profile-$t$ cutoff (a squared Student-$t$ quantile on the residual degrees of freedom, not $\chi^2_1$; see vignette("frequentist-and-bayesian")), found by root-finding on each side of the MLE.

confint(fit, parm = "CTmax", method = "profile")
confint(fit, parm = "z", method = "profile")

These are confidence intervals, not posteriors: they carry no prior, and they need not be symmetric about the estimate. Check both method and conf.status: conf.status = "ok" means the profile closed only when method = "profile". With the default fallback, an open or weakly identified profile may instead return a Wald or bootstrap interval, which has a different method. Set fallback = FALSE to inspect the profile-only result (see vignette("profile-likelihood")).

For comparison, the first-order Wald interval is available with method = "wald":

confint(fit, parm = c("CTmax", "z"), method = "wald")

Plot the fit

plot_survival_curves() draws the fitted survival probability against exposure duration, one curve per temperature, with the observed proportions overlaid:

plot_survival_curves(fit)

The default uncertainty display is the Confidence Eye: a pale confidence lens with a hollow point estimate. It is freqTLS's visual identity and deliberately avoids posterior-density iconography, because these are likelihood intervals. Read the lens width as the confidence interval and the hollow circle as the maximum-likelihood estimate. Do not use overlap as a hypothesis test; inspect the reported contrast or confidence interval for that question. With fallback enabled, the lens may show a Wald or bootstrap interval when a profile does not close, so check the method and conf.status in confint(). The plot call returns a ggplot, not the interval table:

plot_confidence_eye(fit, parm = c("CTmax", "z"), method = "profile")
profile_ci <- confint(fit, parm = c("CTmax", "z"), method = "profile")
profile_ci[c("parameter", "method", "conf.status")]

To inspect an open profile directly without an automatic fallback, set fallback = FALSE. An unavailable interval may reflect an open profile, an invalid profile center, or an unusable Hessian; read conf.status before interpreting missing limits.

Going further: groups, shape predictors, and random effects

The same tls_bf() grammar scales from the single fit above to grouped, covariate, and hierarchical models.

Other families. Besides "beta_binomial", fit_tls() accepts "binomial" (no overdispersion) and "beta" (a continuous proportion in (0, 1) with no trials column; the runnable example below uses simulated beta data).

Grouped CTmax and z. Put a grouping factor on a sub-parameter to estimate a separate, directly profile-able CTmax and z per group, with one shared curve shape (the bayesTLS constant-shape configuration). In the formula, z enters on its internal log scale as log_z (and steepness as log_k), so the grouped term is written log_z ~ group. Intervals are still requested by the natural-scale name (z:cool, not log_z:cool) — confint() converts internally:

dat_grp <- simulate_tls(
  temps = seq(30, 42, by = 2), times = c(30, 60, 120, 240, 480), reps = 3, n = 20,
  group = c("cool", "warm"), CTmax = c(34, 38), z = c(3, 5),
  phi = 50, family = "beta_binomial", tref = 60, seed = 2
)
fit_grp <- fit_tls(
  tls_bf(
    survived | trials(total) ~ time(duration) + temp(temp),
    CTmax ~ group,
    log_z ~ group
  ),
  data = dat_grp, family = "beta_binomial", tref = 60
)
tidy_parameters(fit_grp)
confint(fit_grp, c("CTmax:cool", "CTmax:warm", "z:cool", "z:warm"),
        method = "profile")

Shape predictors. The shape parameters are no longer intercept-only: low, up, and log_k each take their own grouping factor or continuous covariate (for example low ~ group or log_k ~ body_size). See ?tls_bf.

A random intercept. Add an lme4-style (1 | group) term to let a sub-parameter vary across groups drawn from a population — here CTmax varies by colony:

dat_re <- simulate_tls(
  temps = seq(30, 42, by = 2), times = c(30, 60, 120, 240, 480), reps = 2, n = 20,
  CTmax = 36, z = 4, phi = 50, family = "beta_binomial",
  re_sd = 1.2, n_re_groups = 10, tref = 60, seed = 3
)
fit_re <- fit_tls(
  tls_bf(
    survived | trials(total) ~ time(duration) + temp(temp),
    CTmax ~ (1 | colony)
  ),
  data = dat_re, family = "beta_binomial", tref = 60
)
fit_re
head(ranef(fit_re))

The intercept is integrated out by a Laplace approximation; sigma_CTmax is its standard deviation and ranef() returns the per-colony BLUPs. The population CTmax interval is profiled under the random effect (confint(fit_re, "CTmax"), the default), so uncertainty in the variance component is included. Independent random intercepts are supported on CTmax, log_z, low, and log_k, with multiple additive grouping terms on CTmax; see vignette("random-effects") for the hierarchical workflow. Interpret variance components and intervals cautiously with few groups. In a binomial random-intercept simulation, coverage could fall below the nominal level even when the fit converged.

The core workflow at a glance

freqTLS deliberately follows the standardise → fit → quantities → plot workflow used in bayesTLS, while keeping its own maximum-likelihood API. The map below shows the main freqTLS workflow and selected analogous roles, not a one-to-one map of current bayesTLS functions. extract_tdt() remains an optional compatibility-oriented bootstrap bundle; tls() is the primary quantity extractor in this package. The "freqTLS extras" box (gold, upper right) is the frequentist-only addition: Wald, profile, and bootstrap intervals plus the Confidence Eye. The diagram's dashed panel marks user-supplied temperature traces and repair scenarios. predict_heat_injury() evaluates those scenarios, but freqTLS does not fit a heat-injury or repair sub-model.

# Inline the SVG rather than include_graphics() so the figure does not depend on
# pkgdown copying a co-located static asset. The Pandoc raw-HTML fence is
# essential: without it, wildcard labels such as get_*_summary() are parsed as
# Markdown emphasis, which breaks the SVG namespace. Accessibility is provided
# by the SVG's <title>/<desc>.
svg_candidates <- c(
  "freqTLS_function_map.svg",
  system.file("doc", "freqTLS_function_map.svg", package = "freqTLS")
)
svg_path <- svg_candidates[nzchar(svg_candidates) & file.exists(svg_candidates)][1]
if (is.na(svg_path)) {
  stop("The installed freqTLS function-map SVG is missing.")
}
svg_lines <- readLines(svg_path, warn = FALSE)
cat(
  "```{=html}\n",
  paste(svg_lines, collapse = "\n"),
  "\n```\n",
  sep = ""
)

Where to next

Before interpreting any fitted model, run check_tls(fit). The recovery guide in ?check_tls maps each warning to the next design or analysis action; the profile article explains bootstrap fallback for fixed-effects fits, Wald fallback for random-effects fits, and the strict fallback = FALSE open-profile diagnostic.



Try the freqTLS package in your browser

Any scripts or data that you put into this service are public.

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