lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
377 stars 59 forks source link

Add stats method df.residuals #455

Closed rferrali closed 7 months ago

rferrali commented 10 months ago

More of a feature request than a bug report. It'd be great if you could add a df.residual method, so the package gains compatibility with linearHypothesis from the car package. That way, it becomes easy to test linear hypotheses with F-tests, along the lines of what was requested in this issue. I rewrite the method for all my projects. I wish I could just contribute it directly in your codebase, but am not great with GitHub. So instead, I just pasted the method below. Hope this helps.

df.residual.fixest <- function(object, ...) {
    object$nobs - object$nparams
}
grantmcdermott commented 10 months ago

Are you looking for something other than https://lrberge.github.io/fixest/reference/degrees_freedom.html?

As an aside, I'd personally recommend the marginaleffects package over car nowadays. It has fewer dependencies, offers more functionality, and covers a wider array of model classes (fixest included). Example: https://marginaleffects.com/vignettes/hypothesis/

rferrali commented 10 months ago

Thanks @grantmcdermott for pointing me to both fixest::degrees_freedom and marginaleffects! I guess I should've checked the man more carefully.

Looks like marginaleffects has changed a lot since the last time I checked. I'm more than happy to move away from car, for all the reasons you mention.

Even though this is now less relevant, it can't hurt to connect the functions implemented in fixest to standard R methods. Perhaps @lrberge could add the following to a future release?

df.residual.fixest <- function(object, ...) {
fixest::degrees_freedom(x = object, type = "resid", ...)
}
lrberge commented 10 months ago

Somehow df.residuals was out of my radar. That's a very good suggestion @rferrali!

One issue though is that DoF is a tricky topic and maybe I should use degrees_freedom_iid (which is maybe more in line with what people expect) and not degrees_freedom... I'll ponder that.

So I'm reopening to keep this in mind. Thanks. And as usual thanks @grantmcdermott for replying!!!