Skip to content

BUG: Follow up #10790 on GEE marginal effects and small-sample covariances - #10792

Merged
bashtage merged 8 commits into
statsmodels:mainfrom
ChenyangLi4288:bug/gee-10790-followups
Nov 19, 2026
Merged

bashtage merged 8 commits into
statsmodels:mainfrom
ChenyangLi4288:bug/gee-10790-followups

Conversation

@ChenyangLi4288

Copy link
Copy Markdown
Contributor

Fixes the two GEE problems listed under "Not changed" in #10790 by @bashtage (the third, case-sensitive cov_type, is #10791).

  • get_margeff ignored use_t. With use_t=True, the p-values and confidence intervals of the marginal effects now use the t distribution with df_resid_inference, as the parameters do, and the summary_frame columns are t / Pr(>|t|). The default is unchanged.
  • The marginal effects summary() raised ValueError. Its header had one entry for the two confidence interval columns. Found while testing the above.
  • Leverage 1 in bias_reduced / kauermann_carroll. A group with leverage 1, e.g. a single observation with its own dummy, raised a bare LinAlgError (Poisson) or silently returned a meaningless covariance (Gaussian, where rounding hides the singularity). It now raises a ValueError that names the group. The leverages are checked on a p x p matrix with the same nonzero eigenvalues, so groups of 800 cost 0.13 s instead of 5.4 s for the full matrix.

The new tests fail on main and pass here.

Not changed: NominalGEE.get_margeff() fails with 3 or more categories (a shape error), so the J > 1 branch of the margins summary is not reachable.

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude (Claude Code).
    Used for: drafting the fixes, tests and docs.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

…ge 1

A group with leverage 1 raised a bare LinAlgError, or gave a meaningless covariance for Gaussian.
The eigenvalues of the full group leverage matrix cost about 50 times the solve for groups of 800.
The header had one entry for the two confidence interval columns, so summary() raised ValueError.
get_margeff ignored use_t and always used the normal distribution.
@ChenyangLi4288

ChenyangLi4288 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Heads-up: this PR and #10791 both add a bullet at the end of the GLM bug-fix list in docs/source/release/version0.15.1.rst, so whichever is merged second will conflict there. I can rebase that one as soon as the other is merged.

@bashtage
bashtage merged commit 3876f65 into statsmodels:main Nov 19, 2026
10 checks passed
@bashtage

Copy link
Copy Markdown
Member

Thanks for the work on GEE.

bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 19, 2026
The leverage check of statsmodels#10792 calls np.linalg.eigvals, which raises a bare
LinAlgError when the covariance of the parameters contains NaN or inf, for
example for a Poisson model with an exchangeable correlation and an
observation with y = 0 and its own dummy variable. Before statsmodels#10792 the same
fit returned NaN standard errors for cov_type="bias_reduced" and failed in
sqrtm for "kauermann_carroll". Check that the covariance is finite first and
raise a ValueError that says why the leverages cannot be computed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 19, 2026
Add a Raises entry with a versionchanged directive to GEE.fit, and say that a
leverage larger than 1 - 1e-8 counts as 1 (the tolerance of the check added in
statsmodels#10792). Reword the release note of statsmodels#10792: main returned meaningless
covariances for some families, not only Gaussian (Binomial bse about 9e15,
Poisson NaN), and a non-finite covariance now raises the ValueError.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 19, 2026
The leverage test of statsmodels#10792 still passed if the p x p matrix was replaced by
dmat.T @ dmat, if the message showed the position instead of the label of the
group, or if the cov_type name in the message was wrong. Use string group
labels and match the cov_type, compare the check with the eigenvalues of the
full leverage matrix built in numpy for an exchangeable correlation (with
dummies whose leverage is within and outside 1e-8 of 1), and add a case with
a non-finite covariance. Import scipy.stats at module level.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 19, 2026
The leverage check of statsmodels#10792 calls np.linalg.eigvals, which raises a bare
LinAlgError when the covariance of the parameters contains NaN or inf, for
example for a Poisson model with an exchangeable correlation and an
observation with y = 0 and its own dummy variable. Before statsmodels#10792 the same
fit returned NaN standard errors for cov_type="bias_reduced" and failed in
sqrtm for "kauermann_carroll". Check that the covariance is finite first and
raise a ValueError that says why the leverages cannot be computed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 19, 2026
Add a Raises entry with a versionchanged directive to GEE.fit, and say that a
leverage larger than 1 - 1e-8 counts as 1 (the tolerance of the check added in
statsmodels#10792). Reword the release note of statsmodels#10792: main returned meaningless
covariances for some families, not only Gaussian (Binomial bse about 9e15,
Poisson NaN), and a non-finite covariance now raises the ValueError.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 19, 2026
The leverage test of statsmodels#10792 still passed if the p x p matrix was replaced by
dmat.T @ dmat, if the message showed the position instead of the label of the
group, or if the cov_type name in the message was wrong. Use string group
labels and match the cov_type, compare the check with the eigenvalues of the
full leverage matrix built in numpy for an exchangeable correlation (with
dummies whose leverage is within and outside 1e-8 of 1), and add a case with
a non-finite covariance. Import scipy.stats at module level.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit that referenced this pull request Nov 19, 2026
BUG: Follow up #10792 on GEE small-sample covariances, docs and tests
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.

2 participants