statsmodels.stats.outliers_influence.OLSInfluence#

class statsmodels.stats.outliers_influence.OLSInfluence(results)[source]#

Class to calculate outlier and influence measures for OLS and WLS results

Changed in version 0.15.1: The weights of WLS results are used. Previously the weights were ignored, so that the hat matrix diagonal, the studentized residuals, Cook’s distance, dffits, dfbeta, dfbetas and the covariance ratio were incorrect for WLS results.

Parameters:
resultsRegressionResults

Results of an OLS or WLS regression.

Attributes:
cooks_distance

Cook’s distance

Uses original results, no nobs loop

Eubank, R. L. (1999). Nonparametric regression and spline

smoothing. CRC press.

Cook’s distance. (n.d.). In Wikipedia. July 2019, from

https://en.wikipedia.org/wiki/Cook%27s_distance

cov_ratio

covariance ratio between LOOO and original

This uses determinant of the estimate of the parameter covariance from leave-one-out estimates. requires leave one out loop for observations

det_cov_params_not_obsi

determinant of cov_params of all LOOO regressions

dfbeta

dfbeta

uses results from leave-one-observation-out loop

dfbetas

dfbetas

uses results from leave-one-observation-out loop

dffits

dffits measure for influence of an observation

dffitsndarray

The dffits measure for each observation, which is a measure of the influence of a single data point on the predicted value of a model.

dffits_thresholdfloat

The threshold to determine if the influence of an observation is large. The threshold is 2 * sqrt(k / n).

Based on resid_studentized_external, uses results from leave-one-observation-out loop.

It is recommended that observations with dffits larger than a threshold of 2 sqrt{k / n} where k is the number of parameters, should be investigated.

Based on Wikipedia

dffits_internal

dffits measure for influence of an observation

based on resid_studentized_internal uses original results, no nobs loop

ess_press

Error sum of squares of PRESS residuals

hat_diag_factor

Factor of diagonal of hat_matrix used in influence

this might be useful for internal reuse h / (1 - h)

hat_matrix_diag

Diagonal of the hat_matrix for OLS

influence

Influence measure

matches the influence measure that gretl reports u * h / (1 - h) where u are the residuals and h is the diagonal of the hat_matrix

params_not_obsi

parameter estimates for all LOOO regressions

resid_press

PRESS residuals

resid_std

estimate of standard deviation of the residuals

resid_var

resid_studentized

Studentized residuals using variance from OLS

alias for resid_studentized_internal for compatibility with MLEInfluence. This uses sigma from original estimate and does not require leave one out loop

resid_studentized_external

Studentized residuals using LOOO variance

this uses sigma from leave-one-out estimates

requires leave one out loop for observations

resid_studentized_internal

Studentized residuals using variance from OLS

this uses sigma from original estimate does not require leave one out loop

resid_var

estimate of variance of the residuals

sigma2 = sigma2_OLS * (1 - hii)

where hii is the diagonal of the hat matrix

sigma2_not_obsi

error variance for all LOOO regressions

This is ‘mse_resid’ from each auxiliary regression.

uses results from leave-one-observation-out loop

Notes

One part of the results can be calculated without any auxiliary regression (some of which have the _internal postfix in the name). Other statistics require leave-one-observation-out (LOOO) auxiliary regression, and will be slower (mainly results with _external postfix in the name). For the auxiliary LOOO regression, only the required results are stored.

If the model is OLS or WLS and exog has full rank, then the LOOO results are computed from the closed form updates, e.g. Belsley, Kuh and Welsch (1980), without auxiliary regressions, and are fast also for large data sets.

For other models, such as subclasses of OLS or WLS, or if exog does not have full rank, using the LOOO measures is currently only recommended if the data set is not too large. One possible approach for LOOO measures would be to identify possible problem observations with the _internal measures, and then run the leave-one-observation-out only with observations that are possible outliers. (However, this is not yet available in an automated way.)

For WLS, the hat matrix, the studentized residuals, Cook’s distance, dffits and the LOOO measures are those of OLS on the whitened data, sqrt(w) * endog and sqrt(w) * exog, so a LOOO regression is a WLS without observation i. For positive weights, this matches R’s influence.measures for lm(..., weights=w). resid_press and influence stay on the scale of endog, and so does ess_press, which is the unweighted sum of squares of the PRESS residuals.

The weights of WLS are treated as precision weights, i.e. as inverse variances of the errors, and not as frequency weights. As in WLS.mse_resid, the estimate of the error variance and the residual degrees of freedom use the number of rows of the data and not the sum of the weights.

WLS.df_resid counts observations with a weight of zero, whereas R drops those cases. The hat matrix diagonal and the dfbeta of the other observations are the same as in R. For observations with a zero weight, the hat matrix diagonal, Cook’s distance, dfbeta and the studentized residuals are zero, but cov_ratio is not one. Measures that depend on the estimate of the error variance and the residual degrees of freedom differ from R. If there are n_pos observations with positive weights and k is the number of parameters, then Cook’s distance is larger than in R by the factor (nobs - k) / (n_pos - k) and the internally studentized residuals are larger by the square root of that factor. The other measures, i.e. the externally studentized residuals, dffits, dfbetas and cov_ratio, differ by similar amounts. They are the same as in R if the WLS model is estimated with only the observations that have positive weights.

Only OLS and WLS are supported. Results of other models, for example GLS with a non-trivial sigma or GLSAR, are not whitened and the measures are incorrect, without an error or warning. GLS without sigma is the same as OLS.

The leave-one-variable-out (LOVO) auxiliary regression are currently not used.

Methods

get_resid_studentized_external([sigma])

Calculate studentized residuals

plot_index([y_var, threshold, title, ax, idx])

Index plot for influence attributes

plot_influence([external, alpha, criterion, ...])

Plot of influence in regression.

summary_frame()

Creates a DataFrame with all available influence results

summary_table([float_fmt])

Create a summary table with all influence and outlier measures

Properties

cooks_distance

Cook's distance

cov_ratio

covariance ratio between LOOO and original

det_cov_params_not_obsi

determinant of cov_params of all LOOO regressions

dfbeta()

uses results from leave-one-observation-out loop

dfbetas()

uses results from leave-one-observation-out loop

dffits

dffits measure for influence of an observation

dffits_internal

dffits measure for influence of an observation

ess_press

Error sum of squares of PRESS residuals

hat_diag_factor

Factor of diagonal of hat_matrix used in influence

hat_matrix_diag

Diagonal of the hat_matrix for OLS

influence

Influence measure

params_not_obsi

parameter estimates for all LOOO regressions

resid_press

PRESS residuals

resid_std

estimate of standard deviation of the residuals

resid_studentized

Studentized residuals using variance from OLS

resid_studentized_external

Studentized residuals using LOOO variance

resid_studentized_internal

Studentized residuals using variance from OLS

resid_var

estimate of variance of the residuals

sigma2_not_obsi

error variance for all LOOO regressions