# Stratified Wilson confidence interval with unequal probabilities
set.seed(1)
rsp <- sample(c(TRUE, FALSE), 100, TRUE)
strata_data <- data.frame(
x = sample(c(TRUE, FALSE), 100, TRUE),
"f1" = sample(c("a", "b"), 100, TRUE),
"f2" = sample(c("x", "y", "z"), 100, TRUE),
stringsAsFactors = TRUE
)
strata <- interaction(strata_data)
n_strata <- ncol(table(rsp, strata)) # Number of strata
ci_prop_wilson_strata(
x = rsp, strata = strata,
conf.level = 0.90
)
# Not automatic setting of weights
ci_prop_wilson_strata(
x = rsp, strata = strata,
weights = rep(1 / n_strata, n_strata),
conf.level = 0.90
)
Run the code above in your browser using DataLab