Refers to section 10.3
Usage
hierarchical_bayesian_model(
age,
pos = NULL,
tot = NULL,
status = NULL,
type = "far3",
chains = 1,
warmup = 1500,
iter = 5000
)
Arguments
- age
the age vector
- pos
the positive count vector (optional if status is provided).
- tot
the total count vector (optional if status is provided).
- status
the serostatus vector (optional if pos & tot are provided).
- type
type of model ("far2", "far3" or "log_logistic")
- chains
number of Markov chains
- warmup
number of warmup runs
- iter
number of iterations
Value
a list of class hierarchical_bayesian_model with 6 items
- datatype
type of datatype used for model fitting (aggregated or linelisting)
- df
the dataframe used for fitting the model
- type
type of bayesian model far2, far3 or log_logistic
- info
parameters for the fitted model
- sp
seroprevalence
- foi
force of infection
Examples
# \donttest{
df <- mumps_uk_1986_1987
model <- hierarchical_bayesian_model(age = df$age, pos = df$pos, tot = df$tot, type="far3")
#>
#> SAMPLING FOR MODEL 'fra_3' NOW (CHAIN 1).
#> Chain 1: Rejecting initial value:
#> Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
#> Chain 1: Stan can't start sampling from this initial value.
#> Chain 1: Rejecting initial value:
#> Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
#> Chain 1: Stan can't start sampling from this initial value.
#> Chain 1: Rejecting initial value:
#> Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
#> Chain 1: Stan can't start sampling from this initial value.
#> Chain 1:
#> Chain 1: Gradient evaluation took 0.000121 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.21 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Iteration: 1 / 5000 [ 0%] (Warmup)
#> Chain 1: Iteration: 500 / 5000 [ 10%] (Warmup)
#> Chain 1: Iteration: 1000 / 5000 [ 20%] (Warmup)
#> Chain 1: Iteration: 1500 / 5000 [ 30%] (Warmup)
#> Chain 1: Iteration: 1501 / 5000 [ 30%] (Sampling)
#> Chain 1: Iteration: 2000 / 5000 [ 40%] (Sampling)
#> Chain 1: Iteration: 2500 / 5000 [ 50%] (Sampling)
#> Chain 1: Iteration: 3000 / 5000 [ 60%] (Sampling)
#> Chain 1: Iteration: 3500 / 5000 [ 70%] (Sampling)
#> Chain 1: Iteration: 4000 / 5000 [ 80%] (Sampling)
#> Chain 1: Iteration: 4500 / 5000 [ 90%] (Sampling)
#> Chain 1: Iteration: 5000 / 5000 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 49.2 seconds (Warm-up)
#> Chain 1: 130.397 seconds (Sampling)
#> Chain 1: 179.597 seconds (Total)
#> Chain 1:
#> Warning: There were 754 divergent transitions after warmup. See
#> https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
#> to find out why this is a problem and how to eliminate them.
#> Warning: There were 441 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See
#> https://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded
#> Warning: Examine the pairs() plot to diagnose sampling problems
#> Warning: The largest R-hat is 1.14, 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
model$info
#> mean se_mean sd 2.5%
#> alpha1 2.125727e+76 1.873582e+76 9.857746e+77 2.086006e+01
#> alpha2 3.051760e+78 2.980399e+78 4.985109e+79 7.962382e+04
#> alpha3 1.709108e-01 8.195715e-04 3.146095e-03 1.667742e-01
#> tau_alpha1 9.889012e-02 9.193690e-02 9.748461e-01 1.841235e-105
#> tau_alpha2 9.395319e-08 5.345279e-08 2.296888e-06 3.584028e-143
#> tau_alpha3 2.376998e+01 1.514506e+01 3.586927e+01 3.939792e-06
#> mu_alpha1 5.884438e+00 2.884030e+00 8.530155e+01 -1.779321e+02
#> mu_alpha2 -6.249001e+00 2.874228e+00 8.427984e+01 -1.765891e+02
#> mu_alpha3 2.225693e+00 1.190663e+00 3.571111e+01 -6.603497e+01
#> sigma_alpha1 4.361931e+76 4.013065e+76 2.138431e+78 8.260705e+00
#> sigma_alpha2 2.579272e+78 2.446088e+78 3.697949e+79 1.367125e+05
#> sigma_alpha3 1.230550e+02 5.486590e+01 2.280212e+03 1.035053e-01
#> lp__ -2.656979e+03 6.507088e-01 3.424670e+00 -2.664633e+03
#> 25% 50% 75% 97.5%
#> alpha1 8.767568e+05 1.423411e+07 3.050902e+17 6.171746e+52
#> alpha2 8.417773e+16 3.154072e+31 6.436364e+45 5.309616e+70
#> alpha3 1.678333e-01 1.706392e-01 1.732886e-01 1.774482e-01
#> tau_alpha1 5.135079e-36 1.156093e-15 9.727284e-13 1.465456e-02
#> tau_alpha2 1.258968e-92 2.263345e-64 5.752806e-35 5.354637e-11
#> tau_alpha3 3.709497e-03 5.060957e-01 6.172539e+01 9.334150e+01
#> mu_alpha1 -3.590809e+01 8.194513e+00 4.749799e+01 1.806975e+02
#> mu_alpha2 -4.023764e+01 -3.018942e+01 4.648757e+01 1.754870e+02
#> mu_alpha3 -5.309773e-01 1.943059e-01 1.069483e+00 1.061274e+02
#> sigma_alpha1 1.013921e+06 2.943244e+07 4.414435e+17 4.255456e+52
#> sigma_alpha2 1.325968e+17 6.648715e+31 8.912360e+45 1.677776e+71
#> sigma_alpha3 1.272823e-01 1.405673e+00 1.641884e+01 5.038258e+02
#> lp__ -2.659324e+03 -2.656303e+03 -2.654219e+03 -2.652050e+03
#> n_eff Rhat
#> alpha1 2768.279665 0.9999745
#> alpha2 279.769550 1.0034368
#> alpha3 14.735669 1.0976911
#> tau_alpha1 112.432650 1.0077260
#> tau_alpha2 1846.455170 1.0000195
#> tau_alpha3 5.609229 1.2258454
#> mu_alpha1 874.811304 0.9997411
#> mu_alpha2 859.815120 1.0045739
#> mu_alpha3 899.556899 0.9997474
#> sigma_alpha1 2839.474300 1.0000051
#> sigma_alpha2 228.548178 1.0045025
#> sigma_alpha3 1727.211679 1.0005627
#> lp__ 27.699006 1.0232961
plot(model)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
# }