validmind.VarianceInflationFactor
VarianceInflationFactor
@tags('model_diagnosis', 'multicollinearity', 'visualization', 'statsmodels')
@tasks('regression')
defVarianceInflationFactor(model:validmind.vm_models.VMModel,vif_threshold:float=10.0,moderate_vif_threshold:float=5.0,condition_number_threshold:float=30.0) → Tuple[Dict[str, pd.DataFrame], go.Figure, bool, validmind.vm_models.RawData]:
Detects multicollinearity among the regressors of a linear regression model using the variance inflation factor (VIF) and the condition number of the design matrix.
Purpose
Multicollinearity — regressors that carry nearly the same information — inflates the standard errors of the coefficients, makes their signs and sizes unstable, and makes the contribution of each regressor impossible to separate. The model can still predict well, which is why this needs a dedicated check: it is invisible in fit metrics such as R².
Test Mechanism
For each regressor j (excluding the intercept), the VIF is 1 / (1 - R²_j), where R²_j is the R² of regressing that column on all other columns of the design matrix. A VIF of 5 means the variance of the coefficient is five times what it would be with uncorrelated regressors. Each regressor is labelled OK, Moderate (>= moderate_vif_threshold) or Severe (>= vif_threshold).
The condition number is computed on the design matrix with every column scaled to unit length (Belsley's scaling), so it does not depend on the units of the regressors; values above condition_number_threshold (30 by convention) indicate harmful collinearity.
The test passes when no regressor reaches vif_threshold and the scaled condition number is below condition_number_threshold.
Signs of High Risk
- One or more regressors with a VIF at or above 10.
- Pairs of regressors with similarly high VIFs, pointing to two variables that measure the same thing.
- A scaled condition number above 30.
Strengths
- Quantifies multicollinearity per regressor, so the variables involved are identified.
- Independent of the units of the regressors (condition number is scaled).
- Works on the model's own design matrix, including transformed and dummy-coded terms.
Limitations
- Requires a statsmodels OLS model.
- Dummy columns of one categorical variable are assessed separately; a generalized VIF would assess them together.
- VIF identifies collinearity but not which of the collinear variables to keep — that is a modelling judgement.