View source: R/rescale_coefficients.R
rescale_coefficients | R Documentation |
Predictor variables are often standardized to be included in statistical models and allow comparison of the effect sizes for different predictors. This functions scales the fitted models coefficients back to the original scale of the predictors, to allow ecological interpretation.
rescale_coefficients(...)
## S3 method for class 'coxph'
rescale_coefficients(model, data, ...)
## S3 method for class 'lm'
rescale_coefficients(model, data, ...)
## S3 method for class 'glm'
rescale_coefficients(model, data, ...)
## S3 method for class 'bag'
rescale_coefficients(bag, data, tostd = TRUE, ...)
model |
|
data |
|
bag |
|
standardize |
|
A vector of rescaled coefficients for the input model.
library(dplyr)
# standardize predictors
iris_std <- iris |>
dplyr::mutate(across(2:4, ~ scale(.x)))
# fit model
m1 <- lm(Sepal.Length ~ Petal.Length + Species, data = iris_std)
summary(m1)
# rescale coefficients
(resc_cf <- rescale_coefficients(m1, iris))
# compare with model with no standardization of predictors
coef(lm(Sepal.Length ~ Petal.Length + Species, data = iris))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.