简体   繁体   中英

How to obtain standardized regression coefficients for bootstrapped models or models with robust SE in R

In R, when we fit a regression model, standardized coefficients are unfortunately not readily available. Luckily, there is a package lm.beta that extracts them. For example:

fit.model1.lm <- lm(Sepal.Length ~ Sepal.Width + Petal.Width, iris)
lm.beta(fit.model1.lm)

However, if we use bootstrapping (eg from the package simpleboot ):

fit.model1.boot <- lm.boot(fit.model1.lm)

Or if we use robust standard errors (eg from the sandwich package):

coeftest(fit.model1.lm, vcov = vcovHC(fit.model1.lm))

It's impossible to obtain standardized coefficients via lm.beta since they only work on objects of class lm .

How to obtain them in that case then?

To get standardized coefficients we also may scale our variables before estimation:

library("lm.beta")
fit.model1.lm <- lm(Sepal.Length ~ Sepal.Width + Petal.Width, iris)
lm.beta(fit.model1.lm)
# Call:
#   lm(formula = Sepal.Length ~ Sepal.Width + Petal.Width, data = iris)
# 
# Standardized Coefficients::
# (Intercept) Sepal.Width Petal.Width 
#   0.0000000   0.2100575   0.8948486 
(fit.model1.lm.st <- lm(Sepal.Length ~ Sepal.Width + Petal.Width, 
                        cbind(lapply(iris[-5], scale), iris[5])))
# Call:
#   lm(formula = Sepal.Length ~ Sepal.Width + Petal.Width, data = cbind(lapply(iris[-5], 
#                                                                              scale), iris[5]))
# 
# Coefficients:
# (Intercept)  Sepal.Width  Petal.Width  
#  -1.422e-15    2.101e-01    8.948e-01  

So using the scale d lm fit (here fit.model1.lm.st ) in lm.boot will give you the desired standardized bootstrap coefficients.

library("simpleboot")
set.seed(42)  # for sake of reproducibility
(fit.model1.boot <- lm.boot(fit.model1.lm.st, R=200))
# BOOTSTRAP OF LINEAR MODEL  (method = rows)
# 
# Original Model Fit
# ------------------
# Call:
# lm(formula = Sepal.Length ~ Sepal.Width + Petal.Width, data = cbind(lapply(iris[-5], 
#                                                                              scale), iris[5]))
# 
# Coefficients:
# (Intercept)  Sepal.Width  Petal.Width  
#  -1.422e-15    2.101e-01    8.948e-01  

library(lmtest)
library(sandwich)
coeftest(fit.model1.lm.st, vcov=vcovHC(fit.model1.lm.st))
# t test of coefficients:
#   
#                Estimate  Std. Error t value  Pr(>|t|)    
# (Intercept) -1.4222e-15  4.4920e-02  0.0000         1    
# Sepal.Width  2.1006e-01  4.7055e-02  4.4641 1.591e-05 ***
# Petal.Width  8.9485e-01  5.2321e-02 17.1031 < 2.2e-16 ***
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM