statsmodels.stats.multicollinearity.vif_ridge#
- statsmodels.stats.multicollinearity.vif_ridge(data, pen_factors, *, is_moment=False, has_constant='raise')[source]#
Variance inflation factors for ridge regression
The penalization is on the standardized variables, so the VIF depend on the correlation matrix of the variables. The ridge factors are added to the diagonal of the correlation matrix.
- Parameters:
- dataarray_like
The explanatory variables with observations in rows and variables in columns. The data should not include a constant, see has_constant. If is_moment is True, then this is a square covariance or correlation matrix of the variables.
- pen_factorsarray_like
One-dimensional array of non-negative ridge penalization factors.
- is_momentbool,
optional If True, then data is a symmetric, positive semi-definite moment matrix of the variables instead of the observations. The default is False.
- has_constant{“raise”, “skip”},
optional How to treat constant columns, which have zero variance. If “raise”, the default, then a ValueError is raised. If “skip”, then the constant columns are ignored and the corresponding elements of the result are NaN.
- Returns:
- Raises:
ValueErrorIf data contains missing or infinite values, if data has constant columns and has_constant is “raise”, if a penalization factor is negative, or if is_moment is True and data is not a valid moment matrix.
See also
vifVIF of regression without penalization.
Notes
With the correlation matrix \(R\) and the penalization factor \(k\), the VIF of ridge regression are the diagonal elements of \((R + k I)^{-1} R (R + k I)^{-1}\). The result for \(k=0\) is the same as that of
vif. The correlation matrix is singular if some variables are exactly collinear, in which case the penalization factors have to be positive. A factor of zero is handled as invif.All penalization factors are computed with one eigenvalue decomposition of the correlation matrix.
References
[1]Marquardt, D. W. 1970. Generalized inverses, ridge regression, biased linear estimation, and nonlinear estimation. Technometrics 12 (3): 591-612.
Examples
The ridge penalization removes most of the collinearity of the Longley data. The penalization factors are added to the diagonal of the correlation matrix, so they are on the scale of standardized variables. The columns are standardized first to make this explicit, the result is the same as for the original data, which vif_ridge standardizes through the correlation matrix. The row with a penalization factor of zero contains the VIF without penalization.
>>> import statsmodels.api as sm >>> from statsmodels.stats.api import vif_ridge >>> exog = sm.datasets.longley.load_pandas().exog >>> exog_std = (exog - exog.mean()) / exog.std() >>> vif_ridge(exog_std, [0, 0.01, 0.1]).round(1) GNPDEFL GNP UNEMP ARMED POP YEAR 0.00 135.5 1788.5 33.6 3.6 399.2 759.0 0.01 17.2 3.5 2.7 2.1 13.8 10.0 0.10 0.8 0.3 1.5 1.2 0.6 0.2