Open greenguy33 opened 4 days ago
Hi Hayden, thanks for your nice words and awesome that you enjoy using pyfixest
! =)
I did have one quick question which I haven't been able to find an answer to as of yet. Is there an easy way to extract the covariance matrix from a regression object, ideally into a Pandas dataframe, or is that feature not implemented?
The estimated variance covariance is stored as an attribute in all classes derived from Feols
- you can get it by calling Feols._vcov
.
I think it would likely be the .vcov()
method would simply return the estimated variance covariance matrix? This should be easy enough to implement =)
I.e. you can access the vcov matrix as
import pyfixest as pf
data = pf.get_data()
fit = pf.feols("Y ~ X1", data = data)
fit._vcov
# array([[ 0.01250398, -0.00749663],
# [-0.00749663, 0.00718007]])
Awesome! Thank you so much.
@s3alfisc I can take a stab at this quick change if it's helpful. Meaning, having the .vcov() method return the covariance matrix. Let me know and I'll fork the code
Hey @greenguy33 that would be amazing!
@s3alfisc Happy to do it!
I took a quick look at the code. Unless I'm missing something, this change is as simple as changing the line return self
to return self._vcov
on line 481 of file feols_.py
Yes, that would essentially be it!
I have been using pyfixest for a few weeks now and up until now it has been great - I love being able to do the stats modeling I would do in R alongside the nice syntax and integration that Python offers. Overall, fantastic project and two thumbs up!
I did have one quick question which I haven't been able to find an answer to as of yet. Is there an easy way to extract the covariance matrix from a regression object, ideally into a Pandas dataframe, or is that feature not implemented?
The original fixest package has the method
vcov()
which returns a K * K matrix where K == number of model variables. https://rdrr.io/cran/fixest/man/vcov.fixest.htmlIn pyfixest, I see that
.vcov("HC1")
can be called as an attribute of a regression object, but it seems to work in conjunction with.summary()
which updates the standard errors using the provided standard error technique. But I haven't seen how to get the entire K * K matrix out of this.Consider this a feature request if this doesn't exist yet!