Repository navigation
Description
Describe the bug
DistributedModel does not work with GEE. GEE needs a groups array for each data chunk, which can be passed with init_kwds_generator. Both estimation methods then fail:
- Averaging (
_est_unregularized_naivewith_join_naive): every chunk is fitted without error, butfitthen raises aTypeError. At the end offit(distributed_estimation.py, line 574), a placeholder model is made withself.model_class([0], [0], **self.init_kwds). This call does not passgroups, andGEErequires it. The comment above that line already mentions this possible problem. - Default method (
_est_regularized_debiased): it callsfit_regularized(alpha=...).OLSandGLMacceptalpha, butGEE.fit_regularizedusespen_wt, so it raises aTypeError.
The tests in test_distributed_estimation.py only use OLS and GLM.
A related question: DistributedResults has params and predict, but no standard errors. With GEE, the robust standard errors are usually what users want. Each chunk could return the pieces of its robust covariance, and the chunks could be combined into one estimate with standard errors. Would that be useful as a follow-up after this bug is fixed?
xref #4550, which also notes that the distributed results have no cov_params.
Code Sample, a copy-pastable example
import numpy as np
import statsmodels.api as sm
from statsmodels.base.distributed_estimation import (
DistributedModel,
_est_unregularized_naive,
_join_naive,
)
rng = np.random.default_rng(0)
n_groups, m = 200, 5
groups = np.repeat(np.arange(n_groups), m)
x = np.c_[np.ones(n_groups * m), rng.standard_normal((n_groups * m, 2))]
y = x @ [0.5, 1.0, -0.5] + np.repeat(rng.standard_normal(n_groups), m)
y += rng.standard_normal(n_groups * m)
k = 2
masks = [np.isin(groups, b) for b in np.array_split(np.arange(n_groups), k)]
def data_gen():
for mask in masks:
yield y[mask], x[mask]
def init_kwds_gen():
for mask in masks:
yield {"groups": groups[mask]}
# 1. Coefficient averaging: both partition fits succeed, then fit() raises
mod = DistributedModel(
k,
model_class=sm.GEE,
init_kwds={"cov_struct": sm.cov_struct.Exchangeable()},
estimation_method=_est_unregularized_naive,
join_method=_join_naive,
)
try:
mod.fit(data_gen(), init_kwds_generator=init_kwds_gen())
except TypeError as e:
print("averaging:", e)
# 2. Default debiased regularized estimation
mod = DistributedModel(
k,
model_class=sm.GEE,
init_kwds={"cov_struct": sm.cov_struct.Exchangeable()},
)
try:
mod.fit(data_gen(), fit_kwds={"alpha": 0.1}, init_kwds_generator=init_kwds_gen())
except TypeError as e:
print("default:", e)Expected Output
Case 1 returns the averaged GEE parameters, as it does for OLS and GLM.
Case 2 either works with GEE, or raises a clear error before any chunk is fitted, saying that this method does not support GEE.
Actual Output
Traceback (most recent call last):
File "repro.py", line 27, in <module>
mod.fit(
~~~~~~~^
((y[k], x[k]) for k in masks),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
init_kwds_generator=({"groups": groups[k]} for k in masks),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../statsmodels/base/distributed_estimation.py", line 574, in fit
res_mod = self.model_class([0], [0], **self.init_kwds)
TypeError: GEE.__init__() missing 1 required positional argument: 'groups'
Case 2 (default estimation method, with fit_kwds={"alpha": 0.1}):
TypeError: GEE.fit_regularized() got an unexpected keyword argument 'alpha'Versions
Reproduced on main (0.15.1.dev1422+g99725743c, c818140d7 plus a docs-only commit) and on 0.14.6.
Python: 3.13.3
OS: Windows 11 10.0.22631 AMD64
statsmodels: 0.15.1.dev1422+g99725743c
cython: 3.3.1
numpy: 2.5.5
scipy: 1.18.1
pandas: 3.1.1
patsy: 1.0.3
joblib: 1.6.0Checklist
-
I have searched the issue tracker for a similar issue and did not find one.
-
I have confirmed this bug exists on the latest released version of statsmodels, or on the
mainbranch.
Activity
ChenyangLi4288 commentedon Nov 17, 2026
I have a fix for both cases and will open a PR soon.
BUG: Support GEE in DistributedModel