knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, collapse = TRUE) #, comment = "#>") knitr::opts_knit$set(root.dir = '../') options(knitr.table.format = function() { if (knitr::is_latex_output()) "latex" else "pandoc" }) # options(scipen=999)
library(serpico2)
knitr::read_chunk("R/run_model.R") run <- TRUE
We start by simulating a sample dataset using function simulate_mock_data
. By default it represents seropositivity measures in distinct individuals stratified by sex, age and region, and over 3 time periods. A baseline prevalence level is set for the second period and risks of infection are varied by period and individual covariates. Test positivity is a function of sensitivity and specificity. In this simulated example and for simplicity, response rate is considered fixed for now.
Sample looks like so:
rbind(head(d0), tail(d0))
And we can assess observed prevalence (test positivity) by categories
vars = c("time", "sex", "age", "reg") print( lapply(setNames(vars, vars), function(v){ round( tapply(d0[,"res"], d0[,v], mean), 3) }) )
We will also need poststratification population counts and region names (poststrat
and code_region
datasets). Following actual study input and results, we exclude one region (Mayotte).
Then, posteriors of regression parameters are estimated by MCMC
Next, post-stratified counts of positive in the population are calculated
Finally, results are summarized over iterations to estimate overall and stratified prevalence
knitr::kable(res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.