Skip to content

BUG/ENH: LM, score_test variable addition with redundant variables (rank) #5364

Closed

Description

@josef-pkt

#2041 general issue

I'm running a variable addition GLM.score_test
res_glm.model.score_test(res_glm.params, exog_extra=bs.basis_)
to test the addition of splines when the current model includes the linear term.

The score test uses the number of columns as the number of restriction, while the actual addition is smaller because of the repeated subspace.

example base on GAM PR #5296

bs.basis_ includes the basis functions for two variables. Those two are included as linear terms in res_glm.model. Each basis includes the linear function as a linear combination of basis functions.
The constant has been removed from basis function, so only the two linear/trend terms are "duplicated".

res_glm.model.score_test(res_glm.params, exog_extra=bs.basis_)
(array([ 108.91677455]), array([  3.09383926e-14]), 20)

bs.basis_.shape
(203, 20)

from statsmodels.stats.multivariate_tools import partial_project
projection_resid = partial_project(bs.basis_, res_glm.model.exog)
np.linalg.matrix_rank(projection_resid.resid)
18

update
using the pca helper function knowing already how many factors to keep

test statistic is the same, but p-value is corrected to take account of the reduced number of constraints

from statsmodels.sandbox.tools.tools_pca import pca
red = pca(projection_resid.resid, keepdim=18)[1]
res_glm.model.score_test(res_glm.params, exog_extra=red)
(array([ 108.91677455]), array([  5.00598345e-15]), 18)

Activity

  1. josef-pkt commented on Nov 2, 2018

    @josef-pkt
    MemberAuthor

    #4716 is the PR to add score_test as a public method.
    I don't remember whether it handles reduced rank, collinearity or redundancy in the variable addition and in constraints.

  2. josef-pkt commented on Nov 2, 2018

    @josef-pkt
    MemberAuthor

    #1061 is a related case for the diagnostic lm tests with categorical, i.e. x**2 == x which creates reduced rank withing the test design/exog array.

  3. added this to the 0.15 milestone on Feb 13, 2023
  4. josef-pkt commented on Feb 13, 2023

    @josef-pkt
    MemberAuthor

    check if this is still relevant for score_test.

    related: rank reduced number of constraints in anova and similar #8512

  5. added
    type-bug-wrong
    on Sep 28, 2026
  6. added a commit that references this issue on Nov 16, 2026
    abea341
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

    comp-basecomp-genmodcomp-statsprio-hightype-bugtype-bug-wrongtype-enh

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions