rescale_coefficients: Rescale standardized coefficients back to their original...

View source: R/rescale_coefficients.R

rescale_coefficientsR Documentation

Rescale standardized coefficients back to their original range after model fitting

Description

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.

Usage

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, ...)

Arguments

model


Fitted model, i.e. the object created by a model fit funtion such as "lm", "glm", or "coxph".

data


The original data.frame with the data used to fit the model.

bag


A bag of models, as result of the bag_models() function.

standardize

⁠[logical(1)=TRUE]⁠ If TRUE (Default), the coefficients are standardized. If FALSE, the coefficients are standardized. Only numeric coefficients are standardized.

Value

A vector of rescaled coefficients for the input model.

Examples

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))


NINAnor/oneimpact documentation built on June 14, 2025, 12:27 a.m.