Skip to content

BUG: use rank-adjusted df in wald_test_terms for rank-deficient models - #9907

Open
genrichez wants to merge 2 commits into
statsmodels:mainfrom
genrichez:fix/wald-test-terms-df-rank
Open

BUG: use rank-adjusted df in wald_test_terms for rank-deficient models#9907
genrichez wants to merge 2 commits into
statsmodels:mainfrom
genrichez:fix/wald-test-terms-df-rank

Conversation

@genrichez

@genrichez genrichez commented Jul 12, 2026

Copy link
Copy Markdown

Fixes #9686.

wald_test_terms was reporting df_constraint as the number of rows in the constraint matrix (constraint.shape[0] ). For rank-deficient models (e.g. over-parameterized with zero columns via _fit_collinear), this is wrong because some constraints are redundant.

The wald_test method already computes the matrix rank of the constraint covariance and adjusts the degrees of freedom internally. This PR uses that rank-adjusted value in wald_test_terms instead of the nominal row count.

Also updated compare_waldres in the tests to check against the effective df, and added a regression test with a rank-deficient interaction model.

AI Disclosure

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

@bashtage bashtage self-assigned this Jul 20, 2026
@bashtage bashtage added this to the 0.15 milestone Jul 23, 2026
@bashtage
bashtage force-pushed the fix/wald-test-terms-df-rank branch from 0801877 to 0390b0c Compare August 10, 2026 06:26
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

Thanks, the AI Disclosure section looks complete.

genrichez added 2 commits August 10, 2026 18:38
wald_test_terms was reporting df_constraint as the number of rows in the
constraint matrix. For rank-deficient models this is wrong because some
constraints are redundant. The wald_test method already computes the
effective rank internally, so we now use that value instead.

Closes statsmodels#9686
@bashtage
bashtage force-pushed the fix/wald-test-terms-df-rank branch from 0390b0c to 275e4a4 Compare August 10, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG/ENH: wald test, wald_test_terms, degrees of freedom for rank-deficient cases

2 participants