Learn R Programming

jtools (version 0.7.3)

scale_lm: Scale variables in fitted regression models

Description

scale_lm() takes fitted regression models and scales all predictors by dividing each by 1 or 2 standard deviations (as chosen by the user).

Usage

scale_lm(model, binary.inputs = "0/1", n.sd = 1, center = TRUE,
  scale.response = TRUE)

Arguments

model

A regression model of type lm, glm, or svyglm.

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.

n.sd

How many standard deviations should you divide by for standardization? Default is 1, though some prefer 2.

center

Default is TRUE. If TRUE, the predictors are also mean-centered. For binary predictors, the binary.inputs argument supersedes this one.

scale.response

Should the response variable also be rescaled? Default is TRUE.

Value

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

Details

This function will scale all continuous variables in a regression model for ease of interpretation, especially for those models that have interaction terms. It can also mean-center all of them as well, if requested.

The scaling happens on the input data, not the terms themselves. That means interaction terms are still properly calculated because they are the product of standardized predictors, not a standardized product of predictors.

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: center_lm, gscale

Examples

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

# With weights
fitw <- lm(formula = Murder ~ Income * Illiteracy,
           data = as.data.frame(state.x77),
           weights = Population)
fitw_scale <- scale_lm(fitw)
fitw_scale <- scale_lm(fitw, center = TRUE, binary.input = "0/1")

# 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_scale <- scale_lm(regmodel)
regmodel_scale <- scale_lm(regmodel, binary.input = "0/1")

# }

Run the code above in your browser using DataLab