std.coef: Standardized Coefficients

View source: R/std.coef.R

std.coefR Documentation

Standardized Coefficients

Description

This function computes standardized coefficients for linear models estimated by using the lm() function.

Usage

std.coef(model, print = c("all", "stdx", "stdy", "stdyx"), digits = 3, p.digits = 4,
         write = NULL, append = TRUE, check = TRUE, output = TRUE)

Arguments

model

a fitted model of class "lm".

print

a character vector indicating which results to show, i.e. "all", for all results, "stdx" for standardizing only the predictor, "stdy" for for standardizing only the criterion, and "stdyx" for for standardizing both the predictor and the criterion. Note that the default setting is depending on the level of measurement of the predictors, i.e., if all predictors are continuous, the default setting is print = "stdyx"; if all predictors are binary, the default setting is print = "stdy"; if predictors are continuous and binary, the default setting is print = c("stdy", "stdyx").

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 text file with file extension ".txt" (e.g., "Output.txt") for writing the output into a text file.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console.

Details

The slope \beta can be standardized with respect to only x, only y, or both y and x:

StdX(\beta_1) = \beta_1 SD(x)

StdX(\beta_1) standardizes with respect to x only and is interpreted as the change in y when x changes one standard deviation referred to as SD(x).

StdY(\beta_1) = \frac{\beta_1}{SD(x)}

StdY(\beta_1) standardizes with respect to y only and is interpreted as the change in y standard deviation units, referred to as SD(y), when x changes one unit.

StdYX(\beta_1) = \beta_1 \frac{SD(x)}{SD(y)}

StdYX(\beta_1) standardizes with respect to both y and x and is interpreted as the change in y standard deviation units when x changes one standard deviation.

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, Muthen, & Asparouhov, 2016).

The standardization of the slope \beta_3 in a regression model with an interaction term uses 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 (see Wen, Marsh & Hau, 2010). Likewise, the standardization of the slope \beta_3 in a polynomial regression model with a quadratic term uses 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.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

model

model specified in model

args

specification of function arguments

result

list with result tables, i.e., coef for the regression table including standardized coefficients and sd for the standard deviation of the outcome and predictor(s)

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

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

dat <- data.frame(x1 = c(3, 2, 4, 9, 5, 3, 6, 4, 5, 6, 3, 5),
                  x2 = c(1, 4, 3, 1, 2, 4, 3, 5, 1, 7, 8, 7),
                  x3 = c(0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1),
                  y = c(2, 7, 4, 4, 7, 8, 4, 2, 5, 1, 3, 8))

#-------------------------------------------------------------------------------
# Linear model

# Example 1: Regression model with continuous predictors
mod.lm1 <- lm(y ~ x1 + x2, data = dat)
std.coef(mod.lm1)

# Example 2: Print all standardized coefficients
std.coef(mod.lm1, print = "all")

# Example 3: Regression model with dichotomous predictor
mod.lm2 <- lm(y ~ x3, data = dat)
std.coef(mod.lm2)

# Example 4: Regression model with continuous and dichotomous predictors
mod.lm3 <- lm(y ~ x1 + x2 + x3, data = dat)
std.coef(mod.lm3)

# Example 5: Regression model with continuous predictors and an interaction term
mod.lm4 <- lm(y ~ x1*x2, data = dat)

# Example 6: Regression model with a quadratic term
mod.lm5 <- lm(y ~ x1 + I(x1^2), data = dat)
std.coef(mod.lm5)

#-------------------------------------------------------------------------------
# Example 7: Write Results into an Excel file

## Not run: 
mod.lm1 <- lm(y ~ x1 + x2, data = dat)

std.coef(mod.lm1, write = "Std_Coef.xlsx", output = FALSE)

result <- std.coef(mod.lm1, output = FALSE)
write.result(result, "Std_Coef.xlsx")

## End(Not run)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to std.coef in misty...