This is similar to the workflow for fitting Bayesian regression models with rstanarm.
A key difference, however, is that the models fit by epidemia are much more complex,
and are therefore inherently more difficult to specify. epidemia aims to simplify this
process by modularizing the model definition into three distinct parts: transmission, infections and observations.
These components of the model are defined with the functions epirt
, epiinf
and epiobs
respectively.
epim
has arguments
rt
, inf
and obs
which expect a description of the
transmission model, infection model and observational models respectively.
Together, these fully define the joint distribution of data and parameters.
Each of these model components are described in terms of variables that are expected to live in a single dataframe, data
.
This dataframe must be compatible with the model components, in the sense that it holds all variables defined in these models.
In addition to taking a model description and a dataframe, epim
has various
additional arguments which specify how the model should be fit. If algorithm = "sampling"
then the model will be fit using Stan<U+2019>s adaptive Hamiltonian Monte Carlo sampler.
This is done internally by calling sampling
. If
algorithm = "meanfield"
or algorithm = "fullrank"
, then
Stan<U+2019>s variational Bayes algorithms are used instead, by calling vb
.
Any unnamed arguments in the call to epim
are passed directly on to the rstan sampling function.
epim
returns a fitted model object of class epimodel
, which contains posterior samples from the model along with other useful objects.
In general, the adaptive Hamiltonian Monte Carlo sampler should be used for final inference.
Nonetheless, fitting these models using HMC is often computationally demanding, and variational Bayes can often be fruitful for quickly iterating models.