This is a specialized function for mean centering categorical variables. There are two cases where this function should be used instead of the generic `center_mlm`. 1. This function should be used when you need group mean centering for non-dummy-coded variables at L1. Variables at L2 are always dummy-coded as they represent the percentage of subjects in that group. 2. This function should be used whenever you want to z-score the aggregated L2 means

z_scored_mlm_categorical(
  data,
  cols,
  dummy_coded = NA,
  group,
  keep_original = TRUE
)

Arguments

data

A data.frame or a data.frame extension (e.g. a tibble).

cols

Dummy-coded or effect-coded columns for group-mean centering. Support `dplyr::dplyr_tidy_select` options.

dummy_coded

Dummy-coded variables (cannot be effect-coded) for L2 aggregated means. Support `dplyr::dplyr_tidy_select` options.

group

the grouping variable. Must be character

keep_original

default is `FALSE`. Set to `TRUE` to keep original columns

Value

An object of the same type as .data. The output has the following properties: 1. Columns from .data will be preserved 2. Columns with L1 scores that are group-mean centered 3. Columns with L2 aggregated means (i.e., percentage) that are z-scored

Examples

z_scored_mlm_categorical(mlbook_data,cols='female_eff',dummy_coded='female_dum','schoolnr')
#> # A tibble: 3,758 × 19
#>    schoolnr pupilNR_new langPOST    ses IQ_verb   sex Minority denomina
#>       <int>       <int>    <int>  <dbl>   <dbl> <int>    <int>    <int>
#>  1        1           3       46  -4.73    3.13     0        0        1
#>  2        1           4       45 -17.7     2.63     0        1        1
#>  3        1           5       33 -12.7    -2.37     0        0        1
#>  4        1           6       46  -4.73   -0.87     0        0        1
#>  5        1           7       20 -17.7    -3.87     0        0        1
#>  6        1           8       30 -17.7    -2.37     0        1        1
#>  7        1           9       30  -4.73   -2.37     0        1        1
#>  8        1          10       57 -17.7     1.13     0        0        1
#>  9        1          11       36 -14.7    -2.37     0        1        1
#> 10        1          12       36 -12.7    -0.87     0        1        1
#> # ℹ 3,748 more rows
#> # ℹ 11 more variables: female_dum <int>, female_eff <int>, female_CMC <dbl>,
#> #   fempct_agg <dbl>, Zfempct_agg <dbl>, ses_CMC <dbl>, Zses_CMC <dbl>,
#> #   ses_agg <dbl>, Zses_agg <dbl>, female_eff_group_c <dbl>,
#> #   female_dum_mean_z <dbl>