Use of robust std errors in pooled regression & obtaining R^2 in R

15 Views Asked by At

I have a multiply imputed data and run a regression for each impID. Then I pool the results, to obtain one result for the analysis.

Now I wish to use robust standard errors and compare the pooled results. The only way to use robust standard errors (as far as I see) is via coeftest(). The function is applied to every single regression, giving me the error

The `exponentiate` argument is not supported in the `tidy()` method for `coeftest` objects and will be ignored

... which I ignored as I do not think that this error is important for the calculation. The results are pooled again.

Now, if I try to get R^2 from the pooled result of the robust-standarderror-Regressions, I get the following error:

Error in pool.r.squared(pooled_regs_rob_std) :

  r^2 can only be calculated for results of the 'lm' modeling function

Is there another, simplier and thus more comppatible way to apply robust std errors or at least a workaround to this error? Any help is appreciated!

Code with fake data:

library(sandwich)
library(mice)
library(mitools)

clientID <- c(4,4,4,4,4,6,6,6,6,6,7,7,7,7,7,15,15,15,15,15)
impID <- c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)
x <- c(1534500, 1572500, 1555500, 1571500, 1546500, 113000, 113000, 113000, 113000,113000, 4153101,4153101,4153101,4153101,4153101, 1042400, 1044400, 1092400, 1057400, 1051400)
y <- c(14200,14200,14200,14200,14200,160000,15000,14000,14200,4800,12000,14200,10500,14200,48000,150000,150000,150000,150000,150000)
z <- c(200, 200,200,200,200, 400,400,400,400,400,150,150,150,150,150,230,230,230,230,230)
data <- data.frame(clientID=clientID, impID = impID, x=x, y=y, z=z)

sp <- split(data, data$impID)
implist <- imputationList(sp)
regs <- with(implist, lm(x ~ y + z))

pooled_results <- pool(regs)
summary(pooled_results)

# Use of robust std errors on each regression
regs_rob_std$"1" <- coeftest(regs$"1", vcov = vcovHC(regs$"1", type="HC3"))
regs_rob_std$"2" <- coeftest(regs$"2", vcov = vcovHC(regs$"2", type="HC3"))
regs_rob_std$"3" <- coeftest(regs$"3", vcov = vcovHC(regs$"3", type="HC3"))
regs_rob_std$"4" <- coeftest(regs$"4", vcov = vcovHC(regs$"4", type="HC3"))
regs_rob_std$"5" <- coeftest(regs$"5", vcov = vcovHC(regs$"5", type="HC3"))

# Pool results of regressions with robust std
pooled_results_robust_std <- pool(regs_rob_std)

# Determine r2 of pooled result
pool.r.squared(pooled_regs_rob_std) #Error

I tried the showed code, but can't find any alternative to solve this problem.

0

There are 0 best solutions below