-
Notifications
You must be signed in to change notification settings - Fork 36
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
Unexpected behavior with resids and predict post feols #596
Comments
Hi @daltonm-bls , thanks for reporting this! Can confirm: %load_ext autoreload
%autoreload 2
import pandas as pd
import pyfixest as pf
data = pf.get_data()
dfr = data[["Y", "f1"]].dropna()
fml_1 = "Y ~ 1 | f1"
fml_2 = "Y ~ C(f1)"
model_1 = pf.feols(fml = fml_1, data=dfr)
model_2 = pf.feols(fml = fml_2, data = dfr)
model_1.resid().flatten()[0:5]
# array([-1.38608153, 2.05742899, 0.10149807, 1.31744198, -2.12153977])
model_2.resid().flatten()[0:5]
# array([-0.07256172, 1.26208442, 0.03292194, -1.59579222, 0.60175012])
model_1.predict().flatten()[0:5]
# array([-0.07256172, 1.26208442, 0.03292194, -1.59579222, 0.60175012])
model_2.predict().flatten()[0:5]
# array([-1.38608153, 2.05742899, 0.10149807, 1.31744198, -2.12153977]) Will tackle this tomorrow! |
This is the problematic line: pyfixest/pyfixest/estimation/FixestMulti_.py Line 332 in 70e2b0c
|
@all-contributors please add @daltonm-bls for bug |
I've put up a pull request to add @daltonm-bls! 🎉 |
Fixed in version import pyfixest as pf
data = pf.get_data()
fit = pf.feols("Y ~1 |f1", data=data)
fitC = pf.feols("Y ~ C(f1)", data=data)
print(fit.resid()[0:5])
# [-0.07256172 1.26208442 0.03292194 -1.59579222 0.60175012]
print(fitC.resid()[0:5])
#[-0.07256172 1.26208442 0.03292194 -1.59579222 0.60175012]
print(fit.predict()[0:5])
# [-1.38608153 2.05742899 0.10149807 1.31744198 -2.12153977]
print(fitC.predict()[0:5])
# [-1.38608153 2.05742899 0.10149807 1.31744198 -2.12153977] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python Version: 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0]
Operating System: Linux-4.18.0-553.8.1.el8_10.x86_64-x86_64-with-glibc2.28
pyfixest Version: 0.24.0
Expected behavior:
model.resid() should give an array of floats that represent the residuals
model.predict() should give an array of floats that represent the predicted values
Actual behavior:
in a regression with only absorbed fixed effects (all I care about is the residual, so this is a plausible model), the residuals seem to be transposed with the predicted values and vice versa. Furthermore, the residuals are an array of arrays, as opposed to an array of floats.
Recreated:
The text was updated successfully, but these errors were encountered: