Processing math: 100%

Hierarchical Bayesian models

library(serosv)

Parametric Bayesian framework

Currently, serosv only has models under parametric Bayesian framework

Proposed approach

Prevalence has a parametric form π(ai,α) where α is a parameter vector

One can constraint the parameter space of the prior distribution P(α) in order to achieve the desired monotonicity of the posterior distribution P(π1,π2,...,πm|y,n)

Where:

Farrington

Refer to Chapter 10.3.1

Proposed model

The model for prevalence is as followed

π(a)=1exp{α1α2aeα2a+1α2(α1α2α3)(eα2a1)α3a}

For likelihood model, independent binomial distribution are assumed for the number of infected individuals at age ai

yiBin(ni,πi), for i=1,2,3,...m

The constraint on the parameter space can be incorporated by assuming truncated normal distribution for the components of α, α=(α1,α2,α3) in πi=π(ai,α)

αjtruncated N(μj,τj), j=1,2,3

The joint posterior distribution for α can be derived by combining the likelihood and prior as followed

P(α|y)mi=1Bin(yi|ni,π(ai,α))3i=11τjexp(12τ2j(αjμj)2)

The full conditional distribution of αi is thus P(αi|αj,αk,k,ji)1τiexp(12τ2i(αiμi)2)mi=1Bin(yi|ni,π(ai,α))

Fitting data

To fit Farrington model, use hierarchical_bayesian_model() and define type = "far2" or type = "far3" where

df <- mumps_uk_1986_1987
model <- hierarchical_bayesian_model(df, 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: 
#> Chain 1: Gradient evaluation took 6.6e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.66 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: 1.576 seconds (Warm-up)
#> Chain 1:                0.485 seconds (Sampling)
#> Chain 1:                2.061 seconds (Total)
#> Chain 1:
#> Warning: There were 1729 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.28, 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.359200e-01 1.718392e-03 6.634252e-03  1.267890e-01
#> alpha2        1.950533e-01 1.140411e-03 8.105212e-03  1.809270e-01
#> alpha3        7.567629e-03 3.736334e-04 5.954382e-03  6.839367e-04
#> tau_alpha1    3.526243e-01 1.867970e-01 9.495085e-01  4.317908e-06
#> tau_alpha2    1.668595e+00 1.274720e+00 3.000895e+00  9.079584e-06
#> tau_alpha3    8.960579e-02 4.787153e-02 2.607501e-01  3.228223e-06
#> mu_alpha1    -5.020807e+00 3.040566e+00 3.468501e+01 -9.811121e+01
#> mu_alpha2     1.092032e-01 1.214227e+00 2.812453e+01 -6.665632e+01
#> mu_alpha3    -9.867857e+00 8.021242e+00 4.499586e+01 -9.719373e+01
#> sigma_alpha1  7.096216e+01 1.549036e+01 3.165892e+02  5.643009e-01
#> sigma_alpha2  5.147320e+01 1.300805e+01 2.839421e+02  3.507393e-01
#> sigma_alpha3  4.555268e+02 3.579400e+02 9.370173e+03  9.808250e-01
#> lp__         -2.535145e+03 6.460925e-01 3.605881e+00 -2.543527e+03
#>                        25%           50%           75%         97.5%      n_eff
#> alpha1        1.305291e-01  1.337552e-01  1.408133e-01  1.504679e-01  14.905261
#> alpha2        1.912298e-01  1.929279e-01  1.984758e-01  2.153343e-01  50.513286
#> alpha3        3.710596e-03  6.979474e-03  8.457078e-03  2.479728e-02 253.969761
#> tau_alpha1    1.000828e-03  2.804623e-02  7.209248e-02  3.140354e+00  25.837941
#> tau_alpha2    3.931032e-03  7.702037e-02  1.193477e+00  8.128890e+00   5.542067
#> tau_alpha3    2.567107e-04  5.291966e-04  1.052404e-02  1.039482e+00  29.668421
#> mu_alpha1    -5.232470e+00 -2.381782e+00  7.419195e-01  6.725207e+01 130.129197
#> mu_alpha2    -1.684258e+00  3.198146e-01  2.342777e+00  6.354279e+01 536.500895
#> mu_alpha3    -4.227952e+01 -3.980619e+00  5.248327e+00  9.663215e+01  31.467480
#> sigma_alpha1  3.724389e+00  5.971215e+00  3.160979e+01  4.812418e+02 417.704858
#> sigma_alpha2  9.153621e-01  3.603273e+00  1.594949e+01  3.318847e+02 476.469754
#> sigma_alpha3  9.747849e+00  4.347019e+01  6.241343e+01  5.565829e+02 685.290783
#> lp__         -2.537527e+03 -2.533755e+03 -2.532478e+03 -2.529927e+03  31.148233
#>                   Rhat
#> alpha1       1.1107023
#> alpha2       1.0246646
#> alpha3       0.9997907
#> tau_alpha1   1.0059599
#> tau_alpha2   1.3294355
#> tau_alpha3   1.0125176
#> mu_alpha1    1.0224104
#> mu_alpha2    1.0010558
#> mu_alpha3    1.0505264
#> sigma_alpha1 1.0025618
#> sigma_alpha2 1.0075432
#> sigma_alpha3 1.0011065
#> lp__         1.1035163
plot(model)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.

Log-logistic

Proposed approach

The model for seroprevalence is as followed

π(a)=βaα1+βaα, α,β>0

The likelihood is specified to be the same as Farrington model (yiBin(ni,πi)) with

logit(π(a))=α2+α1log(a)

The prior model of α1 is specified as α1truncated N(μ1,τ1) with flat hyperprior as in Farrington model

β is constrained to be positive by specifying α2N(μ2,τ2)

The full conditional distribution of α1 is thus

P(α1|α2)1τ1exp(12τ21(α1μ1)2)mi=1Bin(yi|ni,π(ai,α1,α2))

And α2 can be derived in the same way

Fitting data

To fit Log-logistic model, use hierarchical_bayesian_model() and define type = "log_logistic"

df <- rubella_uk_1986_1987
model <- hierarchical_bayesian_model(df, type="log_logistic")
#> 
#> SAMPLING FOR MODEL 'log_logistic' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 1e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.1 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: 0.345 seconds (Warm-up)
#> Chain 1:                0.262 seconds (Sampling)
#> Chain 1:                0.607 seconds (Total)
#> Chain 1:
#> Warning: There were 587 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: 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$type
#> [1] "log_logistic"
plot(model)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.