se_total()
estimates the totals and confidence intervals of FSO structural surveys.
Arguments
- data
A data frame or tibble.
- ...
Optional grouping variables. Can be passed unquoted (e.g.,
gender
,birth_country
) or programmatically using!!!syms(c("gender", "birth_country"))
.- strata
Unquoted or quoted name of the strata column. Defaults to
zone
if omitted.- weight
Unquoted or quoted name of the sampling weights column. For programmatic use with a string variable (e.g.,
wt <- "weights"
), use!!sym(wt)
in the function call.- alpha
Numeric significance level for confidence intervals. Default is 0.05 (95% CI).
Value
A tibble with total estimates for all grouping column combinations, including:
- <variable>
Value of the grouping variables passed in
...
.- occ
number of observations in survey sample.
- total
population estimate.
- vhat, stand_dev
Estimated variance of the total (
vhat
) and its standard deviation (stand_dev
, square root of the variance).- ci, ci_per, ci_l, ci_u
Confidence interval: half-width (
ci
), percentage of the total (ci_per
), lower (ci_l
) and upper (ci_u
) bounds.
Details
The condition
argument has been deprecated and is no longer supported.
Please use ...
to pass grouping variables either unquoted or programmatically using rlang
:
* Interactive use:
se_total(data, weight = my_weight, group1, group2)
* Programmatic use:
weight_var <- "my_weight"
group_vars <- c("group1", "group2")
se_total(data, weight = !!rlang::sym(weight_var), !!!rlang::syms(group_vars))
Examples
# One grouping variable
se_total(
data = nhanes,
strata = strata,
weight = weights,
gender
)
#> # A tibble: 2 × 9
#> gender occ total vhat stand_dev ci ci_per ci_l ci_u
#> <chr> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Female 5079 161922446. 7.82e12 2795884. 5479833. 3.38 156442613. 1.67e8
#> 2 Male 4892 154558598. 7.90e12 2810039. 5507576. 3.56 149051022. 1.60e8
# Multiple grouping variables
se_total(
data = nhanes,
strata = strata,
weight = weights,
gender, marital_status, birth_country
)
#> # A tibble: 33 × 11
#> gender marital_status birth_country occ total vhat stand_dev ci
#> <chr> <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Female Divorced Other 108 2.25e6 7.81e10 279466. 5.48e5
#> 2 Female Divorced US 260 1.16e7 8.98e11 947386. 1.86e6
#> 3 Female Don't Know US 1 5.94e4 3.53e 9 59381. 1.16e5
#> 4 Female Living with partn… Missing 1 1.17e4 1.37e 8 11709. 2.29e4
#> 5 Female Living with partn… Other 87 1.97e6 5.26e10 229323. 4.49e5
#> 6 Female Living with partn… US 183 8.95e6 6.52e11 807522. 1.58e6
#> 7 Female Married Other 562 1.22e7 3.56e11 596967. 1.17e6
#> 8 Female Married US 796 5.02e7 4.82e12 2196586. 4.31e6
#> 9 Female Missing Missing 1 1.80e4 3.23e 8 17984. 3.52e4
#> 10 Female Missing Other 137 1.97e6 3.52e10 187669. 3.68e5
#> # ℹ 23 more rows
#> # ℹ 3 more variables: ci_per <dbl>, ci_l <dbl>, ci_u <dbl>
# Programmatic use and quoted variables
v <- c("gender", "marital_status", "birth_country")
se_total(
nhanes,
weight = "weights",
strata = "strata",
!!!rlang::syms(v)
)
#> # A tibble: 33 × 11
#> gender marital_status birth_country occ total vhat stand_dev ci
#> <chr> <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Female Divorced Other 108 2.25e6 7.81e10 279466. 5.48e5
#> 2 Female Divorced US 260 1.16e7 8.98e11 947386. 1.86e6
#> 3 Female Don't Know US 1 5.94e4 3.53e 9 59381. 1.16e5
#> 4 Female Living with partn… Missing 1 1.17e4 1.37e 8 11709. 2.29e4
#> 5 Female Living with partn… Other 87 1.97e6 5.26e10 229323. 4.49e5
#> 6 Female Living with partn… US 183 8.95e6 6.52e11 807522. 1.58e6
#> 7 Female Married Other 562 1.22e7 3.56e11 596967. 1.17e6
#> 8 Female Married US 796 5.02e7 4.82e12 2196586. 4.31e6
#> 9 Female Missing Missing 1 1.80e4 3.23e 8 17984. 3.52e4
#> 10 Female Missing Other 137 1.97e6 3.52e10 187669. 3.68e5
#> # ℹ 23 more rows
#> # ℹ 3 more variables: ci_per <dbl>, ci_l <dbl>, ci_u <dbl>