View source: R/bayesian_unknown.R
| sample_posterior_r_mcmc_testun | R Documentation |
one population - unknown test performance - posterior distribution of prevalence. source here
sample_posterior_r_mcmc_testun(samps, pos, n, tp, tn, fp, fn)
samps |
number of MCMC samples desired |
pos |
number of positive tests population |
n |
number of total tests in population |
tp |
true positive tests in the lab |
tn |
true negative tests in the lab |
fp |
false positive tests in the lab |
fn |
false negative tests in the lab |
Prevalence posterior distribution
sample_posterior_r_mcmc_testun: one population - unknown test performance - posterior distribution of prevalence. source here
Larremore, D. B., Fosdick, B. K., Zhang, S., & Grad, Y. H. (2020). Jointly modeling prevalence, sensitivity and specificity for optimal sample allocation. bioRxiv. doi: https://doi.org/10.1101/2020.05.23.112649
## Not run:
library(tidyverse)
library(skimr)
sensitivity = 0.93
specificity = 0.975
positive_pop <- c(321, 123, 100, 10)
negative_pop <- c(1234, 500, 375, 30)
positive_pop[1]/negative_pop[1]
posi <- c(2485713, 692)
total <- c(11609844, 3212)
nega <- total - posi
posi/total
posi/nega
nt <- 2
result_unk <- sample_posterior_r_mcmc_testun(samps = 10000,
#in population
pos = posi[nt], #positive_pop[1], #positive
# n = nega[nt], #negative_pop[1], #negatives
n = total[nt], #negative_pop[1], #negatives
# in lab
tp = 30,tn = 50,fp = 0,fn = 0
# tp = 670,tn = 640,fp = 202,fn = 74
)
# reproducible example YY
result_unk %>%
as_tibble() %>%
skim()
result_unk %>%
as_tibble() %>%
ggplot(aes(x = r)) +
geom_histogram(aes(y=..density..),binwidth = 0.005) +
geom_density()
result_unk %>%
as_tibble() %>%
rownames_to_column() %>%
pivot_longer(cols = -rowname,names_to = "estimates",values_to = "values") %>%
ggplot(aes(x = values)) +
geom_histogram(aes(y=..density..),binwidth = 0.005) +
geom_density() +
facet_grid(~estimates,scales = "free_x")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.