Create an instance of the hierarchical SEIR Stan model incorporating various data elements and sample model.

seir_model_fit(
  stan_model = NULL,
  tmax,
  n_outbreaks,
  outbreak_cases,
  outbreak_sizes,
  intervention_switch = TRUE,
  multilevel_intervention = FALSE,
  priors = prior_list,
  chains = 4,
  iter = 600,
  seed = 42,
  fit_type = "NUTS",
  data_model = "poisson"
)

Arguments

stan_model

[rstan] model object

tmax

Total number of time-points in observation

n_outbreaks

Total number of outbreaks

outbreak_cases

Number of daily reported cases by outbreak

outbreak_sizes

The total size of each facility (initial number of susceptible and exposed)

intervention_switch

Describes whether interventions occur in data (default TRUE)

multilevel_intervention

Describes whether intervention occurs

chains

Number of chains to sample

iter

number of iterations of MCMC

seed

The seed for random number generation. Set to replicate results.

fit_type

string "NUTS" or "VB" (VB quicker but less accurate).

data_model

string "poisson" or "negative_binomial". If negative_binomial selected then uses phi prior to control for overdispersion

prior_list

List of priors. See [prior_list]

Value

An object of class `stanfit` returned by sampling

Author

Mike Irvine

Examples

stan_mod <- rstan::stan_model(system.file("stan", "hierarchical_SEIR_incidence_model.stan", package = "cr0eso")) tmax <- 5 pop_size <- 100 dim(pop_size) <- c(1) example_incidence <- matrix(c(1,1,2,3,2),ncol=1) fit <- seir_model_fit(stan_model = stan_mod, tmax,1,example_incidence,pop_size)
#> #> SAMPLING FOR MODEL 'hierarchical_SEIR_incidence_model' NOW (CHAIN 1). #> Chain 1: #> Chain 1: Gradient evaluation took 0 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: #> Chain 1: Iteration: 1 / 600 [ 0%] (Warmup) #> Chain 1: Iteration: 60 / 600 [ 10%] (Warmup) #> Chain 1: Iteration: 120 / 600 [ 20%] (Warmup) #> Chain 1: Iteration: 180 / 600 [ 30%] (Warmup) #> Chain 1: Iteration: 240 / 600 [ 40%] (Warmup) #> Chain 1: Iteration: 300 / 600 [ 50%] (Warmup) #> Chain 1: Iteration: 301 / 600 [ 50%] (Sampling) #> Chain 1: Iteration: 360 / 600 [ 60%] (Sampling) #> Chain 1: Iteration: 420 / 600 [ 70%] (Sampling) #> Chain 1: Iteration: 480 / 600 [ 80%] (Sampling) #> Chain 1: Iteration: 540 / 600 [ 90%] (Sampling) #> Chain 1: Iteration: 600 / 600 [100%] (Sampling) #> Chain 1: #> Chain 1: Elapsed Time: 1.674 seconds (Warm-up) #> Chain 1: 1.025 seconds (Sampling) #> Chain 1: 2.699 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'hierarchical_SEIR_incidence_model' NOW (CHAIN 2). #> Chain 2: #> Chain 2: Gradient evaluation took 0 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: #> Chain 2: Iteration: 1 / 600 [ 0%] (Warmup) #> Chain 2: Iteration: 60 / 600 [ 10%] (Warmup) #> Chain 2: Iteration: 120 / 600 [ 20%] (Warmup) #> Chain 2: Iteration: 180 / 600 [ 30%] (Warmup) #> Chain 2: Iteration: 240 / 600 [ 40%] (Warmup) #> Chain 2: Iteration: 300 / 600 [ 50%] (Warmup) #> Chain 2: Iteration: 301 / 600 [ 50%] (Sampling) #> Chain 2: Iteration: 360 / 600 [ 60%] (Sampling) #> Chain 2: Iteration: 420 / 600 [ 70%] (Sampling) #> Chain 2: Iteration: 480 / 600 [ 80%] (Sampling) #> Chain 2: Iteration: 540 / 600 [ 90%] (Sampling) #> Chain 2: Iteration: 600 / 600 [100%] (Sampling) #> Chain 2: #> Chain 2: Elapsed Time: 1.567 seconds (Warm-up) #> Chain 2: 1.09 seconds (Sampling) #> Chain 2: 2.657 seconds (Total) #> Chain 2: #> #> SAMPLING FOR MODEL 'hierarchical_SEIR_incidence_model' NOW (CHAIN 3). #> Chain 3: #> Chain 3: Gradient evaluation took 0 seconds #> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds. #> Chain 3: Adjust your expectations accordingly! #> Chain 3: #> Chain 3: #> Chain 3: Iteration: 1 / 600 [ 0%] (Warmup) #> Chain 3: Iteration: 60 / 600 [ 10%] (Warmup) #> Chain 3: Iteration: 120 / 600 [ 20%] (Warmup) #> Chain 3: Iteration: 180 / 600 [ 30%] (Warmup) #> Chain 3: Iteration: 240 / 600 [ 40%] (Warmup) #> Chain 3: Iteration: 300 / 600 [ 50%] (Warmup) #> Chain 3: Iteration: 301 / 600 [ 50%] (Sampling) #> Chain 3: Iteration: 360 / 600 [ 60%] (Sampling) #> Chain 3: Iteration: 420 / 600 [ 70%] (Sampling) #> Chain 3: Iteration: 480 / 600 [ 80%] (Sampling) #> Chain 3: Iteration: 540 / 600 [ 90%] (Sampling) #> Chain 3: Iteration: 600 / 600 [100%] (Sampling) #> Chain 3: #> Chain 3: Elapsed Time: 11.104 seconds (Warm-up) #> Chain 3: 0.705 seconds (Sampling) #> Chain 3: 11.809 seconds (Total) #> Chain 3: #> #> SAMPLING FOR MODEL 'hierarchical_SEIR_incidence_model' NOW (CHAIN 4). #> Chain 4: #> Chain 4: Gradient evaluation took 0 seconds #> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds. #> Chain 4: Adjust your expectations accordingly! #> Chain 4: #> Chain 4: #> Chain 4: Iteration: 1 / 600 [ 0%] (Warmup) #> Chain 4: Iteration: 60 / 600 [ 10%] (Warmup) #> Chain 4: Iteration: 120 / 600 [ 20%] (Warmup) #> Chain 4: Iteration: 180 / 600 [ 30%] (Warmup) #> Chain 4: Iteration: 240 / 600 [ 40%] (Warmup) #> Chain 4: Iteration: 300 / 600 [ 50%] (Warmup) #> Chain 4: Iteration: 301 / 600 [ 50%] (Sampling) #> Chain 4: Iteration: 360 / 600 [ 60%] (Sampling) #> Chain 4: Iteration: 420 / 600 [ 70%] (Sampling) #> Chain 4: Iteration: 480 / 600 [ 80%] (Sampling) #> Chain 4: Iteration: 540 / 600 [ 90%] (Sampling) #> Chain 4: Iteration: 600 / 600 [100%] (Sampling) #> Chain 4: #> Chain 4: Elapsed Time: 12.309 seconds (Warm-up) #> Chain 4: 0.706 seconds (Sampling) #> Chain 4: 13.015 seconds (Total) #> Chain 4:
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> http://mc-stan.org/misc/warnings.html#tail-ess