BayesianDEB provides a complete Bayesian framework for Dynamic Energy Budget (DEB) modelling. It wraps pre-written Stan models with a clean R interface for data preparation, model specification, fitting, diagnostics, and visualisation.
The package implements four model types:
| Type | Stan model | Description |
|---|---|---|
individual |
2-state (E, V) | Single individual growth |
growth_repro |
3-state (E, V, R) | Growth + reproduction |
hierarchical |
2-state + random effects | Multi-individual with partial pooling |
debtox |
4-state (E, V, R, D) | Toxicokinetic-toxicodynamic |
# Install cmdstanr (required backend)
install.packages("cmdstanr",
repos = c("https://stan-dev.r-universe.dev", getOption("repos")))
cmdstanr::install_cmdstan()
# Install BayesianDEB
# remotes::install_github("sciom/BayesianDEB")The chunks below are executed only when cmdstanr and a
working CmdStan installation are available — otherwise they are skipped.
To keep build time within JSS limits we use 2 chains and 300 + 300
iterations, which is sufficient for illustration but
not for publication-grade inference. Re-run with
chains = 4, iter_warmup = iter_sampling = 1000
for production fits.
mod <- bdeb_model(
data = dat,
type = "individual",
priors = list(
p_Am = prior_lognormal(mu = 1.5, sigma = 0.5),
p_M = prior_lognormal(mu = -1.0, sigma = 0.5),
kappa = prior_beta(a = 3, b = 2),
sigma_L = prior_halfnormal(sigma = 0.05)
)
)
modUnspecified priors are filled from
prior_default("individual").
For illustration we use a 5-individual subset; the full multi-individual analysis with all 21 individuals is in the replication archive.
dat_all <- bdeb_data(
growth = eisenia_growth[eisenia_growth$id %in% 1:5, ],
f_food = 1.0
)
mod_hier <- bdeb_model(dat_all, type = "hierarchical")
fit_hier <- bdeb_fit(mod_hier,
chains = 2, iter_warmup = 300, iter_sampling = 300,
seed = 123, refresh = 100)
bdeb_diagnose(fit_hier)
summary(fit_hier, pars = c("mu_log_p_Am", "sigma_log_p_Am", "p_M", "kappa"))data(debtox_growth)
# Concentration mapping
conc_map <- setNames(
c(0, 20, 80, 200),
c("1", "2", "3", "4")
)
dat_tox <- bdeb_data(
growth = debtox_growth,
concentration = conc_map,
f_food = 1.0
)
mod_tox <- bdeb_tox(dat_tox, stress = "assimilation")For this demo only, we use variational inference (ADVI) which gives an approximation of the posterior in seconds rather than minutes. The replication archive uses full HMC (NUTS) which is the publication-grade method.
BayesianDEB follows the prior recommendations of Kooijman (2010) and the AmP collection (Marques et al., 2018):
The default likelihood is Gaussian for growth and negative binomial
for reproduction. Switch via observation: