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

Fepois predict with newdata #703

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

Fepois predict with newdata #703

wants to merge 5 commits into from

Conversation

leostimpfle
Copy link
Collaborator

Closes #468

@leostimpfle
Copy link
Collaborator Author

predict still does not work with newdata and fixed effects (see #467). Something doesn't quite work in the fixef method inherited from feols. I'll investigate further.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyfixest/estimation/fepois_.py 0.00% 6 Missing ⚠️
Flag Coverage Δ
core-tests 77.79% <0.00%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
pyfixest/estimation/fepois_.py 86.79% <0.00%> (-0.42%) ⬇️

@s3alfisc
Copy link
Member

If I change to the following

    def predict(
        self,
        newdata: Optional[DataFrameType] = None,
        atol: float = 1e-6,
        btol: float = 1e-6,
        type: PredictionType = "link",
    ) -> np.ndarray:

        #if newdata is not None and self._has_fixef:
        #    raise NotImplementedError()

        y_hat = super().predict(newdata=newdata, type=type, atol=atol, btol=btol)
        if type == "response":
            y_hat = np.exp(y_hat)
        return y_hat

predict works with newdata and fixed effects for type = "response":

%load_ext autoreload
%autoreload 2

import pyfixest as pf
data = pf.get_data(model = "Fepois")

fit = pf.fepois("Y ~ X1 | f1", data = data)
fit.predict(newdata = data.dropna(), type = "response")[0:5]
# array([2.7803393 , 2.81678101, 3.20245421, 3.3940836 , 3.38641651])
fit.predict(type = "response")[0:5]
# array([2.78032513, 2.81699512, 3.20381613, 3.39393412, 3.38457835])

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.

Fepois: Add support for predict with newdata argument
2 participants