Helper Function for the Estimation of Stratified Quantiles
Source:R/estimate_proportion.R
strata_normal_quantile.RdThis function wraps the estimation of stratified percentiles when we assume the approximation for large numbers. This is necessary only in the case proportions for each strata are unequal.
Arguments
- vars
(
character)
variable names for the primary analysis variable to be iterated over.- weights
(
numericorNULL)
weights for each level of the strata. IfNULL, they are estimated using the iterative algorithm proposed in Yan and Su (2010) that minimizes the weighted squared length of the confidence interval.- conf_level
(
proportion)
confidence level of the interval.
Examples
strata_data <- table(data.frame(
"f1" = sample(c(TRUE, FALSE), 100, TRUE),
"f2" = sample(c("x", "y", "z"), 100, TRUE),
stringsAsFactors = TRUE
))
ns <- colSums(strata_data)
ests <- strata_data["TRUE", ] / ns
vars <- ests * (1 - ests) / ns
weights <- rep(1 / length(ns), length(ns))
strata_normal_quantile(vars, weights, 0.95)
#> [1] 1.131693