Skip to content

feat(fepois): Use dynamic demeaning selection based on backend setting #891

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions pyfixest/estimation/fepois_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pyfixest.errors import (
NonConvergenceError,
)
from pyfixest.estimation.demean_ import demean
# Updated import: Added _set_demeaner_backend
from pyfixest.estimation.demean_ import demean, _set_demeaner_backend
from pyfixest.estimation.feols_ import Feols, PredictionErrorOptions, PredictionType
from pyfixest.estimation.FormulaParser import FixestFormula
from pyfixest.estimation.solvers import solve_ols
Expand Down Expand Up @@ -228,6 +229,9 @@ def get_fit(self) -> None:
_fixef_tol = self._fixef_tol
_solver = self._solver

# Select the appropriate demeaning function based on the backend setting
demean_function = _set_demeaner_backend(self._demeaner_backend)

def compute_deviance(_Y: np.ndarray, mu: np.ndarray):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Expand Down Expand Up @@ -272,8 +276,8 @@ def compute_deviance(_Y: np.ndarray, mu: np.ndarray):
ZX = np.concatenate([reg_Z, _X], axis=1)

if _fe is not None:
# ZX_resid = algorithm.residualize(ZX, mu)
ZX_resid, success = demean(
# Updated call: Use demean_function instead of hardcoded demean
ZX_resid, success = demean_function(
x=ZX, flist=_fe, weights=mu.flatten(), tol=_fixef_tol
)
if success is False:
Expand Down Expand Up @@ -474,7 +478,7 @@ def _check_for_separation(
iterative rectifier ("ir"). Executes all methods by default.

Returns
-------
------
list
List of indices of observations that are removed due to separation.
"""
Expand Down Expand Up @@ -531,7 +535,7 @@ def __call__(
Fixed effects.

Returns
-------
------
set
Set of indices of separated observations.
"""
Expand All @@ -558,7 +562,7 @@ def _check_for_separation_fe(
Fixed effects.

Returns
-------
------
set
Set of indices of separated observations.
"""
Expand Down Expand Up @@ -618,7 +622,7 @@ def _check_for_separation_ir(
Maximum number of iterations. Defaults to 100.

Returns
-------
------
set
Set of indices of separated observations.
"""
Expand Down