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: 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.00012 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.2 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: 22.499 seconds (Warm-up)
#> Chain 1: 10.643 seconds (Sampling)
#> Chain 1: 33.142 seconds (Total)
#> Chain 1:
#> Warning: There were 1142 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: Examine the pairs() plot to diagnose sampling problems
#> Warning: The largest R-hat is 1.2, 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 1.375486e-01 1.414959e-03 6.022566e-03 1.291198e-01
#> alpha2 1.953780e-01 1.788679e-03 8.152268e-03 1.850626e-01
#> alpha3 7.300955e-03 3.997114e-04 6.024438e-03 2.338770e-04
#> tau_alpha1 2.029118e-01 3.819832e-02 4.525285e-01 8.691784e-06
#> tau_alpha2 2.941813e-01 1.450314e-01 7.578939e-01 7.958567e-07
#> tau_alpha3 1.155979e+00 8.872560e-01 2.169811e+00 1.143055e-05
#> mu_alpha1 -3.040194e-01 1.257660e+00 2.919389e+01 -5.544686e+01
#> mu_alpha2 -4.205700e+00 2.443229e+00 3.520175e+01 -9.061386e+01
#> mu_alpha3 -9.312225e-01 1.049432e+00 2.404945e+01 -6.667831e+01
#> sigma_alpha1 7.490480e+01 1.702740e+01 4.007128e+02 7.412308e-01
#> sigma_alpha2 1.509768e+02 5.557536e+01 1.500069e+03 5.836841e-01
#> sigma_alpha3 1.580265e+02 1.197494e+02 2.228078e+03 3.674358e-01
#> lp__ -2.534649e+03 3.559884e-01 3.317282e+00 -2.541995e+03
#> 25% 50% 75% 97.5% n_eff
#> alpha1 1.320796e-01 1.372645e-01 1.421862e-01 1.497366e-01 18.116533
#> alpha2 1.884874e-01 1.940513e-01 2.009908e-01 2.128437e-01 20.772651
#> alpha3 2.951717e-03 6.404190e-03 9.339477e-03 2.369352e-02 227.164334
#> tau_alpha1 1.650895e-04 9.352836e-03 1.529895e-01 1.820091e+00 140.347052
#> tau_alpha2 1.038153e-03 3.656115e-03 1.399306e-01 2.935244e+00 27.308167
#> tau_alpha3 1.640202e-03 3.454710e-02 9.690013e-01 7.406912e+00 5.980616
#> mu_alpha1 -4.486445e+00 -3.098512e-01 2.462742e+00 6.747719e+01 538.837337
#> mu_alpha2 -8.995985e+00 -8.077621e-01 2.514301e+00 6.736891e+01 207.586902
#> mu_alpha3 -2.761475e+00 -1.833920e-01 2.502750e+00 5.303199e+01 525.172439
#> sigma_alpha1 2.556638e+00 1.034024e+01 7.782884e+01 3.391922e+02 553.821311
#> sigma_alpha2 2.673276e+00 1.653827e+01 3.103638e+01 1.121382e+03 728.547218
#> sigma_alpha3 1.015869e+00 5.380207e+00 2.469173e+01 2.957837e+02 346.189345
#> lp__ -2.536591e+03 -2.534378e+03 -2.532491e+03 -2.529171e+03 86.834690
#> Rhat
#> alpha1 1.0750454
#> alpha2 1.0542790
#> alpha3 0.9997181
#> tau_alpha1 1.0063710
#> tau_alpha2 1.0294630
#> tau_alpha3 1.2637902
#> mu_alpha1 1.0096425
#> mu_alpha2 1.0077149
#> mu_alpha3 1.0006734
#> sigma_alpha1 1.0002913
#> sigma_alpha2 1.0011905
#> sigma_alpha3 1.0019304
#> lp__ 1.0060537
plot(model)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
# }