Skip to content

BUG: DistributedModel fails with GEE (groups dropped from the results model; fit_regularized signature) #10778

Closed

Description

@ChenyangLi4288

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:

  1. Averaging (_est_unregularized_naive with _join_naive): every chunk is fitted without error, but fit then raises a TypeError. At the end of fit (distributed_estimation.py, line 574), a placeholder model is made with self.model_class([0], [0], **self.init_kwds). This call does not pass groups, and GEE requires it. The comment above that line already mentions this possible problem.
  2. Default method (_est_regularized_debiased): it calls fit_regularized(alpha=...). OLS and GLM accept alpha, but GEE.fit_regularized uses pen_wt, so it raises a TypeError.

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.0

Checklist

  • 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 main branch.

Activity

  1. ChenyangLi4288 commented on Nov 17, 2026

    @ChenyangLi4288
    ContributorAuthor

    I have a fix for both cases and will open a PR soon.

  2. added a commit that references this issue on Nov 17, 2026
    6b6652f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions