Skip to contents

mzmv_mean_map() estimates weighted means and confidence intervals for a set of features of the mobility survey, optionally grouped by one or more variables.

Usage

mzmv_mean_map(data, variable, ..., weight, cf = 1.14, alpha = 0.1)

Arguments

data

A data frame or tibble.

variable

Character vector of variable names to be estimated. Must be quoted (e.g., "annual_family_income"). For multiple variables, pass as a vector (e.g., c("annual_family_income", "annual_household_income")). Does not support bare (unquoted) variable names.

...

Grouping variables. Can be passed unquoted (e.g., gender, birth_country) or quoted (e.g., "gender", "birth_country"). If omitted, results are aggregated across the whole dataset.

weight

Unquoted or quoted name of the sampling weights column (must exist in data). For programmatic use with a string variable (e.g., wt <- "weights"), use !!sym(wt) in the function call.

cf

Numeric correction factor for the confidence interval. Default is 1.14.

alpha

Numeric significance level for confidence intervals. Default is 0.1 (90% CI).

Value

A tibble with columns:

variable

Name of the estimated variable.

group_vars

Name of the grouping variable.

group_vars_value

Value of the grouping variable.

occ

Number of cases or observations.

wmean

Weighted mean.

ci

Confidence interval.

Examples

# Multiple quoted variables
mzmv_mean_map(
  nhanes,
  variable = c("annual_family_income", "annual_household_income"),
  gender,
  birth_country,
  weight = weights
)
#> # A tibble: 10 × 6
#>    variable                group_vars    group_vars_value   occ wmean     ci
#>    <chr>                   <chr>         <fct>            <int> <dbl>  <dbl>
#>  1 annual_family_income    gender        Female            4917  11.5  0.358
#>  2 annual_family_income    gender        Male              4725  11.6  0.334
#>  3 annual_family_income    birth_country US                7517  11.3  0.251
#>  4 annual_family_income    birth_country Other             2123  12.8  0.744
#>  5 annual_family_income    birth_country Missing              2  47.8 48.0  
#>  6 annual_household_income gender        Female            4906  11.8  0.350
#>  7 annual_household_income gender        Male              4720  12.0  0.328
#>  8 annual_household_income birth_country US                7504  11.6  0.243
#>  9 annual_household_income birth_country Other             2120  13.3  0.747
#> 10 annual_household_income birth_country Missing              2  47.8 48.0  
# No grouping variables
mzmv_mean_map(
  nhanes,
  variable = "annual_family_income",
  weight = weights
)
#> # A tibble: 1 × 6
#>   variable             group_vars   group_vars_value   occ wmean    ci
#>   <chr>                <chr>        <chr>            <int> <dbl> <dbl>
#> 1 annual_family_income .dummy_group all               9642  11.5 0.245
# Programmatic use
wt <- "weights"
mzmv_mean_map(
  nhanes,
  variable = "annual_family_income",
  gender,
  birth_country,
  weight = !!rlang::sym(wt)
)
#> # A tibble: 5 × 6
#>   variable             group_vars    group_vars_value   occ wmean     ci
#>   <chr>                <chr>         <fct>            <int> <dbl>  <dbl>
#> 1 annual_family_income gender        Female            4917  11.5  0.358
#> 2 annual_family_income gender        Male              4725  11.6  0.334
#> 3 annual_family_income birth_country US                7517  11.3  0.251
#> 4 annual_family_income birth_country Other             2123  12.8  0.744
#> 5 annual_family_income birth_country Missing              2  47.8 48.0