In many cases of statistical analysis, we are not sure whether our statistical model is correctly specified. For example when using ols, then linearity and homoscedasticity are assumed, some test statistics additionally assume that the errors are normally distributed or that we have a large sample. Since our results depend on these statistical assumptions, the results are only correct of our assumptions hold (at least approximately).
One solution to the problem of uncertainty about the correct specification is to use robust methods, for example robust regression or robust covariance (sandwich) estimators. The second approach is to test whether our sample is consistent with these assumptions.
The following briefly summarizes specification and diagnostics tests for linear regression.
For these test the null hypothesis is that all observations have the same error variance, i.e. errors are homoscedastic. The tests differ in which kind of heteroscedasticity is considered as alternative hypothesis. They also vary in the power of the test for different types of heteroscedasticity.
het_breuschpagan
het_white
het_goldfeldquandt
This group of test whether the regression residuals are not autocorrelated. They assume that observations are ordered by time.
durbin_watson
acorr_ljungbox
acorr_breusch_godfrey
linear_harvey_collier
acorr_linear_rainbow
acorr_linear_lm
Test whether all or some regression coefficient are constant over the entire data sample.
breaks_cusumolsresid
breaks_hansen
recursive_olsresiduals
jarque_bera
omni_normtest
normal_ad
kstest_normal
lilliefors
qqplot, scipy.stats.probplot
These measures try to identify observations that are outliers, with large residual, or observations that have a large influence on the regression estimates. Robust Regression, RLM, can be used to both estimate in an outlier robust way as well as identify outlier. The advantage of RLM that the estimation results are not strongly influenced even if there are many outliers, while most of the other measures are better in identifying individual outliers and might not be able to identify groups of outliers.
RLM
example from example_rlm.py
import statsmodels.api as sm ### Example for using Huber's T norm with the default ### median absolute deviation scaling data = sm.datasets.stackloss.load() data.exog = sm.add_constant(data.exog) huber_t = sm.RLM(data.endog, data.exog, M=sm.robust.norms.HuberT()) hub_results = huber_t.fit() print(hub_results.weights)
And the weights give an idea of how much a particular observation is down-weighted according to the scaling asked for.
Influence
Class in stats.outliers_influence, most standard measures for outliers and influence are available as methods or attributes given a fitted OLS model. This is mainly written for OLS, some but not all measures are also valid for other models. Some of these statistics can be calculated from an OLS results instance, others require that an OLS is estimated for each left out variable.
unitroot_adf
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/diagnostic.html