-
Notifications
You must be signed in to change notification settings - Fork 48
supporting offset in poisson #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, nice one. Have never used an offset before in my life, so hadn't bothered with this yet 😀 looks like it might not be too hard to add! fixest::feglm() has an "offset" argument, so we should maybe stick with that instead of statsmodels kwarg solution? |
I'd love to have this feature for a project I am working on. Is there anything I can do to help? |
Hi @bradhackinen , thanks for bringing this back to my attention! =) Just thought about this for a few minutes, and this is what I think we'd need to do: I would add an From the
For the beginning, I would only support a scalar input, no formulas. We'd first have to add the Would you be up to take a stab at this @bradhackinen? Of course I'm more than happy to help along the way =) |
Yeah, I was looking at the code yesterday and I think I can figure out most of it. Adding an argument for a scalar input is no problem, but I'm still working on understanding how to modify the WLS fit, particularly how that works with the demeaning step. If you have a clear idea of how that should be done, I'd be glad to hear some hints. Otherwise I can probably figure it out eventually by deciphering the fixest R code and reading Laurent Berge's paper. |
Alright cool, I'll try to give it some though tomorrow / in the next days and put down some notes! |
That would be very helpful, thanks! I'll also take another look at it on Monday and see what I can figure out on my own. |
So either I am completely off or this might actually be kind of straightforward, at least for the case with no fixed effects? 🤔 We simply adjust pyfixest/pyfixest/estimation/fepois_.py Line 267 in 03693d0
Then, everything stays as is for a while until we compute eta = Z - resid + offset Maybe we can build a working solution without fixed effect demeaning first and then iterate on that? And maybe my brain is clouded right now, though I think the above would work with fixed effect demeaning too? |
Useful hints, thanks. That makes sense to me for the no-FE case. Intuitively, I would think you need to demean the offset in the FE case. Or maybe transforming Z works there too? I don't have a clear understanding of how the demeaning works in the non-linear model yet. |
I think I have it working. The simple modification @s3alfisc proposed seems to work in both the FE and non-FE case. Here is a pull request that implements the feature. I tested it manually on a few different cases, and the output looks correct in both the FE and non-FE cases. I don't have r2py set up, so I didn't try to update |
Hi @bradhackinen, awesome, thank you! I'll take a look this evening and will add a few tests. Thank you! |
this gives the gist; having an
offset
argument would involve constraining the coefficient to 1 and being able to model rates (in contrast to the regular use to model counts). Statsmodels supports it under anexposure
arg.more bg
The text was updated successfully, but these errors were encountered: