Last active
December 31, 2020 18:26
-
-
Save statwonk/a87ff335f7d6021cfc5fd937b63c6a8b to your computer and use it in GitHub Desktop.
Using beta-distributed interval-censored data to produce an estimate for the median share of US adults having taken the vaccine by end of Q2 2021.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(fitdistrplus) | |
dplyr::select -> select | |
.Machine$double.eps -> eps | |
1975 -> N # number of responses | |
tibble(lower = c(0, 0.25, 0.5, 0.75), # lower bins | |
upper = c(0.25 + eps, 0.5 + eps, 0.75 + eps, 1), # upper bins | |
pct = c(0.32, 0.51, 0.15, 1 - sum(0.32, 0.51, 0.15)), # response shares | |
n = floor(pct * N)) %>% # implied responses + eps | |
mutate(data = pmap(list(lower, upper, n), function(...) { | |
dots <- list(...) | |
sample_n(tibble(left = dots[[1]], right = dots[[2]]), size = dots[[3]], replace = TRUE) | |
})) %>% | |
select(data) %>% unnest(cols = c(data)) %>% as.data.frame() %>% | |
# use the quantile function to find the % at which half of chance is on either side (the median). | |
fitdistcens("beta") %>% # this is interval-censored beta data | |
coef() %>% | |
{ qbeta(0.5, .[[1]], .[[2]]) } | |
0.3279981 | |
# folks believe a third of US adults will have taken the vaccine by the end of Q2 2021 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment