Skip to content
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

Add offset option for fepois #805

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bradhackinen
Copy link

This code adds an offset option to fepois regressions so that the function can be used to model differences in outcome rates.

  • In terms of the UI, I followed the functionality of the weights parameter in feols regressions. So the offset argument takes a string that must refer to a column name in the data. If no argument is supplied, the _offset vector is set to 0. This required modifying model_matrix_fixest to take an optional offset argument.
  • Changes to the estimation code are very simple. The offset is added to Z before demeaning and WLS, and then re-added to eta before computing the deviance.

I tested the code manually on the included poisson test data, a separation example (01.csv), and data from a current research project. The output the matches the R implementation of fixest (at least to the decimal places visible in the output) in with and without FE.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyfixest/estimation/model_matrix_fixest_.py 50.00% 3 Missing ⚠️
pyfixest/estimation/estimation.py 66.66% 1 Missing ⚠️
pyfixest/estimation/feols_.py 88.88% 1 Missing ⚠️
Flag Coverage Δ
core-tests 80.82% <80.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pyfixest/estimation/FixestMulti_.py 82.58% <100.00%> (+0.15%) ⬆️
pyfixest/estimation/fepois_.py 87.61% <100.00%> (+0.11%) ⬆️
pyfixest/estimation/estimation.py 93.65% <66.66%> (-0.71%) ⬇️
pyfixest/estimation/feols_.py 83.85% <88.88%> (+0.04%) ⬆️
pyfixest/estimation/model_matrix_fixest_.py 84.04% <50.00%> (-1.29%) ⬇️

@s3alfisc
Copy link
Member

s3alfisc commented Feb 4, 2025

pre-commit.ci autofix

@s3alfisc
Copy link
Member

s3alfisc commented Feb 7, 2025

Hi @bradhackinen , looks like the unit tests I added fail, but almost pass, which is of course the worst that could happen as it isn't clear if the implementation is slightly off or the tolerance just too low 😅 . I will try to debug this in the next days, but might not find time this weekend as I am traveling.

@bradhackinen
Copy link
Author

No worries @s3alfisc. Thanks for writing the tests. Let me know if there is something I can do to help resolve the problems. I can get rpy2 set up on my system next week if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants