statsmodels.stats.diagnostic.linear_rainbow#

statsmodels.stats.diagnostic.linear_rainbow(res, frac=0.5, order_by=None, use_distance=False, center=None)[source]#

Rainbow test for linearity

The null hypothesis is the fit of the model using full sample is the same as using a central subset. The alternative is that the fits are different. The rainbow test has power against many different forms of nonlinearity.

Parameters:
resRegressionResults

A results instance from a linear regression.

fracfloat, default 0.5

The fraction of the data to include in the center model.

order_by{ndarray, str, list[str]}, optional

If an ndarray, the values in the array are used to sort the observations. If a string or a list of strings, these are interpreted as column name(s) which are then used to lexicographically sort the data.

use_distancebool, default False

Flag indicating whether the data should be ordered by the Mahalanobis distance to the exog centroid (the multivariate mean). This makes the test invariant to the order of the observations; see the Notes for the precise statement.

centerfloat, default None

Deprecated and ignored. The center used to order the observations when use_distance is True is always the exog centroid (the multivariate mean). Passing a value emits a FutureWarning.

Deprecated since version 0.15.0: center has no effect. center previously was a fraction of the sample and so was not well-defined for regression with more than 1 regressor.

Returns:
fstatfloat

The test statistic based on the F test.

pvaluefloat

The pvalue of the test.

Notes

This test assumes residuals are homoskedastic and may reject a correct linear specification if the residuals are heteroskedastic.

When use_distance is True the observations are ordered by their Mahalanobis distance to the centroid of exog. Using the centroid (the multivariate mean) as the center follows Utts (1982) [1]; the subset used is the middle band of the distance ranks (the same slicing as the order_by path), not the “closest frac” subset of Utts. Because the centroid is order invariant and exact ties in distance are broken deterministically using the exog values, the returned statistic does not depend on the order of the rows of the data. The one exception is a pair of observations with identical exog rows but different endog values that fall on opposite sides of the subset boundary: resolving such a tie would require ordering by the response, which would make the subset depend on endog, so these are left in their input order.

References

[1]

Utts, J. M. (1982). The rainbow test for lack of fit in regression. Communications in Statistics - Theory and Methods, 11(24), 2801-2815.