lrberge / fixest

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

feglm(family='poisson') seems to hang in cpp_demean() but femlm(family='poisson') does not? #510

Open vincLohm opened 3 weeks ago

vincLohm commented 3 weeks ago

Firstly I cannot thank you enough for writing such an amazingly fast high-dimensional FE pkg !

And sorry I'm not sure where to post this question. I feel like it is too specific to this package to be asked on stackexchange. I have a fairly large dataset (16.9M rows) indexed by i j t (with mostly zeros in the response variable). For certain specifications glm(poisson) seems to hang on demeaning, while the same specification with mlm returns pretty quickly. I'm confused as to what the difference between the 2 implementations is, and searched the documentation quite thoroughly but could not find anything on the difference.

Whenever I can get both functions to return I get identical estimates, including the FE.

Feel free to delete this post f it's not appropriate, but maybe you could point me to where I can find the answer in the documentation.

lrberge commented 1 week ago

Thanks for the words! :-)

I'm sorry for the inconvenience. Quick question: is this with the current version of the package (>=0.12.0)? Did you experience similar issues with old versions? I'm asking because I have changed the demeaning algorithm in 0.12.0 and hope I didn't introduce a regression.

That said: feglm and femlm, although they provide the same results are completely different algorithms! The algorithm of feglm is not detailed in the documentation but is a 'classic' GLM algorithm, as described in https://arxiv.org/abs/1903.01690https://arxiv.org/abs/1903.01690

The algorithm of femlm is a direct maximum likelihood estimation, as described in https://github.com/lrberge/fixest/blob/master/_DOCS/FENmlm_paper.pdf

The two algorithms are very different and don't have the same convergence properties.

To (possibly) make convergence faster, you may play with the argument fixef.algo of the feglm function, see its documentation here.