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:
- res
RegressionResults A results instance from a linear regression.
- frac
float,default0.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,
defaultFalse 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.
- center
float,defaultNone Deprecated and ignored. The center used to order the observations when
use_distanceis True is always the exog centroid (the multivariate mean). Passing a value emits aFutureWarning.Deprecated since version 0.15.0:
centerhas no effect.centerpreviously was a fraction of the sample and so was not well-defined for regression with more than 1 regressor.
- res
- Returns:
Notes
This test assumes residuals are homoskedastic and may reject a correct linear specification if the residuals are heteroskedastic.
When
use_distanceis True the observations are ordered by their Mahalanobis distance to the centroid ofexog. 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 theorder_bypath), not the “closestfrac” 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 differentendogvalues 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 onendog, 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.