serosvy_unknown_sample_posterior: Tidy output for Bayesian serological sampling functions for...

View source: R/bayesian_unknown_tidy.R

serosvy_unknown_sample_posteriorR Documentation

Tidy output for Bayesian serological sampling functions for one population and unknown test performance

Description

one population - unknown test performance - posterior distribution of prevalence. source here

Usage

serosvy_unknown_sample_posterior(
  positive_number_test,
  total_number_test,
  true_positive,
  true_negative,
  false_positive,
  false_negative
)

serosvy_unknown_sample_posterior_ii(
  positive_number_test,
  total_number_test,
  true_positive,
  true_negative,
  false_positive,
  false_negative
)

Arguments

positive_number_test

number of positive tests population

total_number_test

number of total tests in population

true_positive

true positive tests in the lab

true_negative

true negative tests in the lab

false_positive

false positive tests in the lab

false_negative

false negative tests in the lab

Value

tibble of prevalence posterior distribution

References

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

Examples


## 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)

result_unk_x <- serosvy_unknown_sample_posterior(
  positive_number_test = positive_pop[1],
  total_number_test = positive_pop[1]+negative_pop[1],
  true_positive = 670,
  true_negative = 640,
  false_positive = 202,
  false_negative = 74)

result_unk_x %>%
  unnest(summary)
# result_unk_x %>%
#   unnest(performance)

#result_unk_x %>%
#  unnest(posterior) %>%
#  as_tibble() %>%
#  rownames_to_column() %>%
#  select(-summary) %>%
#  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")


# ------------------------------------------------------

result_unk_x <- serosvy_unknown_sample_posterior_ii(
  positive_number_test = positive_pop[1],
  total_number_test = positive_pop[1]+negative_pop[1],
  true_positive = 670,
  true_negative = 640,
  false_positive = 202,
  false_negative = 74)

result_unk_x %>%
  unnest(summary)
result_unk_x %>%
  unnest(performance)

result_unk_x %>%
  select(posterior) %>%
  unnest(posterior) %>%
  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)


avallecam/serosurvey documentation built on Feb. 12, 2023, 4:13 p.m.