pbreheny/visreg

Introduce a vcov= argument to allow using sandwich covariance and calculate robust standard errors

Opened this issue · 4 comments

Some models benefit from using heteroskedasticity and autocorrelation consistent covariance estimators (sandwich covariance estimators), giving model-robust standard error estimates. Could this be added to visreg? This could for instance be done by suggesting the package glm.predict and adding a vcov= or sigma= argument.

The design of visreg is to handle prediction in a completely object-oriented fashion. If a model fit is of class 'someClass', then predictions are handled via the predict.someClass() method. visreg itself contains no prediction code -- this is completely delegated to the model's predict method.

So, I can't see introducing a vcov argument, as this is extremely model-specific. However, you can always redirect the method to point to some other function:

predict.glm <- function(object) {
  # use whatever package you want here, with whatever variance-covariance matrix you want
}
visreg(fit, 'x')

This is perhaps sub-optimal in the sense that you'd be changing predict.glm() in the global environment. You can always redefine back to the original: predict.glm <- stats::predict.glm(), although perhaps visreg could accept a predict= argument where you can pass some user-defined function into visreg. I could see that being useful. Would that be useful in your use case?

I'll leave this open in the sense that it would be nicer to pass a custom predict() function than force the user to redefine their environment.