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
if (FALSE) {
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")
}
Run the code above in your browser using DataLab