bayesTLS is an R package for fitting joint Bayesian four-parameter logistic
(4PL) models to thermal death time (TDT) and thermal load sensitivity (TLS) data.
It works with raw counts or continuous proportions, extracts classical quantities
such as z, CTmax, Tcrit, and LT curves as posterior summaries, and provides
tools for uncertainty propagation, group contrasts, heat-injury prediction, and
bundled case-study data.
Please cite the companion paper when using bayesTLS:
Noble, D.W.A., Arnold, P.A. & Pottier, P. (in preparation). A flexible modelling framework for estimating thermal tolerance and sensitivity.
This paper is the primary citation for both the statistical framework and the
bayesTLS package. Citation details will be updated here when the paper is
published. You can also run citation("bayesTLS") in R for the formatted
reference and a BibTeX entry.
The analytical workflow ships as an installable R package at the root of this repository. Install from GitHub:
install.packages("remotes") # if needed
remotes::install_github("daniel1noble/bayesTLS")
library(bayesTLS)The package depends on brms (which needs a
Stan backend; cmdstanr is recommended). All
other imported dependencies (dplyr, ggplot2, MASS, patchwork,
posterior, tibble) are CRAN packages and resolve automatically. The classical
two-stage beta-binomial Stage 1 additionally uses the suggested
glmmTMB package.
The coding workflow is decoupled — each step is a standalone function so users can stop, swap, or skip at any stage:
| Function | Role |
|---|---|
standardize_data() |
Rename user columns to standard names; supports count responses (survived/dead/total) and continuous proportions; records response type + metadata. |
make_4pl_priors() / make_4pl_formula() |
Disjoint-bounds reparameterised 4PL; asymptote bounds adjustable for sublethal/PSII ranges. |
fit_4pl() |
Joint Bayesian 4PL via brms. Family resolved from the response — beta_binomial(identity) for counts, Beta(identity) for proportions. Centred temperature; temp_effects selects which 4PL parameters depend on temperature (all four by default; "mid" for sparse designs). |
extract_tdt() |
z, CTmax at the reference duration, and (lethal data only, lethal = TRUE) T |
tls() / tls_z() / tls_ctmax() / tls_tcrit() |
One call to derive z, CTmax, and (lethal) Tbayes_tls workflow or a hand-written brms 4PL — with all quantities drawn from one consistent posterior. |
derive_z(), derive_tdt_curve(), derive_temperature_for_duration(), derive_tdt_landscape() |
Exported primitives behind extract_tdt(). |
extract_4pl_pars(), tdt_parameter_table(), tdt_quantile(), summarise_observed_survival() |
Per-draw 4PL parameters, natural-scale posterior parameter tables, TDT-friendly quantile summaries, and observed-survival cell summaries (mean ± SE per temp × duration). |
predict_survival_curves(), predict_heat_injury(), repair_rate_schoolfield() |
Posterior survival curves; heat-injury accumulation under a temperature trace, with an optional Sharpe–Schoolfield repair kernel supplied by repair_rate_schoolfield(). |
make_temperature_scenarios(), planted_dose_from_trace() |
Reference temperature traces and the analytical HI integral for validation. |
ts_stage1(), ts_stage2(), ts_ci(), ts_curve() |
The classical two-stage TDT pipeline for side-by-side comparison: per-temperature dose-response (stats::glm binomial or glmmTMB beta-binomial) → OLS of log10(LT50) on temperature → z, CTmax, T |
diagnose_tdt_fit() |
Sampling diagnostics (R-hat, ESS, divergences) for a fitted workflow. |
plot_*() + theme_tdt() |
Plotting helpers (survival curves, TDT curve, tolerance landscape, heat injury, temperature scenarios/density, repair TPC) with a shared project theme. |
get_brmsfit(), get_z_draws() / get_z_summary(), get_ctmax_draws() / get_ctmax_summary(), get_tcrit_draws() / get_tcrit_summary(), get_surv_draws(), get_hi_draws(), has_fit(), … |
Accessors for the underlying fit, posterior draws, and posterior summaries. |
clock_to_minutes(), format_interval() |
Utilities: parse clock-time strings to elapsed minutes; format a posterior median with its interval as median [lower, upper]. |
Full reference: ?fit_4pl, ?extract_tdt, ?predict_heat_injury, etc.
Five datasets are included with the bayesTLS package to make it easier to reproduce analyses and results in the paper and for testing purposes. These datasets are:
| Dataset | Help | Endpoint |
|---|---|---|
shrimp_lethal |
?shrimp_lethal |
Brown-shrimp lethal TDT (survival counts) |
shrimp_sublethal |
?shrimp_sublethal |
Brown-shrimp sublethal time-to-knockdown |
zebrafish_lethal |
?zebrafish_lethal |
Zebrafish lethal TDT across life stages |
snowgum_psii |
?snowgum_psii |
Snowgum leaf PSII (continuous proportion) |
dsuzukii |
?dsuzukii |
Drosophila suzukii multi-trait TDT (lethal, knockdown, fertility; per individual) |
Each dataset can be loaded easily using data(shrimp_lethal) (as an example of loading the shrimp_lethal dataset). If you want other datasets loaded then simply replace shrimp_lethal. If you want to learn more about a dataset you can explore it's helpful ?shrimp_lethal.
This repository also contains the code needed to reproduce the companion paper,
its supplement, and the simulation results. To do this, install the package from
this repository, render the Quarto documents through the Makefile, and use the
tests to verify the package functions used by the manuscript and supplement. All
code chunks are provided in ms/ms.qmd and ms/supplement.qmd; use make supp
to render the supplement and scripts/simulations/run_simulations.R to rerun the
full two-stage-bias simulation suite. Run all scenarios with
Rscript scripts/simulations/run_simulations.R, or a subset by passing scenario
labels, e.g. Rscript scripts/simulations/run_simulations.R scen9_tmax_060. Each
scenario and the per-simulation pipeline are visible in that one script; the
reusable building blocks live in scripts/simulations/sim_functions.R.
Use this map to find the files and outputs involved in reproduction:
Makefile— main entry point for rendering the manuscript and supplement.ms/ms.qmd— manuscript source file; renders to_output/ms.html,_output/ms.docx, and_output/ms.pdf.ms/supplement.qmd— supplement source file; renders to_output/supp.html,_output/supp.docx, and_output/supp.pdf.R/— package source for the analysis functions used by the paper; see Key functions.data/— bundled package datasets as.rdafiles.inst/extdata/— source CSV files used to build the bundled datasets.data-raw/make_datasets.R— script that rebuilds the.rdadatasets from the source CSV files.output/models/— cachedbrmsfits (.rds) created and reused during renders.scripts/simulations/— the two-stage-bias simulation:run_simulations.R(scenarios + runner) andsim_functions.R(reusable building blocks).scripts/— other support scripts (presentation figures, document cleanup).tests/testthat/— fast unit tests plus optionalbrmsintegration tests.bib/— bibliography and the Ecology Letters CSL file.notes/— dated development notes for derivations, literature checks, and simulations.man/— roxygen-generated package help files._output/— final rendered manuscript and supplement files; created by the render commands below.
-
Install the package from this repository so the renders use the same code you are reproducing:
# install.packages("devtools") # if needed devtools::install()
-
Render the manuscript, supplement, or both from the repository root:
make all # manuscript and supplement, all formats make ms # manuscript only: _output/ms.{html,docx,pdf} make supp # supplement only: _output/supp.{html,docx,pdf}
You can also render one format at a time, for example
make ms-pdformake supp-html.The first supplement render may take several minutes because it fits or checks cached models. Subsequent renders reuse the
.rdsfiles inoutput/models/and should be much faster. -
Inspect the rendered files in
_output/. Usemake cleanto remove only_output/, ormake build-cleanto also remove the out-of-tree Quarto build cache at~/Library/Caches/tls-render/. -
Run the package tests if you want to verify the analysis functions separately from the manuscript render:
devtools::test() Sys.setenv(RUN_BRMS_TESTS = "true") devtools::test()
The first command runs the fast unit tests. The second also runs the gated
brmsintegration tests, which fit small cached models and check parameter recovery.
The manuscript and supplement are independent Quarto documents. There is no
project-level _quarto.yml; each .qmd file carries its own YAML so the files
can be rendered separately. The Makefile renders outside the Dropbox-synced
project directory, then copies only the final HTML, DOCX, and PDF files back to
_output/. This avoids conflicted intermediate files while preserving cached
model fits in output/models/.
Within a document, use Quarto's @ references as normal (@fig-X, @tbl-X,
@eq-X, @sec-X). Between the manuscript and supplement, use plain text, such
as "Equation 7 of the manuscript" in the supplement or "Figure S2" in the
manuscript. The supplement render automatically labels figures, tables, and
equations with an "S" prefix.
See CLAUDE.md §8a for more detail on the render architecture,
cross-reference handling, and the brms cache.
The supplement works through the same workflow on simulated data and four empirical examples:
- Brown shrimp — lethal and sublethal endpoints.
- Zebrafish — lethal TDT across life stages, fit as separate per-stage 4PLs
and as a joint model with
life_stageas a covariate. - Snow gum leaf PSII — continuous-proportion response fit with a Beta likelihood.
- Drosophila suzukii — multi-trait TDT data, including mortality, knockdown, and fertility endpoints.
The supplement also contains the two-stage-bias simulation results and sensitivity sweeps used to check the modelling framework.