predict_heat_injury: Predict heat injury and survival under a fluctuating...

View source: R/predict_heat_injury.R

predict_heat_injuryR Documentation

Predict heat injury and survival under a fluctuating temperature trace

Description

Propagates the model's full posterior through an Eulerian damage- accumulation integration along the supplied temperature trace, returning the posterior median and 95% credible band of:

Usage

predict_heat_injury(
  trace,
  workflow,
  target_surv = "relative",
  T_c = NULL,
  trace_unit = "hours",
  ndraws = NULL,
  repair = FALSE,
  repair_pars = NULL,
  repair_scales_with_survival = TRUE,
  irreversible_mortality = TRUE,
  save_draws = FALSE,
  seed = NULL,
  by = NULL,
  shape = c("constant", "varying"),
  varying_method = c("individual", "cumulative")
)

Arguments

trace

Tibble with columns time (numeric time from start, in trace_unit) and temp (°C), in time order. Requires >= 2 rows.

workflow

Fitted bayes_tls.

target_surv

Threshold defining "1 dose". "relative" (default; (low + up)/2), "absolute" (= 0.5), or a numeric in ⁠(0, 1)⁠. The default coincides with the classical LT50 when low is about 0 and up about 1; with sub-unit asymptotes the relative threshold is the more biologically meaningful anchor for dose accounting. With the constant shape, a draw whose curve at the centring temperature cannot reach an absolute target gives no prediction (a warning reports how many). With shape = "varying" and no repair, the target sets the heat injury only; survival does not depend on it (with repair it does, through the units of r_ref; see repair_pars). In the varying shape (either varying_method), heat injury for an absolute target is the injury of the individual of that survival rank. Where the target is at or above a trace temperature's upper asymptote, that individual dies on exposure there (above T_c), and heat injury is Inf (with a warning) while injury accrued there is outstanding (repair that clears all injury resets it); where it is at or below the lower asymptote, that temperature adds no injury to it.

T_c

Optional damage-accumulation threshold (°C). When supplied, the damage rate is forced to zero at temp <= T_c (matches the heat-injury integral, Equation 8 of the manuscript). Default NULL lets the rate fall naturally with T.

trace_unit

Time unit of the trace's time column: one of "hours" (default), "minutes", "seconds", "days". Reconciled internally with the model's fitted duration_unit, so the result is correct for any combination of model and trace time units.

ndraws

Posterior draws to use; NULL (default) uses the full posterior, keeping the integral consistent with the model. Pass an integer to subsample – useful for speed, since the full posterior over a long temperature trace can be slow.

repair

Logical. If TRUE, add Sharpe-Schoolfield repair. Default FALSE.

repair_pars

Required when repair = TRUE. Named list with elements ⁠TA, TAL, TAH, TL, TH, TREF, r_ref⁠ passed straight to repair_rate_schoolfield(). r_ref is in doses per hour, the damage-rate units, where a dose is the threshold time of target_surv; a given r_ref therefore repairs more or less depending on the target. (With shape = "varying", injury is kept in doses of the relative threshold, r_ref is converted with the two thresholds' ratio at the centring temperature, as in the constant shape; repair removes the same fraction of every individual's injury, or with varying_method = "cumulative" lowers the shared injury by the repair amount.)

repair_scales_with_survival

Logical. If TRUE (default), repair rate at each step is scaled by survival / up so dead organisms do not contribute to repair. (With shape = "varying", up is that of the first temperature that accrues injury, where survival starts, so the scale is at most 1.)

irreversible_mortality

Logical. If TRUE (default), survival can only decrease over time — i.e. once the population's predicted survival reaches a value, it cannot rebound even if cumulative dose subsequently decreases.

save_draws

Logical. If TRUE, return the full per-draw trajectories. Default FALSE.

seed

Optional integer seeding the posterior-draw subsample for reproducibility. NULL (default) leaves the RNG untouched.

by

Optional moderator column(s) for per-group injury. NULL (default) uses the fit's moderators; a single-condition fit returns the ungrouped result. A grouped fit runs the dose integral through each group's 4PL and summary gains the moderator column(s).

shape

How the curve's shape enters the prediction. "constant" (default) holds low, up and k at the centring temperature T_bar and lets only the midpoint shift with temperature, along a straight line through its value at T_bar: survival is read off that one curve at the accumulated dose, the classical constant-shape heat-injury assumption (via hi_pars()). "varying" (experimental) uses the temperature-local low(T), up(T), k(T) and mid(T) (via extract_4pl_pars()); varying_method sets how survival follows them. See the section "Varying shape".

varying_method

For shape = "varying" only: "individual" (default; each individual accumulates injury against its own threshold time) or "cumulative" (cumulative exposure: survival is the state). See the section "Varying shape".

Details

  • HI(t) — cumulative heat injury, in percent of an LT_target_surv dose. When HI(t) = 100, the population has accumulated one full dose at the chosen survival threshold (by default midway between the asymptotes, (low + up)/2).

  • S(t) — predicted survival fraction. With shape = "constant" it is read off the fitted dose-response curve (the log-logistic for fit_4pl(), the log-normal or Weibull curve for fit_lognormal() / fit_weibull()) at the cumulative dose; with shape = "varying" it follows each individual's own heat injury (see the section "Varying shape").

Optionally adds a temperature-dependent repair rate via repair_rate_schoolfield().

Value

A list with elements:

  • summary: tibble with time, temp, and posterior median + 95% CrI for hi, survival, and mortality at each time step (plus the moderator column(s) for a grouped fit).

  • draws: optional per-draw trajectories (when save_draws = TRUE); a draw that gives no prediction is kept as rows of NA.

  • meta: list of inputs used. meta$ndraws is the number of posterior draws that produced a prediction; a warning reports any that did not, and they are left out of every summary column. For a grouped fit it is the smallest such number in any group, and meta$ndraws_by_group gives each group's count.

Varying shape (experimental)

The fitted curves describe survival at constant temperatures. When their shape (low, up, k) changes with temperature, survival under a fluctuating trace depends on why it changes, which constant-temperature data cannot reveal. varying_method chooses between two coherent methods. Both reproduce the fitted curve at a constant temperature; both use the constant shape's rule that, with irreversible mortality, injury that is repaired and re-accrued kills no one until it passes its previous peak; and both equal the constant shape exactly when low, up and k do not change with temperature and the midpoint is linear in it (with an absolute target and a very shallow curve, k below about 2, the starting values differ slightly: the two shapes read their curves at a tiny dose measured in different units). Otherwise they differ, and comparing them shows how much the unknown mechanism matters.

  • "individual" (default): each individual is followed separately. The individual of survival rank p is the one that dies, at a constant temperature, when survival there falls to p, at that temperature's threshold time for p. It accumulates heat injury additively (the time at each temperature divided by its own threshold time there) and dies when its injury reaches 1. This is exact if individuals have their own TDT lines that fan out and keep their ranks. Without repair, once the trace has begun to accrue injury, survival depends only on the time spent at each temperature, not on their order or on where the trace starts; more time at any temperature never raises it (a hotter trace can still end higher where the fitted curves cross); and the heat injury of an absolute target reaches 100% exactly when survival falls to that target. Repair removes the same fraction of every individual's injury.

  • "cumulative": cumulative exposure, with survival as the state. Over each time step, survival continues along the current temperature's curve from the point where that curve has the current survival. This is exact if individuals share one injury process whose rate depends on the injury already accrued, and differ only in their thresholds. It is the usual rule in reliability for a shape that changes with stress (Nelson 1980) and the one used by Rezende et al. (2020) and Bullard et al. (2026); given the same curves it reproduces Bullard et al.'s code, except that their code reads each step's curve at the step's end rather than its start (the difference shrinks as the steps do). Temperature order matters. Because survival is the state, deaths on exposure to a lower up (below) also advance the survivors along later curves. A step injures only while survival is above the floor of its curve; otherwise the state stays on the curve of the last step that injured it (as ranks below low accrue no injury in the per-individual method), as it does at or below T_c. With repair, a shared injury falls by the repair amount on the dose scale of the curve the state lies on, so the repair during a cool spell depends on the curve of the last step that injured. The heat injury of an absolute target is the per-individual method's and does not mark when survival under this method reaches the target.

Each time step is held at the temperature at its start, as the dose is. Survival starts at up of the first temperature at which the trace accrues injury (above T_c); a trace that accrues none keeps the constant shape's value, up at T_bar. Both methods read a lower up at some temperature as individuals that die as soon as they are exposed to it (a convention without published precedent), so survival drops to that up once the trace spends time there above T_c; those deaths are permanent even with irreversible_mortality = FALSE, as the share 1 - up is in the constant shape. If a temperature-dependent up reflects losses unrelated to heat, fit up as a constant or set T_c; up(T) is extrapolated at trace temperatures outside the assay range. Heat injury is the same under both methods unless repair scales with survival, when each method's own survival scales it. For a continuous response (the Beta family) the curve is a mean response, so the reading in terms of individuals does not apply. With irreversible_mortality = FALSE, survival rebounds as injury is repaired, up to the lowest up met so far. The cost of the varying shape grows with the number of distinct trace temperatures, so rounding the trace (for example to 0.1 °C) speeds it up.

References

Bullard GW, Buckley LB, Kingsolver JG (2026). Incorporating variation in death times improves predictions of ectotherm responses to stressful temperatures. PLOS Biology 24(5): e3003623. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1371/journal.pbio.3003623")}

Nelson W (1980). Accelerated life testing - step-stress models and data analyses. IEEE Transactions on Reliability R-29(2): 103-108. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1109/TR.1980.5220742")}

Rezende EL, Bozinovic F, Szilagyi A, Santos M (2020). Predicting temperature mortality and selection in natural Drosophila populations. Science 369(6508): 1242-1245. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1126/science.aba9287")}

Examples

## Not run: 
scens <- make_temperature_scenarios()
hi    <- predict_heat_injury(scens$single_spike, wf)
hi$summary

## End(Not run)

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