std.coef | R Documentation |
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.
std.coef(model, print = c("all", "stdx", "stdy", "stdyx"), digits = 3, p.digits = 3,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
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 |
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 individual i
, \beta_0
is the intercept, \beta_1
is the slope (aka regression coefficient),
x_i
is the predictor for individual i
, and \epsilon_i
is the
residual for individual i
.
The slope \beta_1
estimated by using the lm()
function can be
standardized with respect to only x
, only y
, or both y
and
x
:
StdX Standardization: StdX(\beta_1)
standardizes with respect to x
only and is interpreted as expected
difference in y
between individuals that differ one standard
deviation referred to as SD(x)
:
StdX(\beta_1) = \beta_1 SD(x)
StdY Standardization: StdY(\beta_1)
standardizes with respect to y
only and is interpreted as expected
difference in y
standard deviation units, referred to as SD(y)
,
between individuals that differ one unit in x
:
StdY(\beta_1) = \frac{\beta_1}{SD(x)}
StdYX Standardization: StdYX(\beta_1)
standardizes with respect to both y
and x
and is interpreted
as expected difference in y
standard deviation units between individuals
that differ one standard deviation in x
:
StdYX(\beta_1) = \beta_1 \frac{SD(x)}{SD(y)}
Note that the StdYX(\beta_1)
and the StdY(\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 the StdYX(\beta_1)
and the StdY(\beta_1)
standardizations whenever a binary vector, factor,
or character vector is specified for the predictor variable.
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 variable x_1x_2
.
The slope \beta_3
is standardized by using the product of standard
deviations SD(x_1)SD(x_2)
rather than the standard deviation of the
product SD(x_1 x_2)
for the interaction variable x_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
with x2
being binary, the product
SD(x_1)SD(x_3)
while excluding binary predictor x2
is used to
standardize the interaction term.
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 term x^2
.
The slope \beta_3
is standardized by using the product of standard
deviations SD(x)SD(x)
rather than the standard deviation of the product
SD(x x)
for the quadratic term x^2
.
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 individual i
in group j
,
\gamma_{00}
is the fixed-effect average intercept, \gamma_{10}
is the
fixed-effect average slope for the Level-1 predictor x
, and \gamma_{01}
is the fixed-effect slope for the Level-2 predictor z
.
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 the x
and y
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})
and SD(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}
and SD(y_{j})
is square root
of the Level-2 intercept variance \sigma^2_{u_0}
which are estimated in
a null model using the lmer
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.
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., |
Takuya Yanagida takuya.yanagida@univie.ac.at
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
#----------------------------------------------------------------------------
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.