Learn R Programming

psycCleaning (version 0.1.1)

z_scored_mlm_categorical: Z-scored for multilevel analyses

Description

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

Usage

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

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

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

Examples

Run this code
z_scored_mlm_categorical(mlbook_data,cols='female_eff',dummy_coded='female_dum','schoolnr')

Run the code above in your browser using DataLab