Skip to content

Singular design matrix produce very extreme p-values #8670

Open

Description

@JasonTan-code

I found when the design matrix is singular, statsmodels can give me very extreme and wrong p values. In this case, I have x2 + x3 = 1, and statsmodels produced wrong results.

In R, when x2 + x3 = 1, it will drop x3, fit the model with x2 only, and give NA to x3. I would imagine R implementation is less misleading for most of the users.

Is there a way that I can get similar singularity handling as R using statsmodels?

Screen Shot 2023-02-13 at 5 28 43 PM

Screen Shot 2023-02-13 at 5 39 33 PM

Activity

  1. JasonTan-code commented on Feb 13, 2023

    @JasonTan-code
    Author

    Also, when x1 = x2, statsmodels calculated the right p values for both x1 and x2, but it splits the effect size and standard errors by half. This is, of course, not a bug, but I prefer the R implementation.

    Screen Shot 2023-02-13 at 5 49 21 PM

    Screen Shot 2023-02-13 at 5 49 34 PM

  2. josef-pkt commented on Feb 14, 2023

    @josef-pkt
    Member

    It's a design decision that we use pinv in linear regression.
    This is a regularized solution if relative condition number is larger than around 5e15 (default by np.linalg.pinv)

    Currently, statsmodels does NOT have an option to drop semi-arbitrary columns from exog.
    #6935 is a PR that would add pivoting QR
    #3824 has a long discussion on our default
    several issues to figure out how to handle this with more options, for example #2062

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions