
Estimate Totals and Proportions for All Combinations of Grouping Variables (OGD Format) in Structural Survey
Source:R/se_ogd.R
se_total_prop_ogd.Rd
se_total_prop_ogd
estimates totals and proportions for each combination
of grouping variables using se_total_prop
, returning results in a format compatible with Open Government Data (OGD) standards.
along with stratification and weighting.
Arguments
- data
A data frame or tibble containing the survey data.
- ...
Grouping variables (unquoted or programmatic) to compute combinations of totals and proportions.
- strata
Stratification variable (unquoted or programmatic). Defaults to
"zone"
if omitted.- weight
Sampling weight variable (unquoted or programmatic).
- alpha
Significance level for confidence intervals. Default is 0.05 (for 95% CI).
Value
A tibble with totals and proportions for all combinations of the specified grouping variables. The output includes confidence intervals and handles missing values by representing them as "Total".
Examples
# With unquoted variables
se_total_prop_ogd(nhanes, gender, birth_country, strata = strata, weight = weights)
#> # A tibble: 11 × 11
#> gender birth_country occ total ci_total ci_l_total ci_u_total prop
#> <fct> <fct> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Total Total 9971 316481044. 6370681. 310110363. 322851725. 1 e+0
#> 2 Female Total 5079 161922446. 5479833. 156442613. 167402279. 5.12e-1
#> 3 Male Total 4892 154558598. 5507576. 149051022. 160066174. 4.88e-1
#> 4 Total Missing 2 29693. 42060. -12367. 71753. 9.38e-5
#> 5 Total Other 2236 47811833. 2236143. 45575690. 50047977. 1.51e-1
#> 6 Total US 7733 268639517. 6668850. 261970667. 275308367. 8.49e-1
#> 7 Female Missing 2 29693. 42060. -12367. 71753. 9.38e-5
#> 8 Female Other 1168 23914531. 1584444. 22330087. 25498975. 7.56e-2
#> 9 Female US 3909 137978222. 5460390. 132517832. 143438611. 4.36e-1
#> 10 Male Other 1068 23897302. 1743278. 22154024. 25640580. 7.55e-2
#> 11 Male US 3824 130661296. 5426191. 125235105. 136087486. 4.13e-1
#> # ℹ 3 more variables: ci_prop <dbl>, ci_l_prop <dbl>, ci_u_prop <dbl>
# Programmatic usage
vars <- c("gender", "birth_country")
wt <- "weights"
se_total_prop_ogd(nhanes, !!!rlang::syms(vars), strata = strata, weight = !!rlang::sym(wt))
#> # A tibble: 11 × 11
#> gender birth_country occ total ci_total ci_l_total ci_u_total prop
#> <fct> <fct> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Total Total 9971 316481044. 6370681. 310110363. 322851725. 1 e+0
#> 2 Female Total 5079 161922446. 5479833. 156442613. 167402279. 5.12e-1
#> 3 Male Total 4892 154558598. 5507576. 149051022. 160066174. 4.88e-1
#> 4 Total Missing 2 29693. 42060. -12367. 71753. 9.38e-5
#> 5 Total Other 2236 47811833. 2236143. 45575690. 50047977. 1.51e-1
#> 6 Total US 7733 268639517. 6668850. 261970667. 275308367. 8.49e-1
#> 7 Female Missing 2 29693. 42060. -12367. 71753. 9.38e-5
#> 8 Female Other 1168 23914531. 1584444. 22330087. 25498975. 7.56e-2
#> 9 Female US 3909 137978222. 5460390. 132517832. 143438611. 4.36e-1
#> 10 Male Other 1068 23897302. 1743278. 22154024. 25640580. 7.55e-2
#> 11 Male US 3824 130661296. 5426191. 125235105. 136087486. 4.13e-1
#> # ℹ 3 more variables: ci_prop <dbl>, ci_l_prop <dbl>, ci_u_prop <dbl>