Skip to content

White specification test, sanity test, robust standard errors #1126

Open

Description

@josef-pkt

I thought I already added White's general (mis-)specification test somewhere, but I don't find it in the statsmodels source.
Test is based on comparing robust and non-robust cov_params.

reminded me because I saw this:

King, Gary, and Margaret Roberts. "How Robust Standard Errors Expose Methodological Problems They Do Not Fix." (2012).
http://scholar.google.ca/scholar?cluster=8159045491591613177&hl=en&as_sdt=0,5&sciodt=0,5#

need a place to store this reference

Beck, Nathaniel. "Sweeping fewer things under the rug: tis often (usually?) better to model than be robust." (2012).
http://scholar.google.ca/scholar?cluster=7791028302104669808&hl=en&as_sdt=0,5#

Activity

  1. JimVaranelli commented on May 16, 2018

    @JimVaranelli
    Contributor

    Hi Josef - I placed a version of White's spec test in my repository JimVaranelli/WhiteSpec. It operates the same way as the SAS test in that linearly dependent exogenous variables are dropped with a warning. This is useful if the model has dummies. It's been verified extensively against SAS for stat/pval correctness. I have not compared it to other packages like R, etc. I'd be more than happy to add it to statsmodels if interested. Jim

  2. josef-pkt commented on May 16, 2018

    @josef-pkt
    MemberAuthor

    @JimVaranelli Thanks, yes I'm interested and it would make a good addition.
    How to treat categorical when squaring is still an open issue #1061. Currently, we use matrix rank and pinv to avoid having to check, AFAIR.

    I think your spec_white could go with small changes into diagnostics.

    The prep_white_spec_design_matrix looks computationally a bit inefficient. (numpy append shouldn't be used in a loop because it will most likely need to create several intermediate arrays during appending.) Also it might be better to do a full colinearity check in this case instead of just checking individual squared columns, e.g. if the original exog/design already includes a squared x. So this check doesn't guarantee that the rank is equal to the number of columns (dof = devdesign.shape[1])

    Test data for unit tests should go into csv files, so they are easier to use for non-Excel users.

    (I'm planning to do one "round" of working on diagnostics for 0.10, for cases where I have larger conceptual setup cost and need to read up again.)

  3. added this to the 0.10 milestone on May 16, 2018
  4. josef-pkt commented on May 16, 2018

    @josef-pkt
    MemberAuthor

    about checking colinearity:
    There are several PRs that add functions to drop colinear columns which most likely make it into 0.10.
    One addition that I am currently working on will integrate it with a fit method, fit_colinear
    https://github.com/statsmodels/statsmodels/pull/4576/files#diff-b165b4bd4e10edd0dfb485e47c562b2cR646
    Those function will then be available for reuse by other function.

  5. JimVaranelli commented on May 16, 2018

    @JimVaranelli
    Contributor
  6. josef-pkt commented on May 16, 2018

    @josef-pkt
    MemberAuthor

    My guess is that we want to add in the colinearity or dummy checks at some point. That would be computationally more efficient when there are many categorical/dummy variables.

    I didn't realize or didn't pay much attention to the possible problem of creating colinear squared variables when I originally wrote those diagnostic and specification tests.

  7. josef-pkt commented on May 16, 2018

    @josef-pkt
    MemberAuthor

    Another point about dummy check x == x**2:
    This will not identify categorical variables that have a non-{0, 1} encoding.

  8. JimVaranelli commented on May 17, 2018

    @JimVaranelli
    Contributor
  9. JimVaranelli commented on May 18, 2018

    @JimVaranelli
    Contributor

    OK I've uploaded the function in near-final form in file WhiteSpecFn.py. It follows the same methodology as het_white. I removed the simple collinearity check but of course the two test cases with dummies now fail with a singular matrix error. Does it make sense to spend the time/resources to do a full rank calculation (QR decomp or something similar) to remove the dependent columns in the general sense? The OLS function appears to do this but I don't think the reduced design matrix is accessible? Let me know your thoughts. Thanks.

  10. JimVaranelli commented on May 22, 2018

    @JimVaranelli
    Contributor

    I've been experimenting with different methods to extract the set of linearly independent column vectors from a design matrix in order to complete this enhancement. The most obvious method is a QR decomp as used in the _fit_collinear function above. My main objection to this approach is the high computational cost, which is best-case 2mn^2 for an m x n matrix. Compared to QR, a repeated application of Cauchy-Schwartz would instead yield complexity cost m^2n. Given the vast majority of OLS design matrices have n >> m, one would expect a reasonable speedup for the C-S method over QR. Unfortunately (or fortunately?) I was seeing no appreciable time savings with random test cases. For example, the output below is for a random test case with nobs=10,000 and m=9 (simulating a full-rank White spec test with k=3 original IVs). This surprised me since the example would have roughly 810k FLOPs for the C-S method and 1.8B FLOPs for the QR method. My working assumption is this discrepancy is due to the native LAPACK code executing much (MUCH) faster than the native Python/numpy code running my C-S routine. Both methods match SAS dof/stat/pvals but both methods also suffer from threshold uncertainty (_fit_collinear uses 1e-14 so I went with that). If there is no further input I will add the QR decomp for collinearity check and submit a pull request.


    No linear independence check
    White spec: dof = 9 stat = 8.80503162028 pval = 0.455462832625
    time(nocheck) = 0.37703609466552734
    C-S linear independence check
    White spec: dof = 9 stat = 8.80503162028 pval = 0.455462832625
    time(cs check) = 0.42704176902770996
    QR linear independence check
    White spec: dof = 9 stat = 8.80503162028 pval = 0.455462832625
    time(qr check) = 0.4440443515777588

  11. josef-pkt commented on May 22, 2018

    @josef-pkt
    MemberAuthor

    About speed: scipy linalg qr has a 'r' only option which should be faster
    https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.linalg.qr.html

    One property of using linalg is that in most cases by default parallel processing is used by the BLAS/LAPACK libraries for large arrays, which can make it faster for large arrays or slow it down for not large arrays if other parallel processing is desired.

  12. josef-pkt commented on May 22, 2018

    @josef-pkt
    MemberAuthor

    actually numpy has it also

  13. josef-pkt commented on May 22, 2018

    @josef-pkt
    MemberAuthor

    my mistake, I already use 'r' option

  14. JimVaranelli commented on May 24, 2018

    @JimVaranelli
    Contributor

    Yeah I tried a bunch of different code optimizations and I could not get the expected speedup for CS over QR even though QR performs an order of magnitude more operations than CS. So I left the QR in the final version of the code. I will merge the most current version of WhiteSpec.py into my repo later tonight so you can see how I did the CS check. WhiteSpecFn.py will show the function as it would appear in sm. I'll also add the individual .csv test cases to the repo.

    Administrative questions:

    1. should the collinear removal be a user option? default=no? or always run with no option?
    2. should a warning be issued if collinear removal?
    3. should the dof be a return value along with stat/pval?
    4. should the function go into outliers_influence (with RESET) or diagnostic (with het_white)?
  15. josef-pkt commented on May 24, 2018

    @josef-pkt
    MemberAuthor

    (I forgot to reply last time after getting distracted with qr)
    I don't really now how much computation those linalg functions are doing, but my guess was that "r" only qr should be doing about as much work as Cauchy-Schwarz or do I think of something else.
    (The main difference is whether we work on decomposition of the original nobs data or on the moment matrix, X' X. The latter is faster for nobs >> k_vars, but numerically less precise. E.g. cholesky would to the same thing as "r" only QR.)

    should the collinear removal be a user option? default=no? or always run with no option?

    No, this is just an implementation detail. If there are dummy variables the extended array will be collinear, but it's not something that the user needs to worry about.
    If we use different ways of computing it, then we might add a method option if it is relevant for the user.

    should a warning be issued if collinear removal?

    no, as above

    should the dof be a return value along with stat/pval?

    degrees of freedom should be returned,
    In general I would like to move to returning a simple class with attributes by default (still not generally used yet.

    should the function go into outliers_influence (with RESET) or diagnostic (with het_white)?

    in diagnostics, it has a different purpose than outliers_influence
    (RESET test is misplaced in there #3690 )

  16. JimVaranelli commented on May 24, 2018

    @JimVaranelli
    Contributor

    Thanks for the quick response! I will incorporate the above and submit a pull request in the next few days.

  17. JimVaranelli commented on Jun 7, 2018

    @JimVaranelli
    Contributor

    Pull request submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions