Learn R Programming

jtools (version 0.5.0)

center_lm: Center variables in fitted regression models

Description

center_lm() takes fitted regression models and mean-centers the continuous variables in the model to aid interpretation, especially in the case of models with interactions.

Usage

center_lm(model, binary.inputs = "0/1", center.response = FALSE)

Arguments

model

A regression model of type lm, glm, or svyglm. It should contain the interaction(s) of interest, if any.

binary.inputs

Options for binary variables. Default is 0/1; 0/1 keeps original scale; -0.5,0.5 rescales 0 as -0.5 and 1 as 0.5; center subtracts the mean; and full treats them like other continuous variables.

center.response

Should the response variable also be centered? Default is FALSE.

Value

The functions returns a lm or glm object, inheriting from whichever class was supplied.

Details

This function will mean-center all continuous variables in a regression model for ease of interpretation, especially for those models that have interaction terms. The mean for svyglm objects is calculated using svymean, so reflects the survey-weighted mean. The weight variables in svyglm are not centered, nor are they in other lm family models.

This function re-estimates the model, so for large models one should expect a runtime equal to the first run.

References

Bauer, D. J., & Curran, P. J. (2005). Probing interactions in fixed and multilevel regression: Inferential and graphical techniques. Multivariate Behavioral Research, 40(3), 373-400.

Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analyses for the behavioral sciences (3rd ed.). Mahwah, NJ: Lawrence Erlbaum Associates, Inc.

See Also

sim_slopes performs a simple slopes analysis.

interact_plot creates attractive, user-configurable plots of interaction models.

Other standardization, scaling, and centering tools: gscale, scale_lm

Examples

Run this code
# NOT RUN {
fit <- lm(formula = Murder ~ Income * Illiteracy, data = as.data.frame(state.x77))
fit_center <- center_lm(fit)

# With weights
fitw <- lm(formula = Murder ~ Income * Illiteracy,
           data = as.data.frame(state.x77),
           weights = Population)
fitw_center <- center_lm(fitw)

# With svyglm
library(survey)
data(api)
dstrat <- svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
regmodel <- svyglm(api00~ell*meals,design=dstrat)
regmodel_center <- center_lm(regmodel)

# }

Run the code above in your browser using DataLab