Learn R Programming

misty (version 0.4.5)

center: Centering at the Grand Mean or Centering Within Cluster

Description

This function is used to center predictors at the grand mean (CGM, i.e., grand mean centering) or within cluster (CWC, i.e., group-mean centering).

Usage

center(x, type = c("CGM", "CWC"), cluster = NULL, value = NULL, as.na = NULL,
       check = TRUE)

Arguments

x

a numeric vector.

type

a character string indicating the type of centering, i.e., "CGM" for centering at the grand mean (i.e., grand mean centering) or "CWC" for centering within cluster (i.e., group-mean centering).

cluster

a vector representing the nested grouping structure (i.e., group or cluster variable) of each unit in x. Note, this argument is required for centering at the grand mean (CGM) of a level-2 predictor or centering within cluster (CWC) of a level-1 predictor.

value

a numeric value for centering on a specific user-defined value.

as.na

a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis. Note that as.na() function is only applied to x but not to cluster.

check

logical: if TRUE, argument specification is checked.

Value

Returns a numeric vector with the same length as x containing centered values.

Details

Predictors in a single-level regression can only be centered at the grand mean (CGM) by specifying type = "CGM" (default) in conjunction with cluster = NULL (default).

Level-1 (L1) predictors in a multilevel regression can be centered at the grand mean (CGM) by specifying type = "CGM" (default) in conjunction with cluster = NULL (default) or within cluster (CWC) by specifying type = "CWC" in conjunction with specifying a cluster membership variable using the cluster argument.

Level-2 (L2) predictors in a multilevel regression can only be centered at the grand mean (CGM) by specifying type = "CGM" (default) in conjunction with specifying a cluster membership variable using the cluster argument.

Note that predictors can be centered on any meaningful value using the argument value.

References

Enders, C. K. (2013). Centering predictors and contextual effects. In M. A. Scott, J. S. Simonoff, & B. D. Marx (Eds.), The Sage handbook of multilevel modeling (pp. 89-109). Sage. https://dx.doi.org/10.4135/9781446247600

Enders, C. K., & Tofighi, D. (2007). Centering predictor variables in cross-sectional multilevel models: A new look at an old issue. Psychological Methods, 12, 121-138. https://doi.org/10.1037/1082-989X.12.2.121

See Also

dummy.c, cluster.scores, rec, item.reverse, rwg.lindell, item.scores.

Examples

Run this code
# NOT RUN {
#--------------------------------------
# Predictors in a single-level regression
dat.sl <- data.frame(x = c(4, 2, 5, 6, 3, 4, 1, 3, 4),
                     y = c(5, 3, 6, 3, 4, 5, 2, 6, 5))

# Center predictor at the sample mean
center(dat.sl$x)

# Center predictor at the value 3
center(dat.sl$x, value = 3)

#--------------------------------------
# Predictors in a multilevel regression
dat.ml <- data.frame(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9),
                     cluster = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
                     x.l1 = c(4, 2, 5, 6, 3, 4, 1, 3, 4),
                     x.l2 = c(4, 4, 4, 1, 1, 1, 3, 3, 3),
                     y = c(5, 3, 6, 3, 4, 5, 2, 6, 5))

# Center level-1 predictor at the grand mean (CGM)
center(dat.ml$x.l1)

# Center level-1 predictor within cluster (CWC)
center(dat.ml$x.l1, type = "CWC", cluster = dat.ml$cluster)

# Center level-2 predictor at the grand mean (CGM)
center(dat.ml$x.l2, type = "CGM", cluster = dat.ml$cluster)
# }

Run the code above in your browser using DataLab