predict.profile_tls: Predict survival, link, or midpoint from a fitted freqTLS...

View source: R/predict.R

predict.profile_tlsR Documentation

Predict survival, link, or midpoint from a fitted freqTLS model

Description

predict() evaluates the fitted four-parameter thermal-load-sensitivity model at new temperature-by-duration cells, using exactly the same forward map as the TMB engine in src/profile_tls.cpp:

Usage

## S3 method for class 'profile_tls'
predict(
  object,
  newdata,
  type = c("survival", "link", "midpoint", "parameters"),
  re.form = c("population", "conditional"),
  ...
)

## S3 method for class 'freq_tls'
predict(
  object,
  newdata,
  type = c("survival", "link", "midpoint", "parameters"),
  re.form = c("population", "conditional"),
  ...
)

Arguments

object

A profile_tls fit from fit_tls().

newdata

A data frame with numeric columns temp and duration, plus every predictor used in the fitted CTmax, log_z, low, up, and log_k fixed designs. Include group for a grouped column-interface fit. For a formula fit whose temp() axis uses another source-column name, temperature-dependent shape predictions rebuild that source column from newdata$temp. Conditional random-effect predictions additionally require every fitted grouping column. duration must be strictly positive (it is log10-transformed). For type = "midpoint" or "parameters", duration may be omitted.

type

One of "survival" (default), "link", "midpoint", or "parameters".

re.form

How to handle fitted random intercepts. "population" (default) sets them to zero; "conditional" adds the fitted BLUP for each random-effect grouping column in newdata. When omitted for a random- effects fit, predict() warns that it is returning a population prediction.

...

Reserved; must be empty.

Details

Here CTmax is the critical thermal maximum at the reference duration tref; z is thermal sensitivity in degrees per order-of-magnitude change in duration; low and up are the fitted lower and upper survival asymptotes; and k controls the curve's steepness. The model fits log_z = log(z) internally, then reports positive natural-scale z values.

All supported curves use mid = log10(tref) - (temp - CTmax) / z. The selected curve then maps eta = k * (log10(duration) - mid) to survival. The default log-logistic fraction is plogis(-eta); curve also accepts the log-normal and two midpoint-centred Weibull forms.

Four response types are available:

  • "survival" (default) returns the fitted survival probability in ⁠(0, 1)⁠.

  • "link" returns the logit of the survival probability, qlogis(survival).

  • "midpoint" returns the temperature-dependent curve midpoint mid on the log10(duration) axis (constant within a temperature, so the duration column is ignored for this type but a temp column is still required).

  • "parameters" returns the row-specific natural-scale CTmax, z, low, up, and k values. This is useful for interacted formula designs; the duration column may be omitted.

newdata must also contain every predictor used by the fitted fixed-effect designs for CTmax, log_z, low, up, or log_k. For a grouped column- interface fit, supply group with values from the fitted group_levels. For a formula fit, a literal tls_bf() call preserves the fixed-design formulas needed to rebuild transformed or interacted terms. If the model was instead passed through a formula-object variable, predict() can rebuild direct numeric design columns but asks the user to refit with a literal tls_bf() call when a transformed or interacted design cannot be recovered safely.

Value

For type = "parameters", a data frame with one row per row of newdata and columns CTmax, z, low, up, and k. Otherwise a numeric vector with one element per row; survival values lie in ⁠(0, 1)⁠.

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)
nd <- expand.grid(temp = c(34, 36, 38), duration = c(60, 120, 240))
predict(fit, nd, type = "survival")

# A continuous predictor used by CTmax and log_z must also be in newdata.
d$x <- rep(c(-1, 1), length.out = nrow(d))
fit_x <- fit_tls(
  tls_bf(survived | trials(total) ~ time(duration) + temp(temp),
         CTmax ~ x, log_z ~ x),
  data = d, family = "binomial", tref = 60
)
predict(fit_x, data.frame(temp = 36, duration = 60, x = c(-1, 1)))


# Choose population or fitted-group prediction explicitly for an RE fit.
dre <- simulate_tls(family = "binomial", CTmax = 36, z = 4,
                    times = c(30, 60, 120, 240, 480), tref = 60,
                    re_sd = 1, n_re_groups = 8, seed = 2)
fit_re <- fit_tls(
  tls_bf(survived | trials(total) ~ time(duration) + temp(temp),
         CTmax ~ 1 + (1 | colony)),
  data = dre, family = "binomial", tref = 60
)
colony <- as.character(ranef(fit_re)$group[1])
nd_re <- data.frame(temp = 36, duration = 60, colony = colony)
predict(fit_re, nd_re, re.form = "population")
predict(fit_re, nd_re, re.form = "conditional")



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