
Estimate Proportions for All Combinations of Grouping Variables (OGD Format) in Structural Survey
Source:R/se_ogd.R
se_prop_ogd.Rd
se_prop_ogd
estimates survey proportions for every combination of the supplied grouping variables,
using se_prop
internally and returning results in a format suitable for Open Government Data (OGD).
The output includes proportions for each combination of grouping variables, as well as for the overall population.
Arguments
- data
A data frame or tibble.
- ...
Grouping variables (unquoted or programmatic).
- strata
Stratification variable (unquoted or programmatic). Defaults to "zone" if omitted.
- weight
Sampling weights variable (unquoted or programmatic).
- alpha
Significance level for confidence intervals. Default is 0.05 (95% CI).
Value
A tibble with survey proportion estimates for all combinations of grouping variables. Grouping variables are converted to factors with "Total" representing the overall group.
Examples
# Unquoted variables
se_prop_ogd(nhanes, strata = strata, weight = weights, gender, birth_country)
#> # A tibble: 11 × 7
#> gender birth_country occ prop ci ci_l ci_u
#> <fct> <fct> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Total Total 9971 1 0 1 1
#> 2 Female Total 5079 0.512 0.0141 0.498 0.526
#> 3 Male Total 4892 0.488 0.0141 0.474 0.502
#> 4 Total Missing 2 0.0000938 0.000133 -0.0000390 0.000227
#> 5 Total Other 2236 0.151 0.00779 0.143 0.159
#> 6 Total US 7733 0.849 0.00779 0.841 0.857
#> 7 Female Missing 2 0.0000938 0.000133 -0.0000390 0.000227
#> 8 Female Other 1168 0.0756 0.00530 0.0703 0.0809
#> 9 Female US 3909 0.436 0.0141 0.422 0.450
#> 10 Male Other 1068 0.0755 0.00572 0.0698 0.0812
#> 11 Male US 3824 0.413 0.0141 0.399 0.427
# Programmatic use
wt <- "weights"
vars <- c("gender", "birth_country")
se_prop_ogd(nhanes, strata = strata, weight = !!rlang::sym(wt), !!!rlang::syms(vars))
#> # A tibble: 11 × 7
#> gender birth_country occ prop ci ci_l ci_u
#> <fct> <fct> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Total Total 9971 1 0 1 1
#> 2 Female Total 5079 0.512 0.0141 0.498 0.526
#> 3 Male Total 4892 0.488 0.0141 0.474 0.502
#> 4 Total Missing 2 0.0000938 0.000133 -0.0000390 0.000227
#> 5 Total Other 2236 0.151 0.00779 0.143 0.159
#> 6 Total US 7733 0.849 0.00779 0.841 0.857
#> 7 Female Missing 2 0.0000938 0.000133 -0.0000390 0.000227
#> 8 Female Other 1168 0.0756 0.00530 0.0703 0.0809
#> 9 Female US 3909 0.436 0.0141 0.422 0.450
#> 10 Male Other 1068 0.0755 0.00572 0.0698 0.0812
#> 11 Male US 3824 0.413 0.0141 0.399 0.427