Skip to content

Error estimating mean in rainbow test #9103

Closed

Description

@SvenSerneels

The function linear_rainbow has an option to either order cases by a certain reference case order, or alternatively to calculate Mahalanobis distances to the center of the data and then build the central fit from the frac fraction of cases that have the smallest Mahalanobis distances, as was proposed in the original paper by Jessica Utts (1982). In the latter option, cases in the raw data are not assumed to be sorted. However, the present code will just take the n/2 th case as the center of the data:

center_obs = exog[center:center+1]

This is obviously incorrect. The location estimate required in Mahalanobis distances is the mutlivariate mean, not the n/2 th case in the data. I suggest to modify this line to center_vec = np.mean(exog,axis=0) and then use center_vec instead of center_obs going forward.

Activity

  1. added this to the 0.15 milestone on Dec 21, 2023
  2. josef-pkt commented on Dec 21, 2023

    @josef-pkt
    Member

    Thanks for finding this.

    I agree that there is a problem with the current code.
    AFAICS, there is no test coverage for the Mahalanobis distance case (based on brief code search).

    I don't know or remember why there is a try-except with using mean in the except case.

    R uses the mean https://search.r-project.org/CRAN/refmans/lmtest/html/raintest.html

    Alternatively to using the mean, using median might be better, and more in the spirit of using central observations as in the univariate case.
    Also we could use a robust cov, mahalanobis distance when they become available #8129

  3. josef-pkt commented on Dec 21, 2023

    @josef-pkt
    Member

    asides:

    I don't have the Utts article on my computer and not in my Zotero list. So, I don't know what reference I used for this.
    (The mahalanobis extension was not added by me, so I guess I never looked at that part in details)

    relationship to outlier robust and influence diagnostics.
    AFAICS, This test does not only reject the model for missing nonlinearities but also for outlier-influence problems.
    It's a good idea to have a diagnostic test similar to robust estimators. The corresponding robust estimator would be LTS (least trimmed squares) where the regression is only based on a subset of exog that should be outlier free.

    I guess we can extend the basic idea to other (nonlinear) models like GLM. If there is no specific test statistic, then we could use a variable addition test that separates parameter estimates for central and tail observations (defined by mahalanobis distance).

  4. SvenSerneels commented on Dec 21, 2023

    @SvenSerneels
    Author

    Thanks for acknowledging the issue.

    While I like your remarks on robustness, I think that we should at first focus on having a correct and reliable test in the classical case (no outliers). The rainbow test is based on F statistics that hold true under normal distribution assumptions for the linear model. When using a robust estimator, this inference is no longer correct (and it is much more complicated to derive accurate distributional properties). I therefore suggest to go with the mean (univariate and multivariate) and defer a robust version to further research. That research could even lead to a publication.

    Another suggestion is to expand the linear_rainbow function such that it also works for Ridge regression fits (fit_regularized(method='elastic_net', L1_wt=0)), since there are no inference issues in that case.

    The original paper by Jessica Utts is available free of charge at: https://www.researchgate.net/publication/232819080_The_Rainbow_Test_for_Lack_of_Fit_in_Regression

  5. josef-pkt commented on Dec 23, 2023

    @josef-pkt
    Member

    independently of fixing the problem with rainbow test implementation

    I found an article that included the rainbow test in a monte carlo for nonlinear specification (nonlinearity also in y, so a bit different)

    rainbow test
    compared to other specification tests, rainbow test is not very powerful under normality.
    If the error distribution is non-normal, then rainbow test is liberal and overrejects quite a bit.

    reset test was doing pretty well and is robust to non-normality in their case, but maybe because it's a larger misspecification that also affects nonlinearity in endog/link.

    Godfrey, L. G., Michael McAleer, and C. R. McKenzie. “Variable Addition and Lagrange Multiplier Tests for Linear and Logarithmic Regression Models.” The Review of Economics and Statistics 70, no. 3 (1988): 492–503. https://doi.org/10.2307/1926788.

  6. added a commit that references this issue on Aug 7, 2026
  7. added a commit that references this issue on Aug 7, 2026
    1955c7b
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions