| Title: | Hierarchical Methods for Differential Equations |
|---|---|
| Description: | Wrapper for 'Stan' that offers a number of in-built models to implement a hierarchical Bayesian longitudinal model for repeat observation data. Model choice selects the differential equation that is fit to the observations. Single and multi-individual models are available. O'Brien et al. (2024) <doi:10.1111/2041-210X.14463>. |
| Authors: | Daniel Falster [aut, ctb] (ORCID: <https://orcid.org/0000-0002-9814-092X>), Tess O'Brien [aut, cre, cph] (ORCID: <https://orcid.org/0009-0000-5821-8801>), Fonti Kar [ctb] (ORCID: <https://orcid.org/0000-0002-2760-3974>), David Warton [aut, ctb] (ORCID: <https://orcid.org/0000-0002-1642-628X>) |
| Maintainer: | Tess O'Brien <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.4.0 |
| Built: | 2026-05-07 02:32:12 UTC |
| Source: | https://github.com/traitecoevo/hmde |
A package to implement a selection of hierarchical Bayesian longitudinal models for inverse Bayesian problems.
Maintainer: Tess O'Brien [email protected] (ORCID) [copyright holder]
Authors:
Daniel Falster [email protected] (ORCID) [contributor]
David Warton [email protected] (ORCID) [contributor]
Other contributors:
Fonti Kar [email protected] (ORCID) [contributor]
Stan Development Team (NA). RStan: the R interface to Stan. R package version 2.26.23. https://mc-stan.org
Useful links:
generic error_ests getter
generic error_ests setter
error_ests(x) error_ests(x) <- valueerror_ests(x) error_ests(x) <- value
x |
hmde_estimates class object |
value |
tibble of error parameter estimates |
generic fit_summary getter
generic fit_summary setter
fit_summary(x) fit_summary(x) <- valuefit_summary(x) fit_summary(x) <- value
x |
hmde_estimates class object |
value |
character string description of fit |
Differential equation for affine growth single individual model
hmde_affine_de(y = NULL, pars = NULL)hmde_affine_de(y = NULL, pars = NULL)
y |
input real |
pars |
list of parameters beta_0, beta_1 |
value of differential equation at y
Differential equation for Canham growth single and multi- individual models
hmde_canham_de(y = NULL, pars = NULL)hmde_canham_de(y = NULL, pars = NULL)
y |
input real |
pars |
list of parameters g_max, S_max, k |
value of differential equation at y
Differential equation for constant growth single and multi- individual models
hmde_const_de(y = NULL, pars = NULL)hmde_const_de(y = NULL, pars = NULL)
y |
input real |
pars |
list of parameter beta |
value of differential equation at y
Calculate Rhat statistics for a hmde_fit object
hmde_extract_Rhat(fit)hmde_extract_Rhat(fit)
fit |
hmde_fit fitted model object, output of hmde_run |
named vector of Rhat values
# basic usage of hmde_extract_Rhat hmde_data_template("constant_single_ind", obs_data = Trout_Size_Data[1:4,])|> hmde_run(chains = 2, iter = 1000, verbose = FALSE, show_messages = FALSE) |> hmde_extract_Rhat()# basic usage of hmde_extract_Rhat hmde_data_template("constant_single_ind", obs_data = Trout_Size_Data[1:4,])|> hmde_run(chains = 2, iter = 1000, verbose = FALSE, show_messages = FALSE) |> hmde_extract_Rhat()
helper function for hmde_data_template that provides data structure for model, Also used to guide the user on the required structure for the model they want.
hmde_model(model = NULL)hmde_model(model = NULL)
model |
model name character string |
hmde_data_template class that suits Stan model input
# basic usage of hmde_model hmde_model("constant_single_ind")# basic usage of hmde_model hmde_model("constant_single_ind")
Function to select DE given model name
hmde_model_des(model = NULL)hmde_model_des(model = NULL)
model |
character string model name |
DE function corresponding to specific model
# basic usage of hmde_model_des hmde_model_des("constant_single_ind")# basic usage of hmde_model_des hmde_model_des("constant_single_ind")
Returns names of available models.
hmde_model_names()hmde_model_names()
vector of character strings for model names.
# basic usage of hmde_model_names hmde_model_names()# basic usage of hmde_model_names hmde_model_names()
Show parameter list for hmde supported model
hmde_model_pars(model = NULL)hmde_model_pars(model = NULL)
model |
model name character string |
named list that matches Stan model parameters
# basic usage of hmde_model_pars hmde_model_pars("constant_single_ind")# basic usage of hmde_model_pars hmde_model_pars("constant_single_ind")
Plot pieces of chosen differential equation model for each individual. Structured to take the individual data tibble that is built by the hmde_estimates function using the ind_par_name_mean estimates. Function piece will go from the first fitted size to the last. Accepted ggplot arguments will change the axis labels, title, line colour, alpha
hmde_plot_de_pieces( estimates = NULL, xlab = "Y(t)", ylab = "f", title = NULL, colour = "#006600", alpha = 0.4 )hmde_plot_de_pieces( estimates = NULL, xlab = "Y(t)", ylab = "f", title = NULL, colour = "#006600", alpha = 0.4 )
estimates |
hmde_estimates object |
xlab |
character string for replacement x axis label |
ylab |
character string for replacement y axis label |
title |
character string for replacement plot title |
colour |
character string for replacement line colour |
alpha |
real number for replacement alpha value |
ggplot object
# basic usage of hmde_plot_de_pieces hmde_plot_de_pieces(estimates = Tree_Size_Ests)# basic usage of hmde_plot_de_pieces hmde_plot_de_pieces(estimates = Tree_Size_Ests)
Plot estimated and observed values over time for a chosen number of individuals based on posterior estimates. Structured to take in the measurement_data tibble constructed by the hmde_extract_estimates function.
hmde_plot_obs_est_inds( estimates = NULL, ind_id_vec = NULL, n_ind_to_plot = NULL, xlab = "Time", ylab = "Y(t)", title = NULL )hmde_plot_obs_est_inds( estimates = NULL, ind_id_vec = NULL, n_ind_to_plot = NULL, xlab = "Time", ylab = "Y(t)", title = NULL )
estimates |
hmde_estimates class object |
ind_id_vec |
vector with list of ind_id values |
n_ind_to_plot |
integer giving number of individuals to plot if not specified |
xlab |
character string for replacement x axis label |
ylab |
character string for replacement y axis label |
title |
character string for replacement plot title |
ggplot object
# basic usage of hmde_plot_obs_est_inds hmde_plot_obs_est_inds(estimates = Tree_Size_Ests, n_ind_to_plot = 5)# basic usage of hmde_plot_obs_est_inds hmde_plot_obs_est_inds(estimates = Tree_Size_Ests, n_ind_to_plot = 5)
Plot histogram of R_hat values for hmde_fit object.
hmde_plot_Rhat_hist(fit)hmde_plot_Rhat_hist(fit)
fit |
hmde_fit object output from hmde_run |
ggplot object
# basic usage of hmde_plot_Rhat_hist hmde_data_template("constant_single_ind", Trout_Size_Data[1:4,]) |> hmde_run(chains = 2, iter = 1000, verbose = FALSE, show_messages = FALSE) |> hmde_plot_Rhat_hist()# basic usage of hmde_plot_Rhat_hist hmde_data_template("constant_single_ind", Trout_Size_Data[1:4,]) |> hmde_run(chains = 2, iter = 1000, verbose = FALSE, show_messages = FALSE) |> hmde_plot_Rhat_hist()
Run chosen pre-built model in Stan
hmde_run(data_template, ...)hmde_run(data_template, ...)
data_template |
hmde_data_template class object |
... |
additional arguments passed to rstan::sampling |
Stanfit S4 object
# basic usage of hmde_run hmde_data_template("constant_single_ind", obs_data = Trout_Size_Data[1:4,]) |> hmde_run(chains = 1, iter = 1000, verbose = FALSE, show_messages = FALSE)# basic usage of hmde_run hmde_data_template("constant_single_ind", obs_data = Trout_Size_Data[1:4,]) |> hmde_run(chains = 1, iter = 1000, verbose = FALSE, show_messages = FALSE)
Differential equation for von Bertalanffy growth single and multi- individual models
hmde_vb_de(y = NULL, pars = NULL)hmde_vb_de(y = NULL, pars = NULL)
y |
input real |
pars |
list of parameters Y_max, growth_rate |
value of differential equation at y
generic individual_ests getter
generic individual-ests setter
individual_ests(x) individual_ests(x) <- valueindividual_ests(x) individual_ests(x) <- value
x |
hmde_estimates class object |
value |
tibble of individaul-level parameter estimates |
A subset of data from Kar, Nakagawa, and Noble (2024), used to model growth behaviour in a skink species. Observations are of the length from the tip of the nose to the start of the cloaca. Data was prepared by taking a simple random sample with replacement of 50 individual IDs among individuals with at least 5 observations each. Data was then transformed to conform to the needs of a model data set in the package.
Lizard_Size_DataLizard_Size_Data
Lizard_Size_DataA data frame with 336 rows and 4 columns:
ID number for individual
Days since first observation.
Individual size in mm.
Index of observations for individual
generic measurement_ests getter
generic measurement_ests setter
measurement_ests(x) measurement_ests(x) <- valuemeasurement_ests(x) measurement_ests(x) <- value
x |
hmde_estimates class object |
value |
tibble of measurement-level estimates |
generic method getter
generic method setter
method(x) method(x) <- valuemethod(x) method(x) <- value
x |
hmde_estimates class object |
value |
character string name of object |
generic model_level setter
generic model_level setter
generic obs_data setter
generic obs_data setter
model_level(x) model_level(x) <- value obs_data(x) obs_data(x) <- valuemodel_level(x) model_level(x) <- value obs_data(x) obs_data(x) <- value
x |
hmde hmde_data_template |
value |
character string |
generic model_name getter
generic model_name setter
model_name(x) model_name(x) <- valuemodel_name(x) model_name(x) <- value
x |
hmde special class object |
value |
character string |
generic par_names getter
generic par_names setter
par_names(x) par_names(x) <- valuepar_names(x) par_names(x) <- value
x |
hmde special class object |
value |
vector of parameter names |
generic population_ests setter
generic population_ests setter
population_ests(x) population_ests(x) <- valuepopulation_ests(x) population_ests(x) <- value
x |
hmde_estimates class object |
value |
tibble of population-level estimates |
generic prior_pars getter
generic prior_pars setter
prior_pars(x) prior_pars(x) <- valueprior_pars(x) prior_pars(x) <- value
x |
hmde special class object |
value |
list of prior parameters |
generic runtime getter
generic runtime setter
runtime(x) runtime(x) <- valueruntime(x) runtime(x) <- value
x |
hmde_estimates class object |
value |
matrix of chains for runtimes |
A subset of data from the Barro Colorado Island long term forest plot managed by the Smithsonian Tropical Research Institute (Condit et al. 2019). Data was prepared by taking a simple random sample without replacement of 30 individual IDs from Garcinia recondita. The sampling frame was restricted to individuals with 6 observations since 1990, and a difference between observed first and last sizes of more than 3cm in order to avoid identifiability issues. Data was then transformed and renamed to match the required structure to act as demonstration for the package.
Tree_Size_DataTree_Size_Data
Tree_Size_DataA data frame with 300 rows and 4 columns:
ID number for individual
Years since first observation.
Individual diameter at breast height (DBH) in centimetres.
Index of observations for individual
Estimates object of class hmde_estimates for Canham fit. Contains estimated sizes, individual growth parameters, and population-level hyper-parameters for Garcinia recondita fit with a Canham growth function hierarchical model. The data used to fit the model is the Tree_Size_Data object.
Tree_Size_EstsTree_Size_Ests
Tree_Size_EstsA hmde_estimates object:
A character string giving the model name - Canham with multiple individuals.
A character string stating that the model is fit to multiple individuals.
A character string stating that the model was fit with MCMC sampling.
A matrix giving the runtime of each chain.
A character string summarising the model fitting.
A tibble with 5 columns that gives information on size observations and estimates.
A tibble with 13 columns that gives posterior estimates for individual growth parameters.
A tibble with 5 columns that gives posterior estimates for population-level hyper-parameters.
A tibble with 5 columns that gives posterior estimates of the error parameter.
A list contianing details of the prior parameters used for the model fit.
A list containing the names of estimated parameters at each level of the hierarchical model.
A subset of data from the SUSTAIN trout capture-recapture data set from Moe et al. (2020). Observations are of total body length in centimetres. Data prepared by taking a stratified sample of individual IDs based on the number of observations per individual: 25 individuals with 2 observations, 15 with 3, 10 with 4. Within the groups a simple random sample without replacement was used. Data was then transformed and renamed to match the required structure to act as demonstration for the package.
Trout_Size_DataTrout_Size_Data
Trout_Size_DataA data frame with 135 rows and 4 columns:
ID number for individual
Years since first capture and tagging of individual.
Individual length in centimetres.
Index of observations for individual