Skip to content

Instantly share code, notes, and snippets.

@dspm
Last active April 26, 2020 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dspm/3a87f18a1438badc573c99b200e1511e to your computer and use it in GitHub Desktop.
Save dspm/3a87f18a1438badc573c99b200e1511e to your computer and use it in GitHub Desktop.
library(tidyverse)
library(purrr)
set.seed(123)
nsim <- 10000
df <- data.frame(
num_cases = 2000,
prop_underreporting = rnorm(nsim, .3, .05),
prop_asymptomatic = rnorm(nsim, .6, .05)
)
fun <- function(num_cases, prop_underreporting, prop_asymptomatic){
num_symptomatic <- num_cases * (1/prop_underreporting)
num_positive <- num_symptomatic + (num_symptomatic * prop_asymptomatic)
return(num_positive)
}
df <- df %>% mutate(num_positive = pmap_dbl(df, fun))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment