se_summarise()
is a helper function for se_total()
. It calculates survey-weighted group-level summaries by adding columns for the number
of observations and the estimated population size per group.
Arguments
- data
A data frame or tibble.
- ...
One or more grouping variables. Can be passed unquoted (e.g.,
gender
,birth_country
) or programmatically using!!!syms(c("gender", "birth_country"))
.- weight
The name of the weight column. Can be passed unquoted, quoted, or programmatically using
!!sym(wt)
wherewt
is a character variable.- mh_col
A character string specifying the name of the column for the number of observations (respondents) per group. Default is `"mh"`.
- Nh_col
A character string specifying the name of the column for the estimated population size per group. Default is `"Nh"`.
Value
A tibble containing the original data with two additional columns mh_col
and Nh_col
(or their specified names).
Examples
# One grouping variable
se_summarise(nhanes, weight = weights, strata)
#> # A tibble: 9,971 × 15
#> PSU weights strata gender age birth_country marital_status interview_lang
#> <dbl> <dbl> <dbl> <fct> <dbl> <fct> <fct> <fct>
#> 1 1 134671. 125 Male 62 US Married English
#> 2 1 24329. 125 Male 53 Other Divorced English
#> 3 1 12400. 131 Male 78 US Married English
#> 4 1 102718. 131 Female 56 US Living with p… English
#> 5 2 17628. 126 Female 42 US Divorced English
#> 6 1 11252. 128 Female 72 Other Separated Spanish
#> 7 1 9965. 120 Female 11 US Missing English
#> 8 2 44750. 124 Male 4 US Missing English
#> 9 1 9892. 119 Male 1 US Missing English
#> 10 2 37043. 128 Male 22 US Never married English
#> # ℹ 9,961 more rows
#> # ℹ 7 more variables: edu_level <fct>, household_size <dbl>, family_size <dbl>,
#> # annual_household_income <dbl>, annual_family_income <dbl>, mh <int>,
#> # Nh <dbl>
# Two grouping variables
se_summarise(nhanes,
weight = weights,
mh_col = "mhc",
Nh_col = "Nhc",
strata, gender
)
#> # A tibble: 9,971 × 15
#> PSU weights strata gender age birth_country marital_status interview_lang
#> <dbl> <dbl> <dbl> <fct> <dbl> <fct> <fct> <fct>
#> 1 1 134671. 125 Male 62 US Married English
#> 2 1 24329. 125 Male 53 Other Divorced English
#> 3 1 12400. 131 Male 78 US Married English
#> 4 1 102718. 131 Female 56 US Living with p… English
#> 5 2 17628. 126 Female 42 US Divorced English
#> 6 1 11252. 128 Female 72 Other Separated Spanish
#> 7 1 9965. 120 Female 11 US Missing English
#> 8 2 44750. 124 Male 4 US Missing English
#> 9 1 9892. 119 Male 1 US Missing English
#> 10 2 37043. 128 Male 22 US Never married English
#> # ℹ 9,961 more rows
#> # ℹ 7 more variables: edu_level <fct>, household_size <dbl>, family_size <dbl>,
#> # annual_household_income <dbl>, annual_family_income <dbl>, mhc <int>,
#> # Nhc <dbl>