odemodeling-package | R Documentation |
Building and fitting ordinary differential equation (ODE)
models with different numerical solvers in 'Stan'. Designed for efficient
validation of the accuracy of numerical solvers in the Bayesian context.
Using Pareto-smoothed importance sampling (PSIS) and its diagnostics.
The package is based on the R6
object oriented system and uses
cmdstanr
as the interface to 'Stan'.
Declare model data, parameters, and other variables using
stan_array()
, stan_dim()
, stan_matrix()
, stan_param()
,
stan_transform()
, stan_vector_array()
, and stan_vector()
.
Create an OdeModel model using ode_model()
.
See odesolvers
for constructors that create objects
of class OdeSolver.
Sample the posterior or prior distribution of the model parameters,
and generate corresponding ODE solutions using the $sample()
method
of the OdeModel class.
See methods of the OdeModelMCMC class for studying the returned object.
See the $gqs()
method of the OdeModelMCMC and OdeModel
classes.
See methods of the OdeModelGQ class for studying the returned object.
See compare_odefits
for functions to compare
different ODE model simulations and fits.
Our proposed workflow is to
Select an initial ODE solver M.
Sample the parameter posterior using MCMC with M as the ODE solver.
Compute certain metrics using a more accurate solver M∗.
Increase the accuracy of M∗ and repeat Step 3 until the metrics converge. If the Pareto-k metric converges to a value larger than 0.7, increase the accuracy of M and go back to Step 2.
Compute any posterior estimates using final importance weights. See Timonen et al. (2022) below.
The algorithm can be used to validate the reliability, and correct the errors of a given method M, which can be for example a software default. On the other hand, a smart initial selection of M can provide speed gains compared to often rather conservatively set software defaults, while still maintaining reliability of the inferences.
We generally recommend selecting M initially so that sampling is as fast as possible. For example, for non-adaptive ODE solvers, one can first try using the smallest sensible number of steps that does not result in immediate failure. Selecting a good M is more difficult in the case of adaptive solvers. We have observed that tolerances on the order of 1e-4 to 1e-3 generally work well.
See the reliability()
method of the OdeModelMCMC
class.
See the tutorial vignette.
Maintainer: Juho Timonen juho.timonen@iki.fi (ORCID)
Timonen, J., Siccha, N., Bales, B., Lähdesmäki, H., & Vehtari, A. (2023). An importance sampling approach for reliable and efficient inference in Bayesian ordinary differential equation models. Stat, 12(1), e614. https://onlinelibrary.wiley.com/doi/full/10.1002/sta4.614
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.