Skip to contents

Estimate the true sero prevalence using Frequentist/Bayesian estimation

Usage

correct_prevalence(
  data,
  bayesian = TRUE,
  age_col = "age",
  pos_col = "pos",
  tot_col = "tot",
  status_col = "status",
  init_se = 0.95,
  init_sp = 0.8,
  study_size_se = 1000,
  study_size_sp = 1000,
  chains = 1,
  warmup = 1000,
  iter = 2000
)

Arguments

data

the input data frame, must either have columns for `age`, `pos`, `tot` (for aggregated data) OR `age`, `status` (for linelisting data)

bayesian

whether to adjust sero-prevalence using the Bayesian or frequentist approach. If set to `TRUE`, true sero-prevalence is estimated using MCMC.

age_col

name of the `age` column (default age_col="age").

pos_col

name of the `pos` column (default pos_col="pos").

tot_col

name of the `tot` column (default tot_col="tot").

status_col

name of the `status` column (default status_col="status").

init_se

sensitivity of the serological test

init_sp

specificity of the serological test

study_size_se

(applicable when `bayesian=TRUE`) study size for sensitivity validation study (i.e., number of confirmed infected patients in the study)

study_size_sp

(applicable when `bayesian=TRUE`) study size for specificity validation study (i.e., number of confirmed non-infected patients in the study)

chains

(applicable when `bayesian=TRUE`) number of Markov chains

warmup

(applicable when `bayesian=TRUE`) number of warm up runs

iter

(applicable when `bayesian=TRUE`) number of iterations

Value

a list of 3 items

info

estimated parameters (when `bayesian = TRUE`) or formula to compute corrected prevalence (when `bayesian = FALSE`)

df

data.frame of input data (in aggregated form) with the 95% confidence interval for apparent (i.e. observed) seroprevalence

corrected_se

data.frame containing age, the corresponding estimated seroprevalance with 95% confidence/credible interval, and adjusted tot and pos

method

method for prevalence correction (frequentist or bayesian)

Examples

data <- rubella_uk_1986_1987
correct_prevalence(data)
#> 
#> SAMPLING FOR MODEL 'prevalence_correction' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0.000138 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.38 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 1.796 seconds (Warm-up)
#> Chain 1:                1.361 seconds (Sampling)
#> Chain 1:                3.157 seconds (Total)
#> Chain 1: 
#> $info
#>                    mean      se_mean          sd          2.5%           25%
#> est_se     9.578983e-01 0.0001564491 0.005299343  9.475492e-01  9.545930e-01
#> est_sp     8.072674e-01 0.0003273161 0.011299689  7.868643e-01  7.998011e-01
#> theta[1]   1.669654e-02 0.0003291363 0.014951557  5.549454e-04  5.436573e-03
#> theta[2]   4.329741e-02 0.0007954605 0.033505745  1.467503e-03  1.651068e-02
#> theta[3]   3.879132e-02 0.0008799998 0.031081809  1.241802e-03  1.337696e-02
#> theta[4]   1.448606e-01 0.0012276323 0.046771985  5.281925e-02  1.118217e-01
#> theta[5]   3.153880e-01 0.0011343793 0.044372787  2.289082e-01  2.858122e-01
#> theta[6]   4.434183e-01 0.0010855364 0.047586866  3.510733e-01  4.096427e-01
#> theta[7]   4.647093e-01 0.0009291617 0.047351315  3.729134e-01  4.344579e-01
#> theta[8]   6.095610e-01 0.0013721435 0.050000717  5.089066e-01  5.767979e-01
#> theta[9]   7.187272e-01 0.0008927006 0.040907083  6.377160e-01  6.913358e-01
#> theta[10]  6.424637e-01 0.0010754826 0.049940181  5.401598e-01  6.103942e-01
#> theta[11]  7.249644e-01 0.0010735915 0.045912976  6.303863e-01  6.935997e-01
#> theta[12]  8.234903e-01 0.0009684222 0.036816018  7.511686e-01  7.976608e-01
#> theta[13]  7.618391e-01 0.0009278374 0.042091597  6.728069e-01  7.347508e-01
#> theta[14]  8.601090e-01 0.0008489790 0.036252554  7.842988e-01  8.375775e-01
#> theta[15]  7.699981e-01 0.0015022090 0.064044742  6.362368e-01  7.257891e-01
#> theta[16]  8.389379e-01 0.0017984439 0.059243813  7.121039e-01  8.011785e-01
#> theta[17]  9.140480e-01 0.0010677130 0.044420964  8.111940e-01  8.886860e-01
#> theta[18]  8.761843e-01 0.0010016606 0.046316174  7.737187e-01  8.469274e-01
#> theta[19]  8.814184e-01 0.0009722171 0.041926032  7.894166e-01  8.552368e-01
#> theta[20]  8.523403e-01 0.0013253153 0.055634736  7.341595e-01  8.151135e-01
#> theta[21]  9.131240e-01 0.0011861298 0.046023911  8.116555e-01  8.845245e-01
#> theta[22]  8.269171e-01 0.0010882429 0.049660076  7.243766e-01  7.964444e-01
#> theta[23]  9.481100e-01 0.0008517645 0.034750745  8.645941e-01  9.282505e-01
#> theta[24]  9.461300e-01 0.0010070969 0.034504325  8.681899e-01  9.248499e-01
#> theta[25]  9.699000e-01 0.0005241616 0.022601922  9.126689e-01  9.582041e-01
#> theta[26]  9.390541e-01 0.0009863739 0.035254120  8.601011e-01  9.182011e-01
#> theta[27]  9.247749e-01 0.0010298051 0.038121127  8.442768e-01  8.997571e-01
#> theta[28]  9.595704e-01 0.0007194901 0.031411871  8.821263e-01  9.425301e-01
#> theta[29]  9.063620e-01 0.0012481463 0.045942710  7.997833e-01  8.797070e-01
#> theta[30]  9.165815e-01 0.0011682592 0.047483212  8.130119e-01  8.890910e-01
#> theta[31]  8.597531e-01 0.0014521275 0.062359464  7.255506e-01  8.188071e-01
#> theta[32]  9.404372e-01 0.0011422222 0.044701885  8.330009e-01  9.173810e-01
#> theta[33]  9.371685e-01 0.0010877382 0.049343779  8.209475e-01  9.119171e-01
#> theta[34]  9.471238e-01 0.0010867016 0.044937620  8.363487e-01  9.235314e-01
#> theta[35]  8.960836e-01 0.0014374909 0.061383474  7.561438e-01  8.572547e-01
#> theta[36]  9.558507e-01 0.0009861226 0.039780189  8.479101e-01  9.378256e-01
#> theta[37]  9.393751e-01 0.0012388854 0.047679828  8.161455e-01  9.158068e-01
#> theta[38]  9.012769e-01 0.0014164823 0.060900832  7.644432e-01  8.664412e-01
#> theta[39]  9.195168e-01 0.0016743658 0.060735446  7.742928e-01  8.865756e-01
#> theta[40]  9.368969e-01 0.0012956190 0.053206576  8.018638e-01  9.090884e-01
#> theta[41]  9.519623e-01 0.0012660166 0.048138541  8.228055e-01  9.337493e-01
#> theta[42]  9.194543e-01 0.0015372919 0.069305536  7.468094e-01  8.781855e-01
#> theta[43]  9.094111e-01 0.0018270703 0.078465591  7.079141e-01  8.681752e-01
#> theta[44]  9.367735e-01 0.0014203068 0.062566898  7.705174e-01  9.111712e-01
#> lp__      -2.763100e+03 0.3407042473 5.809555889 -2.774868e+03 -2.766679e+03
#>                     50%           75%         97.5%     n_eff      Rhat
#> est_se     9.580472e-01  9.618166e-01  9.675911e-01 1147.3558 1.0008010
#> est_sp     8.072815e-01  8.150193e-01  8.287246e-01 1191.7860 1.0005527
#> theta[1]   1.265957e-02  2.280508e-02  5.577128e-02 2063.5798 0.9991123
#> theta[2]   3.566937e-02  6.322686e-02  1.206142e-01 1774.1949 1.0008382
#> theta[3]   3.234279e-02  5.593393e-02  1.157535e-01 1247.5199 0.9990031
#> theta[4]   1.429949e-01  1.764445e-01  2.370467e-01 1451.5600 0.9990775
#> theta[5]   3.141435e-01  3.452631e-01  4.018391e-01 1530.0894 0.9990028
#> theta[6]   4.443684e-01  4.742828e-01  5.331767e-01 1921.6994 0.9992167
#> theta[7]   4.647795e-01  4.956444e-01  5.581049e-01 2597.0572 0.9993886
#> theta[8]   6.107021e-01  6.411558e-01  7.068452e-01 1327.8634 1.0008550
#> theta[9]   7.183645e-01  7.477843e-01  7.961476e-01 2099.8357 0.9989998
#> theta[10]  6.440328e-01  6.785150e-01  7.348042e-01 2156.2219 0.9998202
#> theta[11]  7.267195e-01  7.585823e-01  8.079132e-01 1828.9118 1.0000115
#> theta[12]  8.258218e-01  8.501723e-01  8.885769e-01 1445.2540 0.9990750
#> theta[13]  7.641737e-01  7.899657e-01  8.416700e-01 2058.0082 1.0008883
#> theta[14]  8.606840e-01  8.845478e-01  9.292628e-01 1823.4056 0.9991442
#> theta[15]  7.720891e-01  8.143762e-01  8.818328e-01 1817.6332 0.9996487
#> theta[16]  8.423321e-01  8.819023e-01  9.422853e-01 1085.1562 0.9992634
#> theta[17]  9.174596e-01  9.470447e-01  9.857562e-01 1730.8796 0.9996854
#> theta[18]  8.801411e-01  9.076787e-01  9.569382e-01 2138.0809 0.9991453
#> theta[19]  8.838135e-01  9.113407e-01  9.559063e-01 1859.6920 0.9990211
#> theta[20]  8.560078e-01  8.943424e-01  9.469605e-01 1762.1937 0.9991939
#> theta[21]  9.162745e-01  9.456814e-01  9.896018e-01 1505.5756 0.9990450
#> theta[22]  8.297876e-01  8.613889e-01  9.150618e-01 2082.3947 1.0005471
#> theta[23]  9.538836e-01  9.741659e-01  9.959213e-01 1664.5207 0.9990466
#> theta[24]  9.522831e-01  9.735068e-01  9.950129e-01 1173.8282 0.9992849
#> theta[25]  9.745490e-01  9.873933e-01  9.981742e-01 1859.3466 0.9993630
#> theta[26]  9.435099e-01  9.664215e-01  9.912220e-01 1277.4286 0.9993886
#> theta[27]  9.305068e-01  9.526727e-01  9.877526e-01 1370.3181 0.9998641
#> theta[28]  9.666047e-01  9.837204e-01  9.979154e-01 1906.0660 1.0018095
#> theta[29]  9.102604e-01  9.398177e-01  9.841393e-01 1354.8844 1.0005505
#> theta[30]  9.212163e-01  9.536439e-01  9.911483e-01 1651.9686 0.9999586
#> theta[31]  8.621003e-01  9.067179e-01  9.640881e-01 1844.1458 0.9991159
#> theta[32]  9.476940e-01  9.764106e-01  9.966453e-01 1531.6181 0.9991615
#> theta[33]  9.468479e-01  9.759285e-01  9.969125e-01 2057.8612 0.9998342
#> theta[34]  9.586939e-01  9.801665e-01  9.977756e-01 1710.0135 1.0001468
#> theta[35]  9.077136e-01  9.439052e-01  9.901030e-01 1823.4451 0.9992650
#> theta[36]  9.665357e-01  9.852162e-01  9.986833e-01 1627.3158 0.9999466
#> theta[37]  9.497114e-01  9.753977e-01  9.982296e-01 1481.1774 0.9990695
#> theta[38]  9.088730e-01  9.488198e-01  9.908209e-01 1848.5198 0.9992228
#> theta[39]  9.306081e-01  9.655231e-01  9.956106e-01 1315.7814 0.9991682
#> theta[40]  9.517907e-01  9.785200e-01  9.977298e-01 1686.4599 0.9993031
#> theta[41]  9.679552e-01  9.866211e-01  9.983313e-01 1445.7961 0.9989998
#> theta[42]  9.401710e-01  9.734705e-01  9.966189e-01 2032.4654 0.9990749
#> theta[43]  9.302229e-01  9.693141e-01  9.976236e-01 1844.3697 0.9996387
#> theta[44]  9.570638e-01  9.814269e-01  9.987236e-01 1940.5504 0.9990096
#> lp__      -2.762992e+03 -2.759004e+03 -2.752454e+03  290.7574 1.0008494
#> 
#> $df
#>     age pos tot      sero  sero_lwr  sero_upr
#> 1   1.5  31 206 0.1504854 0.1060177 0.2083748
#> 2   2.5  30 146 0.2054795 0.1449496 0.2818842
#> 3   3.5  34 168 0.2023810 0.1460087 0.2727002
#> 4   4.5  57 189 0.3015873 0.2382102 0.3731851
#> 5   5.5  95 219 0.4337900 0.3676479 0.5022934
#> 6   6.5 104 195 0.5333333 0.4608072 0.6045248
#> 7   7.5  90 164 0.5487805 0.4693519 0.6258878
#> 8   8.5  96 145 0.6620690 0.5782402 0.7371628
#> 9   9.5 134 180 0.7444444 0.6731424 0.8050917
#> 10 10.5 110 160 0.6875000 0.6087555 0.7570748
#> 11 11.5 111 148 0.7500000 0.6709203 0.8158278
#> 12 12.5 147 178 0.8258427 0.7603216 0.8769152
#> 13 13.5 138 177 0.7796610 0.7099871 0.8369125
#> 14 14.5 141 165 0.8545455 0.7892898 0.9027796
#> 15 15.5  53  67 0.7910448 0.6710850 0.8771184
#> 16 16.5  49  58 0.8448276 0.7207490 0.9223300
#> 17 17.5  73  81 0.9012346 0.8095518 0.9533386
#> 18 18.5  69  79 0.8734177 0.7750073 0.9343581
#> 19 19.5  97 111 0.8738739 0.7941533 0.9268253
#> 20 20.5  65  76 0.8552632 0.7515326 0.9220985
#> 21 21.5  74  82 0.9024390 0.8117280 0.9539169
#> 22 22.5  84 101 0.8316832 0.7413312 0.8961330
#> 23 23.5  82  88 0.9318182 0.8519298 0.9719801
#> 24 24.5  79  85 0.9294118 0.8470005 0.9709798
#> 25 25.5  90  94 0.9574468 0.8884991 0.9862810
#> 26 26.5  84  91 0.9230769 0.8427965 0.9658735
#> 27 27.5  81  89 0.9101124 0.8256740 0.9575953
#> 28 28.5  72  76 0.9473684 0.8636358 0.9830057
#> 29 29.5  71  79 0.8987342 0.8050453 0.9521374
#> 30 30.5  51  56 0.9107143 0.7963017 0.9666611
#> 31 31.5  45  52 0.8653846 0.7359542 0.9396995
#> 32 32.5  45  48 0.9375000 0.8179078 0.9837187
#> 33 33.5  35  37 0.9459459 0.8046945 0.9905819
#> 34 34.5  39  41 0.9512195 0.8219181 0.9915057
#> 35 35.5  36  40 0.9000000 0.7540414 0.9674737
#> 36 36.5  37  38 0.9736842 0.8456597 0.9986248
#> 37 37.5  37  39 0.9487179 0.8137029 0.9910676
#> 38 38.5  37  41 0.9024390 0.7594053 0.9682791
#> 39 39.5  28  30 0.9333333 0.7649271 0.9883682
#> 40 40.5  26  27 0.9629630 0.7911082 0.9980636
#> 41 41.5  25  25 1.0000000 0.8342270 1.0000000
#> 42 42.5  21  22 0.9545455 0.7511570 0.9976227
#> 43 43.5  18  19 0.9473684 0.7189259 0.9972465
#> 44 44.5  18  18 1.0000000 0.7812431 1.0000000
#> 
#> $corrected_se
#>     age        pos tot       sero     sero_lwr   sero_upr
#> 1   1.5   2.607870 206 0.01265957 0.0005549454 0.05577128
#> 2   2.5   5.207727 146 0.03566937 0.0014675025 0.12061422
#> 3   3.5   5.433589 168 0.03234279 0.0012418020 0.11575350
#> 4   4.5  27.026028 189 0.14299486 0.0528192495 0.23704671
#> 5   5.5  68.797434 219 0.31414353 0.2289081743 0.40183911
#> 6   6.5  86.651841 195 0.44436842 0.3510733317 0.53317669
#> 7   7.5  76.223832 164 0.46477947 0.3729134024 0.55810495
#> 8   8.5  88.551801 145 0.61070208 0.5089066357 0.70684521
#> 9   9.5 129.305605 180 0.71836447 0.6377159760 0.79614756
#> 10 10.5 103.045252 160 0.64403283 0.5401598355 0.73480416
#> 11 11.5 107.554485 148 0.72671950 0.6303862815 0.80791320
#> 12 12.5 146.996279 178 0.82582179 0.7511685854 0.88857692
#> 13 13.5 135.258748 177 0.76417372 0.6728068678 0.84167002
#> 14 14.5 142.012854 165 0.86068397 0.7842987651 0.92926279
#> 15 15.5  51.729968  67 0.77208908 0.6362368038 0.88183283
#> 16 16.5  48.855264  58 0.84233214 0.7121038773 0.94228535
#> 17 17.5  74.314226  81 0.91745957 0.8111940053 0.98575618
#> 18 18.5  69.531146  79 0.88014109 0.7737187428 0.95693818
#> 19 19.5  98.103304 111 0.88381355 0.7894165884 0.95590629
#> 20 20.5  65.056589  76 0.85600776 0.7341595318 0.94696046
#> 21 21.5  75.134509  82 0.91627450 0.8116554890 0.98960176
#> 22 22.5  83.808543 101 0.82978755 0.7243766186 0.91506183
#> 23 23.5  83.941759  88 0.95388363 0.8645940995 0.99592134
#> 24 24.5  80.944060  85 0.95228306 0.8681899268 0.99501289
#> 25 25.5  91.607607  94 0.97454901 0.9126688989 0.99817423
#> 26 26.5  85.859401  91 0.94350990 0.8601010747 0.99122195
#> 27 27.5  82.815102  89 0.93050676 0.8442768096 0.98775260
#> 28 28.5  73.461959  76 0.96660472 0.8821263027 0.99791536
#> 29 29.5  71.910571  79 0.91026039 0.7997833469 0.98413933
#> 30 30.5  51.588113  56 0.92121630 0.8130118670 0.99114835
#> 31 31.5  44.829214  52 0.86210027 0.7255506043 0.96408809
#> 32 32.5  45.489312  48 0.94769400 0.8330009069 0.99664527
#> 33 33.5  35.033373  37 0.94684793 0.8209475261 0.99691254
#> 34 34.5  39.306449  41 0.95869387 0.8363486668 0.99777557
#> 35 35.5  36.308543  40 0.90771357 0.7561438104 0.99010304
#> 36 36.5  36.728355  38 0.96653566 0.8479100953 0.99868333
#> 37 37.5  37.038746  39 0.94971144 0.8161455149 0.99822960
#> 38 38.5  37.263792  41 0.90887297 0.7644432016 0.99082093
#> 39 39.5  27.918243  30 0.93060811 0.7742928481 0.99561055
#> 40 40.5  25.698349  27 0.95179072 0.8018638379 0.99772984
#> 41 41.5  24.198880  25 0.96795520 0.8228055240 0.99833129
#> 42 42.5  20.683763  22 0.94017104 0.7468094381 0.99661886
#> 43 43.5  17.674236  19 0.93022292 0.7079141484 0.99762362
#> 44 44.5  17.227149  18 0.95706384 0.7705174295 0.99872365
#> 
#> $method
#> [1] "bayesian"
#>