gforge / Greg

This R-package provides additional functions that help you convey regression models. It has also a few functions for handling robust confidence intervals for the ols() regression in the rms-package.
6 stars 3 forks source link

`robcov` or `robcovalt` on `lm` models? #4

Closed landroni closed 10 years ago

landroni commented 10 years ago

This is more of a query. Following http://stackoverflow.com/questions/8389843/clustered-standard-errors-r-panel-data/8390880#8390880 I discovered robcov in rms and then robcovalt in Greg. However it seems that both these functions work exclusively with ols models from rms, but NOT with lm models.

Are you aware of any function that allows clustering (like robcov does) but for lm models? (Before checking out Greg, I was hoping that robcovalt would extend robcov to lm models, but this doesn't seem to be the case.)

gforge commented 10 years ago

I'm not that sure of how to best implement the vcovHC seamlessly with the lm function. The vcov.lm is rather simple:

stats:::vcov.lm
function (object, ...) 
{
    so <- summary.lm(object)
    so$sigma^2 * so$cov.unscaled
}

Unfortunately the summary.lm is more complex, the rms-package has the variable object$var and therefore all you need to do is a switch of the var in order to make it work seamlessly with predict, contrast, and all the other neat rms functions. Just out of curiosity, what do you need from the lm that the ols doesn't have?

landroni commented 10 years ago

Hmm.. vcovHC by default works just fine with lm models. But I was hoping to go the opposite way: make robcov work with lm objects. Can the latter be done?

"Just out of curiosity, what do you need from the lm that the ols doesn't have?"

As much as I appreciate Frank's work and expertise, the ols function is somewhat non-standard (and I'm not very familiar with it). On the other hand lm is indeed the standard function for linear models. As such, for good or bad reasons, I'm naturally wary of using ols..

gforge commented 10 years ago

Unfortunately I'm not enough familiar with the inner workings of lm in order to adjust the covariance matrix. My best bet would be to implement a robcov function that adds the class robcov and then write your own version of the predict.lm, confint.lm, summary.lm... functions.

landroni commented 10 years ago

I see. Thanks a lot for the pointers.

landroni commented 10 years ago

BTW, out of curiosity, why do you prefer ols over lm?

gforge commented 10 years ago

I believe that the anova.rms and the contrast functions are killer functions. It is perhaps not that necessary for lm but the package contains cox regression and other regression functions where it is difficult to find a replacement.

I agree though that it would be nicer to use the standard functions, getting everything working is a monumental task, even for someone as experienced as Frank Harrell; I recently wanted to use the offset-term with the Glm-function and getting it to work seamlessly was overwhelming and I had to give up on using splines in that particular case :-(