mcmcSEIR: Run the MCMC algorithm to obtain posterior samples for all...

View source: R/mcmcSEIR.R

mcmcSEIRR Documentation

Run the MCMC algorithm to obtain posterior samples for all model parameters.

Description

Run the MCMC algorithm to obtain posterior samples for all model parameters.

Usage

mcmcSEIR(
  dat,
  X,
  inits,
  niter,
  nburn,
  infPeriodSpec = c("exp", "PS", "IDD"),
  priors,
  iddFun = NULL,
  maxInf = NULL,
  dist = NULL,
  EKnown = FALSE,
  WAIC = FALSE,
  progressBar = FALSE,
  seed = NULL
)

Arguments

dat

A list providing the necessary data on the epidemic. Must contain Istar, S0, E0, I0, and N. If EKnown = TRUE, must also contain Estar.

X

The design matrix corresponding to the intensity process over epidemic time.

inits

A list of initial values for all parameters. Must contain initial values for beta vector with elements for each column of X. Other parameters needed depend on the model being fit - see Details.

niter

The total number of iterations to be run.

nburn

The number of burn-in iterations to be discarded.

infPeriodSpec

A character indicating which model for the infectious period will be used.

priors

A list of functions to compute the prior probability for each parameter. Functions must take only one argument and must compute the probability on the log scale.

iddFun

If infPeriodSpec = "IDD" this will specify the functional form used to describe the IDD transmissibility curve. Default functions are dgammaIDD, dlnormIDD, logitIDD, and splineIDD

maxInf

If infPeriodSpec = "PS" or infPeriodSpec = "IDD", this will specify the maximum length of the infectious period.

dist

If infPeriodSpec = "PS" this will specify the distribution for the path-specific removal probability. Currently only the exponential ("exp"), gamma ("gamma"), and Weibull ("weibull") distributions are supported.

EKnown

logical. If EKnown = TRUE the model will run assuming the exposure times are known. Estar must be provided in dat.

WAIC

logical. If WAIC = TRUE, WAIC will be computed using post burn-in samples.

progressBar

logical. If progressBar = TRUE a progress bar will be displayed.

seed

optional seeding for reproducibility.

Details

mcmcSEIR offers modelers three options to specify the infectious period: the exponential distribution, the path-specific (PS) approach of Porter and Oleson (2013), or the infectious-duration dependent (IDD) formulation of Ward et al. (upcoming).

All models will estimate a beta parameter associated with each column of the matrix X and a rate parameter rateE associated with the exposure probability.

For the exponential model infPeriodSpec = 'exp', only one additional parameter will be estimated: rateI the rate parameter associated with the removal probability. Initial values and a prior for rateI need to be specified.

For the path-specific model infPeriodSpec = 'PS', additional parameters corresponding to the distribution specified in dist will be estimated. Initial values are named as psParams, which itself is a list with initial values for each associated parameter. Function giving priors for these parameters should be named psParamsPrior and contained in priors. For example, if dist = 'gamma', then inits$psParams = list(shape = , rate = ) will provide the initial values for the shape and rate parameters associated with the gamma distribution. priors$psParamsPriors should contain a function which computes the joint prior for these parameters.

For the infectious-duration dependent model infPeriodSpec = 'IDD', additional parameters corresponding to the IDD curve specified in iddFun will also be estimated. Initial values are named as iddParams, which itself is a list with initial values for each associated parameter. Function giving priors for these parameters should be named iddParamsPrior and contained in priors. For example, if iddFun = logitIDD, then inits$iddParams = list(rate = ..., mid = ...) will provide the initial values and priors$iddParamsPriors should contain a function which computes the joint prior for these parameters (see example).

If WAIC = TRUE, the WAIC will be calculated. WAIC is computed based on the log-likelihood values at each post burn-in iteration using the pWAIC2 formulation described in Gelman et al. (2013), which multiplies the WAIC of Watanabe (2010) by 2 to be on the deviance scale.

Value

A data frame of posterior samples or a two-element list with posterior samples and WAIC.

References

Porter, Aaron T., and Oleson, Jacob J. "A path-specific SEIR model for use with general latent and infectious time distributions." Biometrics 69.1 (2013): 101-108.

Gelman, Andrew, Hwang, Jessica and Vehtari, Aki. "Understanding predictive information criteria for Bayesian models." Statistics and computing 24.6 (2014): 997-1016.

Watanabe, Sumio, and Opper, Manfred. "Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory." Journal of machine learning research 11.12 (2010).

Examples

## Not run: 

dat <- simSEIR(S0=999, E0=0, I0=1, N=1000, tau=100,
               beta=0.7, X=cbind(rep(1, 100)), rateE=0.1,
               infPeriodSpec = 'IDD', 
               infIDDParams = list(maxInf = 15,
                                   iddFun = logitIDD,
                                   iddParams = list(mid = 8, rate = 1.5)))


initsList <- list(beta = 1, rateE = 0.2, 
                  iddParams = list(mid = 4, rate = 0.1))
                  
priorsList <- list(betaPrior = function(x) dnorm(x, 0, 4, log = T),
                   rateEPrior = function(x) dgamma(x, 10, 100, log = T),
                   iddParamsPrior = function(x) {
                       dnorm(x["mid"], 5, 1, log = T) +
                       dgamma(x["rate"], 1, 1, log = T)
                   })

postRes <- mcmcSEIR(dat = dat, X=cbind(rep(1, 100)), 
                    inits = initsList, 
                    niter=10000, nburn=5000,
                    infPeriodSpec = 'IDD',
                    priors=priorsList,
                    iddFun = logitIDD, maxInf = 10,
                    progressBar = T)


## End(Not run)

ceward18/BayesSEIR documentation built on June 15, 2022, 11:06 a.m.