The goal of hmde
is to implement hierarchical Bayesian longitudinal models to solve the Bayesian inverse problem of estimating differential equation parameters based on repeat measurement surveys. Estimation is done using Markov Chain Monte Carlo, implemented through Stan via RStan, built under R 4.3.3. The inbuilt models are based on case studies in ecology. The hierarchical Bayesian longitudinal method was first introduced in OβBrien et al., 2024.
As hmde
is first intended for biologists, the initial set of vignettes (hmde
, constant-growth
, von-bertalanffy
, and canham
) are written aimed at an audience more interested in applications than the underlying theory. A vignette for the more mathematically interested is under development.
The Maths
The general use case is to estimate a vector of parameters for a chosen differential equation based on the longitudinal structure
The input data are observations of the form for individual at time , with repeated observations coming from the same individual. We parameterise at the individual level by estimating as the vector of parameters. We have hyper-parameters that determine the distribution of with typical prior distribution where and are vectors of means and standard deviations. In the case of a single individual, these are chosen prior values. In the case of a multi-individual model and have their own prior distributions and are fit to data.
Implemented Models
hmde
comes with four DEs built and ready to go, each of which has a version for a single individual and multiple individuals.
Constant Model
The constant model is given by and is best understood as describing the average rate of change over time.
von Bertalanffy
The von Bertalanffy mode is given by where is the growth rate parameter and is the maximum value that takes.
Canham
The Canham (Canham et al.Β 2004) model is a hump-shaped function given by where is the maximum growth rate, is the -value at which that maximum occurs, and controls how narrow or wide the peak is.
Installation
βhmdeβ is under active development. You can install the current developmental version of βhmdeβ from GitHub with:
# install.packages("remotes")
remotes::install_github("traitecoevo/hmde")
Quick demo
Create constant growth data with measurement error:
Measurement error is necessary as otherwise the normal likelihood blows up as approaches 0.
Fit the model:
constant_fit <- hmde_model("constant_single_ind") |>
hmde_assign_data(n_obs = 10, #Integer
y_obs = y_obs, #vector length n_obs
obs_index = 1:10, #vector length n_obs
time = 0:9, #Vector length n_obs
y_0_obs = y_obs[1] #Real
) |>
hmde_run(chains = 1, iter = 1000, verbose = FALSE, show_messages = FALSE)
Found a bug?
Please submit a GitHub issue with details of the bug. A reprex would be particularly helpful with the bug-proofing process!