center {mlmtools}R Documentation

Centers variables for mixed effects models

Description

Centers variables using the group-mean (person-mean) centering approach for mixed-effects models, and adds these variables to the data frame.

Usage

center(
  dataset,
  x,
  grouping,
  type = "mean",
  standardize = FALSE,
  centerResult = FALSE
)

Arguments

dataset

A dataset containing the variables to be centered and the grouping variable

x

The variable or variables to be centered

grouping

The variable or variables that define the grouping structure of the data

type

a function to compute the grouping summary variable

standardize

a logical value indicating whether x should be standardized before the computaion proceeds

centerResult

a logical value indicating whether resulting grouping summary variable values should be centered at 0

Value

Creates two new variables in the data frame - a mean of the desired variable computed for each unique value in the grouping variable and a deviation score for each observation within the grouping variable that is that observation's raw score subtracted from the group mean.

References

Enders, C. & Tofighi, D. (2007). Centering predictor variables in cross-sectional multilevel models: A new look at an old problem. Psychological Methods, 12(2), 121–138

Examples

data(instruction)
#Center student level socioeconomic status, "ses", around class mean "ses"
### To repress output: use invisible()
center(dataset = instruction, x = "ses", grouping = "classid")
#Center class-level variable teacher's mathematic prepartion,
# mathprep, around school mean "mathprep"
center(dataset = instruction, x = "mathprep", grouping = "schoolid")


[Package mlmtools version 1.0.2 Index]