
Estimate Means for All Combinations of Grouping Variables (OGD Format) in Structural Survey
Source:R/se_ogd.R
se_mean_ogd.Rd
se_mean_ogd
estimates survey means of a continuous variable for every combination of the supplied grouping variables,
using se_mean
internally and returning results in a format suitable for Open Government Data (OGD).
The output includes means for each combination of grouping variables, as well as for the overall population.
Arguments
- data
A data frame or tibble.
- variable
Variable to estimate the mean for (unquoted or programmatic).
- ...
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 mean estimates for all combinations of grouping variables. Grouping variables are converted to factors with "Total" representing the overall group.
Examples
# Unquoted variables
se_mean_ogd(nhanes, variable = household_size, strata = strata, weight = weights, gender)
#> # A tibble: 3 × 6
#> gender occ household_size ci ci_l ci_u
#> <fct> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Total 9971 3.46 0.0436 3.42 3.51
#> 2 Female 5079 3.44 0.0611 3.38 3.50
#> 3 Male 4892 3.49 0.0621 3.43 3.55
# Programmatic use
var <- "household_size"
wt <- "weights"
vars <- "gender"
se_mean_ogd(
nhanes,
variable = !!rlang::sym(var),
strata = strata,
weight = !!rlang::sym(wt),
!!!rlang::syms(vars)
)
#> # A tibble: 3 × 6
#> gender occ household_size ci ci_l ci_u
#> <fct> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Total 9971 3.46 0.0436 3.42 3.51
#> 2 Female 5079 3.44 0.0611 3.38 3.50
#> 3 Male 4892 3.49 0.0621 3.43 3.55