Skip to contents

se_total_ogd estimates survey totals for every combination of the supplied grouping variables, using se_total internally and returning results in a format suitable for Open Government Data (OGD). The output includes totals for each combination of grouping variables, as well as for the overall population.

Usage

se_total_ogd(data, ..., strata, weight, alpha = 0.05)

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 estimates for all combinations of grouping variables. Grouping variables are converted to factors with "Total" representing the overall group.

Examples

# Unquoted variables
se_total_ogd(nhanes, strata = strata, weight = weights, gender, birth_country)
#> # A tibble: 11 × 7
#>    gender birth_country   occ      total       ci       ci_l       ci_u
#>    <fct>  <fct>         <int>      <dbl>    <dbl>      <dbl>      <dbl>
#>  1 Total  Total          9971 316481044. 6370681. 310110363. 322851725.
#>  2 Female Total          5079 161922446. 5479833. 156442613. 167402279.
#>  3 Male   Total          4892 154558598. 5507576. 149051022. 160066174.
#>  4 Total  Missing           2     29693.   42060.    -12367.     71753.
#>  5 Total  Other          2236  47811833. 2236143.  45575690.  50047977.
#>  6 Total  US             7733 268639517. 6668850. 261970667. 275308367.
#>  7 Female Missing           2     29693.   42060.    -12367.     71753.
#>  8 Female Other          1168  23914531. 1584444.  22330087.  25498975.
#>  9 Female US             3909 137978222. 5460390. 132517832. 143438611.
#> 10 Male   Other          1068  23897302. 1743278.  22154024.  25640580.
#> 11 Male   US             3824 130661296. 5426191. 125235105. 136087486.

# Programmatic use
wt <- "weights"
vars <- c("gender", "birth_country")
se_total_ogd(nhanes, strata = strata, weight = !!rlang::sym(wt), !!!rlang::syms(vars))
#> # A tibble: 11 × 7
#>    gender birth_country   occ      total       ci       ci_l       ci_u
#>    <fct>  <fct>         <int>      <dbl>    <dbl>      <dbl>      <dbl>
#>  1 Total  Total          9971 316481044. 6370681. 310110363. 322851725.
#>  2 Female Total          5079 161922446. 5479833. 156442613. 167402279.
#>  3 Male   Total          4892 154558598. 5507576. 149051022. 160066174.
#>  4 Total  Missing           2     29693.   42060.    -12367.     71753.
#>  5 Total  Other          2236  47811833. 2236143.  45575690.  50047977.
#>  6 Total  US             7733 268639517. 6668850. 261970667. 275308367.
#>  7 Female Missing           2     29693.   42060.    -12367.     71753.
#>  8 Female Other          1168  23914531. 1584444.  22330087.  25498975.
#>  9 Female US             3909 137978222. 5460390. 132517832. 143438611.
#> 10 Male   Other          1068  23897302. 1743278.  22154024.  25640580.
#> 11 Male   US             3824 130661296. 5426191. 125235105. 136087486.