leeper / prediction

Tidy, Type-Safe 'prediction()' Methods
https://cran.r-project.org/package=prediction
Other
89 stars 14 forks source link

`vcov` argument doesn't affect output #31

Open vincentarelbundock opened 5 years ago

vincentarelbundock commented 5 years ago

Please specify whether your issue is about:

I was trying to figure out why the confidence intervals didn't change in my margins ggplot2 branch when using predictions. So I just want to check here if there should be a difference in se.fitted between those two commands.

Thanks!

library(sandwich)                                                                                                                                                                                                                             
library(prediction)                                                                                                                                                                                                                            
mod <- lm(am ~ wt*drat, data = mtcars)         

head(prediction(mod, vcov = vcov(mod)))                                                                                                                                                                                                        
#>    mpg cyl disp  hp drat    wt  qsec vs am gear carb     fitted  se.fitted
#> 1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4 0.62380854 0.07567668
#> 2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4 0.56084776 0.08093441
#> 3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1 0.67453295 0.08344169
#> 4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1 0.17696915 0.10392980
#> 5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2 0.16609522 0.08536989
#> 6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1 0.03100386 0.13623569

head(prediction(mod, vcov = sandwich::vcovHC(mod)))    
#>    mpg cyl disp  hp drat    wt  qsec vs am gear carb     fitted  se.fitted
#> 1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4 0.62380854 0.07567668
#> 2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4 0.56084776 0.08093441
#> 3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1 0.67453295 0.08344169
#> 4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1 0.17696915 0.10392980
#> 5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2 0.16609522 0.08536989
#> 6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1 0.03100386 0.13623569

Created on 2019-03-09 by the reprex package (v0.2.1)

leeper commented 4 years ago

Note for myself: this is because the se.fit column is taken directly from predict.lm() but there's no way to pass a custom vcov value to that function.