std.coef {misty} | R Documentation |
Standardized Coefficients for Linear, Multilevel and Mixed-Effects Models
Description
This function computes standardized coefficients for linear models estimated
by using the lm()
function and for multilevel and linear mixed-effects
models estimated by using the lmer()
or lme()
function from the
lme4 or nlme package.
Usage
std.coef(model, print = c("all", "stdx", "stdy", "stdyx"), digits = 3, p.digits = 3,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
Arguments
model |
a fitted model of class |
print |
a character vector indicating which results to show, i.e. |
digits |
an integer value indicating the number of decimal places to be used for displaying results. |
p.digits |
an integer value indicating the number of decimal places to be used for displaying the p-value. |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
Details
- Linear Regression Model
The linear regression model is expressed as follows:
y_i = \beta_0 + \beta_1x_i + \epsilon_i
where
y_i
is the outcome variable for individuali
,\beta_0
is the intercept,\beta_1
is the slope (aka regression coefficient),x_i
is the predictor for individuali
, and\epsilon_i
is the residual for individuali
.The slope
\beta_1
estimated by using thelm()
function can be standardized with respect to onlyx
, onlyy
, or bothy
andx
:StdX Standardization:
StdX(\beta_1)
standardizes with respect tox
only and is interpreted as expected difference iny
between individuals that differ one standard deviation referred to asSD(x)
:StdX(\beta_1) = \beta_1 SD(x)
StdY Standardization:
StdY(\beta_1)
standardizes with respect toy
only and is interpreted as expected difference iny
standard deviation units, referred to asSD(y)
, between individuals that differ one unit inx
:StdY(\beta_1) = \frac{\beta_1}{SD(x)}
StdYX Standardization:
StdYX(\beta_1)
standardizes with respect to bothy
andx
and is interpreted as expected difference iny
standard deviation units between individuals that differ one standard deviation inx
:StdYX(\beta_1) = \beta_1 \frac{SD(x)}{SD(y)}
Note that the
StdYX(\beta_1)
and theStdY(\beta_1)
standardizations are not suitable for the slope of a binary predictor because a one standard deviation change in a binary variable is generally not of interest (Muthen et al, 2016). Accordingly, the function does not provide theStdYX(\beta_1)
and theStdY(\beta_1)
standardizations whenever a binary vector, factor, or character vector is specified for the predictor variable.- Moderated Regression Model
The moderated regression model is expressed as follows:
y_i = \beta_0 + \beta_1x_{1i} + \beta_2x_{2i} + \beta_3x_{1i}x_{2i} + \epsilon_i
where
\beta_3
is the slope for the interaction variablex_1x_2
.The slope
\beta_3
is standardized by using the product of standard deviationsSD(x_1)SD(x_2)
rather than the standard deviation of the productSD(x_1 x_2)
for the interaction variablex_1x_2
as discussed in Wen et al. (2010).Note that the function does not use binary variables in the interaction term in standardizing the interaction variable. For example, when standardizing the interaction term
x1:x2:x3
withx2
being binary, the productSD(x_1)SD(x_3)
while excluding binary predictorx2
is used to standardize the interaction term.- Polynomial Regression Model
The polynomial regression model is expressed as follows:
y_i = \beta_0 + \beta_1x_{i} + \beta_2x^2_{i} + \epsilon_i
where
\beta_2
is the slope for the quadratic termx^2
.The slope
\beta_3
is standardized by using the product of standard deviationsSD(x)SD(x)
rather than the standard deviation of the productSD(x x)
for the quadratic termx^2
.- Multilevel and Mixed-Effects Model
The random intercept and slope model in the multiple-equation notation is expressed as follows:
Level 1:
y_{ij} = \beta_{0j} + \beta_{1j}x_{ij} + r_{ij}
Level 2:
\beta_{0j} = \gamma_{00} + \gamma_{01}z_{j} + u_{0j}
\beta_{1j} = \gamma_{10} + u_{1j}
The model expressed in the single-equation notation is as follows:
y_{ij} = \gamma_{00} + \gamma_{10}x_{ij} + \gamma_{01}z_{j} + u_{0j} + u_{1j}x_{ij} + r_{ij}
where
y_{ij}
is the outcome variable for individuali
in groupj
,\gamma_{00}
is the fixed-effect average intercept,\gamma_{10}
is the fixed-effect average slope for the Level-1 predictorx
, and\gamma_{01}
is the fixed-effect slope for the Level-2 predictorz
.The slopes
\gamma_{10}
and\gamma_{01}
are standardized according to the within- and between-group or within-and between-person standard deviations, i.e., slopes are standardizes with respect to thex
andy
standard deviation relevant for the level of the fixed effect of interest. The resulting standardized slopes are called pseudo-standardized coefficients (Hoffman 2015, p. 342). The StdYX Standardization for\gamma_{10}
and\gamma_{10}
is expressed as follows:Level-1 Predictor:
StdYX(\gamma_{10}) = \gamma_{10} \frac{SD(x_{ij})}{SD(y_{ij})}
Level-2 Predictor:
StdYX(\gamma_{01}) = \gamma_{01} \frac{SD(x_{j})}{SD(y_{j})}
where
SD(x_{ij})
andSD(x_{j})
are the standard deviations of the predictors at each analytic level,SD(y_{ij})
is the square root of the Level-1 residual variance\sigma^2_{r}
andSD(y_{j})
is square root of the Level-2 intercept variance\sigma^2_{u_0}
which are estimated in a null model using thelmer
function in the lme4 package using the restricted maximum likelihood estimation method.The function uses the square root of the Level-1 residual variance
\sigma^2_{r}
to standardize the slope of the cross-level interaction though it should be noted that it is unclear whether this is the correct approach to standardize the slope of the cross-level interaction.
Value
Returns an object of class misty.object
, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
data frame with variables used in the analysis |
model |
model specified in |
args |
specification of function arguments |
result |
list with result tables, i.e., |
Author(s)
Takuya Yanagida takuya.yanagida@univie.ac.at
References
Hoffman, L. (2015). Longitudinal Analysis: Modeling Within-Person Fluctuation and Change. Routledge.
Muthen, B. O., Muthen, L. K., & Asparouhov, T. (2016). Regression and mediation analysis using Mplus. Muthen & Muthen.
Wen, Z., Marsh, H. W., & Hau, K.-T. (2010). Structural equation models of latent interactions: An appropriate standardized solution and its scale-free properties. Structural Equation Modeling: A Multidisciplinary Journal, 17, 1-22. https://doi.org/10.1080/10705510903438872
Examples
#----------------------------------------------------------------------------
# Linear Model
# Example 1a: Continuous predictors
mod.lm1 <- lm(mpg ~ cyl + disp, data = mtcars)
std.coef(mod.lm1)
# Example 1b: Print all standardized coefficients
std.coef(mod.lm1, print = "all")
# Example 1c: Binary predictor
mod.lm2 <- lm(mpg ~ vs, data = mtcars)
std.coef(mod.lm2)
# Example 1d: Continuous and binary predictors
mod.lm3 <- lm(mpg ~ disp + vs, data = mtcars)
std.coef(mod.lm3)
# Example 1e: Continuous predictors with interaction term
mod.lm4 <- lm(mpg ~ cyl*disp, data = mtcars)
std.coef(mod.lm4)
# Example 1f: Continuous and binary predictor with interaction term
mod.lm5 <- lm(mpg ~ cyl*vs, data = mtcars)
std.coef(mod.lm5)
# Example 1g: Continuous predictor with a quadratic term
mod.lm6 <- lm(mpg ~ cyl + I(cyl^2), data = mtcars)
std.coef(mod.lm6)
## Not run:
#----------------------------------------------------------------------------
# Multilevel and Linear Mixed-Effects Model
# Load lme4, nlme, and ggplot2 package
misty::libraries(lme4, nlme)
# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")
# Cluster mean centering, center() from the misty package
Demo.twolevel <- center(Demo.twolevel, x2, type = "CWC", cluster = "cluster")
# Grand mean centering, center() from the misty package
Demo.twolevel <- center(Demo.twolevel, w1, type = "CGM", cluster = "cluster")
# Estimate models using the lme4 package
mod1a <- lmer(y1 ~ x2.c + w1.c + (1 + x2.c | cluster), data = Demo.twolevel,
REML = FALSE)
mod2a <- lmer(y1 ~ x2.c + w1.c + x2.c:w1.c + (1 + x2.c | cluster),
data = Demo.twolevel, REML = FALSE)
# Estimate models using the nlme package
mod1b <- lme(y1 ~ x2.c + w1.c, random = ~ 1 + x2.c | cluster, data = Demo.twolevel,
method = "ML")
mod2b <- lme(y1 ~ x2.c + w1.c + x2.c:w1.c, random = ~ 1 + x2.c | cluster,
data = Demo.twolevel, method = "ML")
# Example 2: Continuous predictors
std.coef(mod1a)
std.coef(mod1b)
# Example 2: Continuous predictors with cross-level interaction
std.coef(mod2a)
std.coef(mod2b)
#----------------------------------------------------------------------------
# Example 3: Write Results into a text or Excel file
# Example 3a: Text file
std.coef(mod.lm1, write = "Std_Coef.txt", output = FALSE, check = FALSE)
# Example 3b: Excel file
std.coef(mod.lm1, write = "Std_Coef.xlsx", output = FALSE, check = FALSE)
## End(Not run)