| mlm_center | R Documentation |
Performs grand-mean centering, group-mean centering, or both (within-between decomposition) on one or more variables in a data frame. Group-mean centering is the standard preparation for cross-level interaction models.
mlm_center(
data,
vars,
cluster = NULL,
type = c("grand", "group", "both"),
suffix_within = "_within",
suffix_between = "_between"
)
data |
A data frame. |
vars |
Character vector of variable names to center. |
cluster |
Character scalar: name of the clustering variable (required
when |
type |
One of
|
suffix_within |
Suffix appended to within-centered variable names when
|
suffix_between |
Suffix appended to between (cluster mean) variable
names when |
The input data frame with new centered columns appended. Original columns are not modified.
data(school_data)
# Grand-mean center SES
d1 <- mlm_center(school_data, vars = "ses", type = "grand")
head(d1[, c("ses", "ses_c")])
# Group-mean center SES within schools
d2 <- mlm_center(school_data, vars = "ses", cluster = "school", type = "group")
head(d2[, c("ses", "ses_c")])
# Within-between decomposition
d3 <- mlm_center(school_data, vars = "ses", cluster = "school", type = "both")
head(d3[, c("ses", "ses_within", "ses_between")])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.