Skip to contents

Estimate the true sero prevalence using Frequentist/Bayesian estimation

Usage

correct_prevalence(
  data,
  bayesian = TRUE,
  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 `age`, `pos`, `tot` columns (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.

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)

corrected_sero

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

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.000244 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 2.44 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.656 seconds (Warm-up)
#> Chain 1:                1.233 seconds (Sampling)
#> Chain 1:                2.889 seconds (Total)
#> Chain 1: 
#> $info
#>                    mean      se_mean          sd          2.5%           25%
#> est_se     9.579691e-01 0.0001720772 0.005234571  9.468221e-01  9.545560e-01
#> est_sp     8.070363e-01 0.0003593900 0.010998038  7.851243e-01  8.001180e-01
#> theta[1]   1.747732e-02 0.0004012933 0.015518658  3.397982e-04  5.556424e-03
#> theta[2]   4.521156e-02 0.0009719303 0.032103002  3.497362e-03  1.967008e-02
#> theta[3]   3.934172e-02 0.0008073821 0.027757712  1.900997e-03  1.793613e-02
#> theta[4]   1.439986e-01 0.0014055351 0.046463549  5.425350e-02  1.123683e-01
#> theta[5]   3.158280e-01 0.0011278041 0.045792461  2.305850e-01  2.838526e-01
#> theta[6]   4.452249e-01 0.0012812842 0.047140675  3.545909e-01  4.120292e-01
#> theta[7]   4.636578e-01 0.0013137642 0.049670685  3.671684e-01  4.296514e-01
#> theta[8]   6.077679e-01 0.0012322838 0.051758945  5.034081e-01  5.746207e-01
#> theta[9]   7.173174e-01 0.0011569343 0.042494430  6.248539e-01  6.900703e-01
#> theta[10]  6.414107e-01 0.0013163957 0.050844687  5.427184e-01  6.076674e-01
#> theta[11]  7.251551e-01 0.0012041984 0.046902001  6.257779e-01  6.937983e-01
#> theta[12]  8.200245e-01 0.0010676660 0.039122057  7.334985e-01  7.953583e-01
#> theta[13]  7.607357e-01 0.0010292102 0.041323713  6.779961e-01  7.336668e-01
#> theta[14]  8.589639e-01 0.0008862776 0.033589290  7.896023e-01  8.380959e-01
#> theta[15]  7.716052e-01 0.0017929505 0.065516404  6.349394e-01  7.285860e-01
#> theta[16]  8.381310e-01 0.0017053329 0.066149986  7.006723e-01  7.966934e-01
#> theta[17]  9.133985e-01 0.0014411494 0.044158724  8.153283e-01  8.879187e-01
#> theta[18]  8.803590e-01 0.0013704992 0.048219400  7.815409e-01  8.477237e-01
#> theta[19]  8.801362e-01 0.0009873217 0.041440481  7.940748e-01  8.510319e-01
#> theta[20]  8.516456e-01 0.0013062293 0.051569875  7.386624e-01  8.196764e-01
#> theta[21]  9.149110e-01 0.0014600247 0.046220606  8.144062e-01  8.874402e-01
#> theta[22]  8.248331e-01 0.0012972922 0.049342001  7.226267e-01  7.924436e-01
#> theta[23]  9.461869e-01 0.0012688504 0.035172720  8.654861e-01  9.237220e-01
#> theta[24]  9.458786e-01 0.0010783110 0.033650049  8.708283e-01  9.239385e-01
#> theta[25]  9.706552e-01 0.0006278715 0.023829751  9.115230e-01  9.589298e-01
#> theta[26]  9.400029e-01 0.0010821960 0.033457664  8.681502e-01  9.181518e-01
#> theta[27]  9.251679e-01 0.0012477057 0.043365359  8.198036e-01  9.011331e-01
#> theta[28]  9.578219e-01 0.0008736670 0.032194552  8.824005e-01  9.384708e-01
#> theta[29]  9.064031e-01 0.0012458483 0.043045202  8.166192e-01  8.788169e-01
#> theta[30]  9.164445e-01 0.0013366119 0.049352158  8.018241e-01  8.855027e-01
#> theta[31]  8.607109e-01 0.0017207072 0.062663082  7.114398e-01  8.265632e-01
#> theta[32]  9.407438e-01 0.0012121067 0.045559916  8.244369e-01  9.173058e-01
#> theta[33]  9.357270e-01 0.0013794554 0.054278925  7.888680e-01  9.085377e-01
#> theta[34]  9.458862e-01 0.0012548097 0.043638644  8.334385e-01  9.249963e-01
#> theta[35]  8.961572e-01 0.0018858060 0.062735450  7.444533e-01  8.625101e-01
#> theta[36]  9.553792e-01 0.0009240727 0.037492222  8.613046e-01  9.363582e-01
#> theta[37]  9.389160e-01 0.0014208188 0.049938528  8.041306e-01  9.158440e-01
#> theta[38]  8.990585e-01 0.0018333159 0.066536570  7.442794e-01  8.581524e-01
#> theta[39]  9.168747e-01 0.0018935154 0.062687616  7.562417e-01  8.885957e-01
#> theta[40]  9.371065e-01 0.0015140064 0.056832194  7.920169e-01  9.115977e-01
#> theta[41]  9.528511e-01 0.0010380880 0.045128543  8.275254e-01  9.341298e-01
#> theta[42]  9.173219e-01 0.0017494957 0.065112154  7.639822e-01  8.834364e-01
#> theta[43]  9.080154e-01 0.0019124502 0.072102410  7.300474e-01  8.720032e-01
#> theta[44]  9.386586e-01 0.0014204252 0.055390859  8.014757e-01  9.138788e-01
#> lp__      -2.763145e+03 0.3011237007 5.715746786 -2.775866e+03 -2.766777e+03
#>                     50%           75%         97.5%     n_eff      Rhat
#> est_se     9.582485e-01  9.613921e-01  9.678490e-01  925.3698 0.9990461
#> est_sp     8.070742e-01  8.144335e-01  8.281304e-01  936.4798 1.0003010
#> theta[1]   1.325944e-02  2.580038e-02  5.764662e-02 1495.4931 0.9990388
#> theta[2]   3.926800e-02  6.313427e-02  1.179769e-01 1090.9906 0.9991753
#> theta[3]   3.510345e-02  5.608013e-02  1.059055e-01 1181.9772 0.9992290
#> theta[4]   1.436227e-01  1.740261e-01  2.363213e-01 1092.8017 1.0041265
#> theta[5]   3.135946e-01  3.461306e-01  4.051240e-01 1648.6201 1.0032065
#> theta[6]   4.451716e-01  4.781418e-01  5.345672e-01 1353.6321 1.0045891
#> theta[7]   4.650392e-01  4.964724e-01  5.600045e-01 1429.4384 0.9991162
#> theta[8]   6.071917e-01  6.426559e-01  7.083871e-01 1764.2062 0.9996147
#> theta[9]   7.187469e-01  7.459264e-01  7.981012e-01 1349.1078 0.9994776
#> theta[10]  6.413189e-01  6.777565e-01  7.376091e-01 1491.8264 0.9999393
#> theta[11]  7.275840e-01  7.571155e-01  8.113803e-01 1517.0036 0.9990510
#> theta[12]  8.232098e-01  8.466952e-01  8.914191e-01 1342.6802 0.9990800
#> theta[13]  7.630979e-01  7.894624e-01  8.355361e-01 1612.0945 0.9994269
#> theta[14]  8.596282e-01  8.830362e-01  9.199369e-01 1436.3561 1.0028516
#> theta[15]  7.768558e-01  8.169429e-01  8.886224e-01 1335.2529 0.9990301
#> theta[16]  8.440784e-01  8.872369e-01  9.488487e-01 1504.6697 0.9990161
#> theta[17]  9.172955e-01  9.451696e-01  9.910868e-01  938.8907 0.9990891
#> theta[18]  8.832052e-01  9.150528e-01  9.691902e-01 1237.9014 1.0004986
#> theta[19]  8.835078e-01  9.116064e-01  9.480115e-01 1761.7010 0.9998162
#> theta[20]  8.551365e-01  8.881845e-01  9.406861e-01 1558.6669 1.0006793
#> theta[21]  9.202015e-01  9.487129e-01  9.903668e-01 1002.1918 1.0008532
#> theta[22]  8.264882e-01  8.589395e-01  9.131122e-01 1446.6315 0.9993236
#> theta[23]  9.535076e-01  9.739242e-01  9.950822e-01  768.4065 0.9994326
#> theta[24]  9.497731e-01  9.711970e-01  9.966858e-01  973.8305 0.9995677
#> theta[25]  9.762265e-01  9.886092e-01  9.990507e-01 1440.4476 1.0010816
#> theta[26]  9.439230e-01  9.641349e-01  9.964088e-01  955.8272 1.0003354
#> theta[27]  9.305549e-01  9.561449e-01  9.929416e-01 1207.9850 0.9998152
#> theta[28]  9.653058e-01  9.828475e-01  9.980652e-01 1357.9160 0.9997075
#> theta[29]  9.094284e-01  9.377292e-01  9.803109e-01 1193.7659 0.9990008
#> theta[30]  9.239625e-01  9.526448e-01  9.917734e-01 1363.3321 0.9990114
#> theta[31]  8.645073e-01  9.066013e-01  9.615028e-01 1326.2016 0.9995796
#> theta[32]  9.514552e-01  9.741705e-01  9.978432e-01 1412.8111 0.9994082
#> theta[33]  9.493927e-01  9.758949e-01  9.982326e-01 1548.2716 1.0000931
#> theta[34]  9.557844e-01  9.797785e-01  9.973173e-01 1209.4468 0.9998171
#> theta[35]  9.057973e-01  9.406812e-01  9.882563e-01 1106.7053 0.9990242
#> theta[36]  9.663073e-01  9.840566e-01  9.982648e-01 1646.1524 0.9992741
#> theta[37]  9.502159e-01  9.773138e-01  9.976396e-01 1235.3616 0.9992080
#> theta[38]  9.099911e-01  9.501315e-01  9.910139e-01 1317.1832 0.9990001
#> theta[39]  9.280455e-01  9.629734e-01  9.939965e-01 1096.0386 0.9992802
#> theta[40]  9.530193e-01  9.777640e-01  9.975286e-01 1409.0728 0.9993224
#> theta[41]  9.646571e-01  9.854371e-01  9.991666e-01 1889.8803 0.9991952
#> theta[42]  9.328743e-01  9.681655e-01  9.964167e-01 1385.1550 0.9990917
#> theta[43]  9.253118e-01  9.602544e-01  9.959770e-01 1421.4097 0.9991980
#> theta[44]  9.546272e-01  9.817446e-01  9.978124e-01 1520.6858 0.9991256
#> lp__      -2.762797e+03 -2.759032e+03 -2.753133e+03  360.2932 1.0126026
#> 
#> $df
#>     age pos tot
#> 1   1.5  31 206
#> 2   2.5  30 146
#> 3   3.5  34 168
#> 4   4.5  57 189
#> 5   5.5  95 219
#> 6   6.5 104 195
#> 7   7.5  90 164
#> 8   8.5  96 145
#> 9   9.5 134 180
#> 10 10.5 110 160
#> 11 11.5 111 148
#> 12 12.5 147 178
#> 13 13.5 138 177
#> 14 14.5 141 165
#> 15 15.5  53  67
#> 16 16.5  49  58
#> 17 17.5  73  81
#> 18 18.5  69  79
#> 19 19.5  97 111
#> 20 20.5  65  76
#> 21 21.5  74  82
#> 22 22.5  84 101
#> 23 23.5  82  88
#> 24 24.5  79  85
#> 25 25.5  90  94
#> 26 26.5  84  91
#> 27 27.5  81  89
#> 28 28.5  72  76
#> 29 29.5  71  79
#> 30 30.5  51  56
#> 31 31.5  45  52
#> 32 32.5  45  48
#> 33 33.5  35  37
#> 34 34.5  39  41
#> 35 35.5  36  40
#> 36 36.5  37  38
#> 37 37.5  37  39
#> 38 38.5  37  41
#> 39 39.5  28  30
#> 40 40.5  26  27
#> 41 41.5  25  25
#> 42 42.5  21  22
#> 43 43.5  18  19
#> 44 44.5  18  18
#> 
#> $corrected_se
#>     age       sero        pos tot     sero_lwr   sero_upr
#> 1   1.5 0.01325944   2.731444 206 0.0003397982 0.05764662
#> 2   2.5 0.03926800   5.733129 146 0.0034973616 0.11797694
#> 3   3.5 0.03510345   5.897379 168 0.0019009974 0.10590546
#> 4   4.5 0.14362274  27.144698 189 0.0542534972 0.23632128
#> 5   5.5 0.31359457  68.677211 219 0.2305849615 0.40512397
#> 6   6.5 0.44517156  86.808453 195 0.3545909437 0.53456725
#> 7   7.5 0.46503915  76.266421 164 0.3671684261 0.56000455
#> 8   8.5 0.60719173  88.042801 145 0.5034081474 0.70838708
#> 9   9.5 0.71874687 129.374436 180 0.6248538646 0.79810121
#> 10 10.5 0.64131891 102.611026 160 0.5427183649 0.73760906
#> 11 11.5 0.72758395 107.682425 148 0.6257778650 0.81138031
#> 12 12.5 0.82320978 146.531341 178 0.7334985417 0.89141914
#> 13 13.5 0.76309793 135.068334 177 0.6779961210 0.83553609
#> 14 14.5 0.85962824 141.838659 165 0.7896023026 0.91993691
#> 15 15.5 0.77685579  52.049338  67 0.6349393644 0.88862239
#> 16 16.5 0.84407836  48.956545  58 0.7006722751 0.94884869
#> 17 17.5 0.91729554  74.300939  81 0.8153282665 0.99108683
#> 18 18.5 0.88320521  69.773211  79 0.7815408701 0.96919022
#> 19 19.5 0.88350782  98.069368 111 0.7940747981 0.94801151
#> 20 20.5 0.85513649  64.990373  76 0.7386624226 0.94068610
#> 21 21.5 0.92020148  75.456521  82 0.8144062288 0.99036682
#> 22 22.5 0.82648821  83.475309 101 0.7226266670 0.91311217
#> 23 23.5 0.95350762  83.908671  88 0.8654860615 0.99508220
#> 24 24.5 0.94977310  80.730713  85 0.8708282569 0.99668585
#> 25 25.5 0.97622654  91.765295  94 0.9115229908 0.99905070
#> 26 26.5 0.94392302  85.896995  91 0.8681502083 0.99640880
#> 27 27.5 0.93055493  82.819389  89 0.8198035939 0.99294163
#> 28 28.5 0.96530578  73.363239  76 0.8824004970 0.99806516
#> 29 29.5 0.90942839  71.844843  79 0.8166192321 0.98031092
#> 30 30.5 0.92396246  51.741898  56 0.8018241060 0.99177343
#> 31 31.5 0.86450734  44.954381  52 0.7114398199 0.96150283
#> 32 32.5 0.95145521  45.669850  48 0.8244368835 0.99784321
#> 33 33.5 0.94939266  35.127529  37 0.7888680098 0.99823258
#> 34 34.5 0.95578440  39.187161  41 0.8334385481 0.99731726
#> 35 35.5 0.90579729  36.231892  40 0.7444533435 0.98825635
#> 36 36.5 0.96630732  36.719678  38 0.8613046445 0.99826479
#> 37 37.5 0.95021588  37.058419  39 0.8041305633 0.99763957
#> 38 38.5 0.90999106  37.309634  41 0.7442793553 0.99101392
#> 39 39.5 0.92804546  27.841364  30 0.7562417314 0.99399646
#> 40 40.5 0.95301930  25.731521  27 0.7920169109 0.99752857
#> 41 41.5 0.96465707  24.116427  25 0.8275253759 0.99916657
#> 42 42.5 0.93287433  20.523235  22 0.7639822308 0.99641675
#> 43 43.5 0.92531182  17.580925  19 0.7300474394 0.99597705
#> 44 44.5 0.95462715  17.183289  18 0.8014756977 0.99781240
#> 
#> $method
#> [1] "bayesian"
#>