Skip to contents

Parametric Bayesian framework

Currently, serosv only has models under parametric Bayesian framework

Proposed approach

Prevalence has a parametric form \(\pi(a_i, \alpha)\) where \(\alpha\) is a parameter vector

One can constraint the parameter space of the prior distribution \(P(\alpha)\) in order to achieve the desired monotonicity of the posterior distribution \(P(\pi_1, \pi_2, ..., \pi_m|y,n)\)

Where:

  • \(n = (n_1, n_2, ..., n_m)\) and \(n_i\) is the sample size at age \(a_i\)
  • \(y = (y_1, y_2, ..., y_m)\) and \(y_i\) is the number of infected individual from the \(n_i\) sampled subjects

Farrington

Refer to Chapter 10.3.1

Proposed model

The model for prevalence is as followed

\[ \pi (a) = 1 - exp\{ \frac{\alpha_1}{\alpha_2}ae^{-\alpha_2 a} + \frac{1}{\alpha_2}(\frac{\alpha_1}{\alpha_2} - \alpha_3)(e^{-\alpha_2 a} - 1) -\alpha_3 a \} \]

For likelihood model, independent binomial distribution are assumed for the number of infected individuals at age \(a_i\)

\[ y_i \sim Bin(n_i, \pi_i), \text{ for } i = 1,2,3,...m \]

The constraint on the parameter space can be incorporated by assuming truncated normal distribution for the components of \(\alpha\), \(\alpha = (\alpha_1, \alpha_2, \alpha_3)\) in \(\pi_i = \pi(a_i,\alpha)\)

\[ \alpha_j \sim \text{truncated } \mathcal{N}(\mu_j, \tau_j), \text{ } j = 1,2,3 \]

The joint posterior distribution for \(\alpha\) can be derived by combining the likelihood and prior as followed

\[ P(\alpha|y) \propto \prod^m_{i=1} \text{Bin}(y_i|n_i, \pi(a_i, \alpha)) \prod^3_{i=1}-\frac{1}{\tau_j}\text{exp}(\frac{1}{2\tau^2_j} (\alpha_j - \mu_j)^2) \]

  • Where the flat hyperprior distribution is defined as followed:

    • \(\mu_j \sim \mathcal{N}(0, 10000)\)

    • \(\tau^{-2}_j \sim \Gamma(100,100)\)

The full conditional distribution of \(\alpha_i\) is thus \[ P(\alpha_i|\alpha_j,\alpha_k, k, j \neq i) \propto -\frac{1}{\tau_i}\text{exp}(\frac{1}{2\tau^2_i} (\alpha_i - \mu_i)^2) \prod^m_{i=1} \text{Bin}(y_i|n_i, \pi(a_i, \alpha)) \]

Fitting data

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

  • type = "far2" refers to Farrington model with 2 parameters (\(\alpha_3 = 0\))

  • type = "far3" refers to Farrington model with 3 parameters (\(\alpha_3 > 0\))

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: 
#> Chain 1: Gradient evaluation took 0.000126 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.26 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: 15.967 seconds (Warm-up)
#> Chain 1:                2.939 seconds (Sampling)
#> Chain 1:                18.906 seconds (Total)
#> Chain 1:
#> Warning: There were 2169 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.69, 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.404610e-01  0.001270789 4.240893e-03  1.307983e-01
#> alpha2        1.978917e-01  0.001108002 4.847981e-03  1.876572e-01
#> alpha3        4.581793e-03  0.001129939 4.515832e-03  9.197295e-04
#> tau_alpha1    4.728669e+00  3.349642903 6.069512e+00  1.161593e-05
#> tau_alpha2    5.876988e-01  0.391563323 9.266651e-01  3.489248e-05
#> tau_alpha3    1.970699e-01  0.034753942 2.012707e-01  2.349313e-05
#> mu_alpha1    -4.970837e-01  1.465994271 2.893347e+01 -7.758940e+01
#> mu_alpha2     4.402852e+01 29.491225136 5.477443e+01 -2.072408e+01
#> mu_alpha3     4.022308e-01  1.433063710 1.918446e+01 -3.268952e+01
#> sigma_alpha1  3.605547e+01 13.476785763 1.898002e+02  2.459205e-01
#> sigma_alpha2  5.993208e+01 25.181868577 1.204609e+02  5.975497e-01
#> sigma_alpha3  2.025130e+01  5.860669345 9.620430e+01  1.265343e+00
#> lp__         -2.532041e+03  1.304420232 4.029538e+00 -2.541120e+03
#>                        25%           50%           75%         97.5%      n_eff
#> alpha1        1.376453e-01  1.416781e-01  1.435347e-01  1.474684e-01  11.136995
#> alpha2        1.946952e-01  1.991809e-01  2.006164e-01  2.082627e-01  19.144358
#> alpha3        2.563433e-03  2.845478e-03  3.655249e-03  1.856862e-02  15.972232
#> tau_alpha1    3.320626e-02  1.256068e+00  9.939663e+00  1.653524e+01   3.283300
#> tau_alpha2    9.649649e-05  2.070646e-03  1.226426e+00  2.800606e+00   5.600690
#> tau_alpha3    3.494424e-02  1.732966e-01  2.643553e-01  6.245737e-01  33.539229
#> mu_alpha1     5.012078e-02  1.780196e-01  4.387907e-01  5.980845e+01 389.525954
#> mu_alpha2     1.929633e-01  4.534205e+00  1.039994e+02  1.210853e+02   3.449611
#> mu_alpha3    -2.935927e-01  6.616097e-01  1.659996e+00  4.728202e+01 179.212421
#> sigma_alpha1  3.171861e-01  8.922642e-01  5.487755e+00  2.934647e+02 198.344781
#> sigma_alpha2  9.029823e-01  2.197893e+01  1.017992e+02  1.692911e+02  22.883168
#> sigma_alpha3  1.944939e+00  2.402177e+00  5.349488e+00  2.068504e+02 269.460111
#> lp__         -2.533908e+03 -2.532359e+03 -2.528288e+03 -2.526180e+03   9.542791
#>                  Rhat
#> alpha1       1.248572
#> alpha2       1.092689
#> alpha3       1.091090
#> tau_alpha1   1.657948
#> tau_alpha2   1.328989
#> tau_alpha3   1.015755
#> mu_alpha1    1.000124
#> mu_alpha2    1.811754
#> mu_alpha3    1.010423
#> sigma_alpha1 1.002090
#> sigma_alpha2 1.113388
#> sigma_alpha3 1.002690
#> lp__         1.053495
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

\[ \pi(a) = \frac{\beta a^\alpha}{1 + \beta a^\alpha}, \text{ } \alpha, \beta > 0 \]

The likelihood is specified to be the same as Farrington model (\(y_i \sim Bin(n_i, \pi_i)\)) with

\[ \text{logit}(\pi(a)) = \alpha_2 + \alpha_1\log(a) \]

  • Where \(\alpha_2 = \text{log}(\beta)\)

The prior model of \(\alpha_1\) is specified as \(\alpha_1 \sim \text{truncated } \mathcal{N}(\mu_1, \tau_1)\) with flat hyperprior as in Farrington model

\(\beta\) is constrained to be positive by specifying \(\alpha_2 \sim \mathcal{N}(\mu_2, \tau_2)\)

The full conditional distribution of \(\alpha_1\) is thus

\[ P(\alpha_1|\alpha_2) \propto -\frac{1}{\tau_1} \text{exp} (\frac{1}{2 \tau_1^2} (\alpha_1 - \mu_1)^2) \prod_{i=1}^m \text{Bin}(y_i|n_i,\pi(a_i, \alpha_1, \alpha_2) ) \]

And \(\alpha_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(age = df$age, pos = df$pos, tot = df$tot, type="log_logistic")
#> 
#> SAMPLING FOR MODEL 'log_logistic' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 7.1e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.71 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: 4.057 seconds (Warm-up)
#> Chain 1:                17.135 seconds (Sampling)
#> Chain 1:                21.192 seconds (Total)
#> Chain 1:
#> Warning: There were 264 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.