Skip to contents

Runs specified stan model for the force-of-infection

Usage

fit_seromodel(
  serosurvey,
  model_type = "constant",
  is_log_foi = FALSE,
  foi_prior = sf_normal(),
  foi_sigma_rw = sf_none(),
  foi_index = NULL,
  foi_init = NULL,
  is_seroreversion = FALSE,
  seroreversion_prior = sf_normal(),
  ...
)

Arguments

serosurvey
survey_year

Year in which the survey took place (only needed to plot time models)

age_min

Floor value of the average between age_min and age_max

age_max

The size of the sample

n_sample

Number of samples for each age group

n_seropositive

Number of positive samples for each age group

model_type

Type of the model. Either "constant", "age" or "time"

is_log_foi

Boolean to set logarithmic scale in the FOI

foi_prior

Force-of-infection distribution specified by means of the helper functions. Currently available options are:

sf_normal

Function to set normal distribution priors

sf_uniform

Function to set uniform distribution priors

foi_sigma_rw

Prior distribution for the standard deviation of the force-of-infection. Currently available options are:

sf_normal

Function to set normal distribution prior. Available for time models in the log-scale

sf_cauchy

Function to set Cauchy distribution prior. Available for time models in regular scale.

foi_index

Integer vector specifying the age-groups for which force-of-infection values will be estimated. It can be specified by means of get_foi_index

foi_init

Initialization function for sampling. If null, default is chosen depending on the foi-scale of the model

is_seroreversion

Boolean specifying whether to include seroreversion rate estimation in the model

seroreversion_prior

seroreversion distribution specified by means of the helper functions. Currently available options are:

sf_normal

Function to set normal distribution priors

sf_uniform

Function to set uniform distribution priors

sf_none

Function to set no prior distribution

...

Additional parameters for rstan

Value

stan_fit object with force-of-infection and seroreversion (when applicable) samples

Examples

data(chagas2012)
seromodel <- fit_seromodel(
  serosurvey = chagas2012,
  model_type = "time",
  foi_index = data.frame(
    year = 1935:2011,
    foi_index = c(rep(1, 46), rep(2, 31))
  ),
  iter = 100
)
#> 
#> SAMPLING FOR MODEL 'time_no_seroreversion' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0.00084 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 8.4 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: WARNING: There aren't enough warmup iterations to fit the
#> Chain 1:          three stages of adaptation as currently configured.
#> Chain 1:          Reducing each adaptation stage to 15%/75%/10% of
#> Chain 1:          the given number of warmup iterations:
#> Chain 1:            init_buffer = 7
#> Chain 1:            adapt_window = 38
#> Chain 1:            term_buffer = 5
#> Chain 1: 
#> Chain 1: Iteration:  1 / 100 [  1%]  (Warmup)
#> Chain 1: Iteration: 10 / 100 [ 10%]  (Warmup)
#> Chain 1: Iteration: 20 / 100 [ 20%]  (Warmup)
#> Chain 1: Iteration: 30 / 100 [ 30%]  (Warmup)
#> Chain 1: Iteration: 40 / 100 [ 40%]  (Warmup)
#> Chain 1: Iteration: 50 / 100 [ 50%]  (Warmup)
#> Chain 1: Iteration: 51 / 100 [ 51%]  (Sampling)
#> Chain 1: Iteration: 60 / 100 [ 60%]  (Sampling)
#> Chain 1: Iteration: 70 / 100 [ 70%]  (Sampling)
#> Chain 1: Iteration: 80 / 100 [ 80%]  (Sampling)
#> Chain 1: Iteration: 90 / 100 [ 90%]  (Sampling)
#> Chain 1: Iteration: 100 / 100 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 0.425 seconds (Warm-up)
#> Chain 1:                0.387 seconds (Sampling)
#> Chain 1:                0.812 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'time_no_seroreversion' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 0.000588 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 5.88 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2: 
#> Chain 2: 
#> Chain 2: WARNING: There aren't enough warmup iterations to fit the
#> Chain 2:          three stages of adaptation as currently configured.
#> Chain 2:          Reducing each adaptation stage to 15%/75%/10% of
#> Chain 2:          the given number of warmup iterations:
#> Chain 2:            init_buffer = 7
#> Chain 2:            adapt_window = 38
#> Chain 2:            term_buffer = 5
#> Chain 2: 
#> Chain 2: Iteration:  1 / 100 [  1%]  (Warmup)
#> Chain 2: Iteration: 10 / 100 [ 10%]  (Warmup)
#> Chain 2: Iteration: 20 / 100 [ 20%]  (Warmup)
#> Chain 2: Iteration: 30 / 100 [ 30%]  (Warmup)
#> Chain 2: Iteration: 40 / 100 [ 40%]  (Warmup)
#> Chain 2: Iteration: 50 / 100 [ 50%]  (Warmup)
#> Chain 2: Iteration: 51 / 100 [ 51%]  (Sampling)
#> Chain 2: Iteration: 60 / 100 [ 60%]  (Sampling)
#> Chain 2: Iteration: 70 / 100 [ 70%]  (Sampling)
#> Chain 2: Iteration: 80 / 100 [ 80%]  (Sampling)
#> Chain 2: Iteration: 90 / 100 [ 90%]  (Sampling)
#> Chain 2: Iteration: 100 / 100 [100%]  (Sampling)
#> Chain 2: 
#> Chain 2:  Elapsed Time: 0.508 seconds (Warm-up)
#> Chain 2:                0.499 seconds (Sampling)
#> Chain 2:                1.007 seconds (Total)
#> Chain 2: 
#> 
#> SAMPLING FOR MODEL 'time_no_seroreversion' NOW (CHAIN 3).
#> Chain 3: 
#> Chain 3: Gradient evaluation took 0.000587 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 5.87 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3: 
#> Chain 3: 
#> Chain 3: WARNING: There aren't enough warmup iterations to fit the
#> Chain 3:          three stages of adaptation as currently configured.
#> Chain 3:          Reducing each adaptation stage to 15%/75%/10% of
#> Chain 3:          the given number of warmup iterations:
#> Chain 3:            init_buffer = 7
#> Chain 3:            adapt_window = 38
#> Chain 3:            term_buffer = 5
#> Chain 3: 
#> Chain 3: Iteration:  1 / 100 [  1%]  (Warmup)
#> Chain 3: Iteration: 10 / 100 [ 10%]  (Warmup)
#> Chain 3: Iteration: 20 / 100 [ 20%]  (Warmup)
#> Chain 3: Iteration: 30 / 100 [ 30%]  (Warmup)
#> Chain 3: Iteration: 40 / 100 [ 40%]  (Warmup)
#> Chain 3: Iteration: 50 / 100 [ 50%]  (Warmup)
#> Chain 3: Iteration: 51 / 100 [ 51%]  (Sampling)
#> Chain 3: Iteration: 60 / 100 [ 60%]  (Sampling)
#> Chain 3: Iteration: 70 / 100 [ 70%]  (Sampling)
#> Chain 3: Iteration: 80 / 100 [ 80%]  (Sampling)
#> Chain 3: Iteration: 90 / 100 [ 90%]  (Sampling)
#> Chain 3: Iteration: 100 / 100 [100%]  (Sampling)
#> Chain 3: 
#> Chain 3:  Elapsed Time: 0.542 seconds (Warm-up)
#> Chain 3:                0.515 seconds (Sampling)
#> Chain 3:                1.057 seconds (Total)
#> Chain 3: 
#> 
#> SAMPLING FOR MODEL 'time_no_seroreversion' NOW (CHAIN 4).
#> Chain 4: 
#> Chain 4: Gradient evaluation took 0.00059 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 5.9 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4: 
#> Chain 4: 
#> Chain 4: WARNING: There aren't enough warmup iterations to fit the
#> Chain 4:          three stages of adaptation as currently configured.
#> Chain 4:          Reducing each adaptation stage to 15%/75%/10% of
#> Chain 4:          the given number of warmup iterations:
#> Chain 4:            init_buffer = 7
#> Chain 4:            adapt_window = 38
#> Chain 4:            term_buffer = 5
#> Chain 4: 
#> Chain 4: Iteration:  1 / 100 [  1%]  (Warmup)
#> Chain 4: Iteration: 10 / 100 [ 10%]  (Warmup)
#> Chain 4: Iteration: 20 / 100 [ 20%]  (Warmup)
#> Chain 4: Iteration: 30 / 100 [ 30%]  (Warmup)
#> Chain 4: Iteration: 40 / 100 [ 40%]  (Warmup)
#> Chain 4: Iteration: 50 / 100 [ 50%]  (Warmup)
#> Chain 4: Iteration: 51 / 100 [ 51%]  (Sampling)
#> Chain 4: Iteration: 60 / 100 [ 60%]  (Sampling)
#> Chain 4: Iteration: 70 / 100 [ 70%]  (Sampling)
#> Chain 4: Iteration: 80 / 100 [ 80%]  (Sampling)
#> Chain 4: Iteration: 90 / 100 [ 90%]  (Sampling)
#> Chain 4: Iteration: 100 / 100 [100%]  (Sampling)
#> Chain 4: 
#> Chain 4:  Elapsed Time: 0.325 seconds (Warm-up)
#> Chain 4:                0.445 seconds (Sampling)
#> Chain 4:                0.77 seconds (Total)
#> Chain 4: 
#> Warning: The largest R-hat is 1.06, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> 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
#> https://mc-stan.org/misc/warnings.html#tail-ess