spreg.vif

spreg.vif(reg)[source]

Calculates the variance inflation factor for each independent variable. For the ease of indexing the results, the constant is currently included. This should be omitted when reporting the results to the output text. [Gre03]

Parameters
regregression object

output instance from a regression model

Returns
vif_resultlist of tuples

each tuple includes the vif and the tolerance, the order of the variables corresponds to their order in the reg.x matrix

Examples

>>> import numpy as np
>>> import libpysal
>>> from libpysal import examples
>>> import spreg
>>> from spreg import OLS

Read the DBF associated with the Columbus data.

>>> db = libpysal.io.open(examples.get_path("columbus.dbf"),"r")

Create the dependent variable vector.

>>> y = np.array(db.by_col("CRIME"))
>>> y = np.reshape(y, (49,1))

Create the matrix of independent variables.

>>> X = []
>>> X.append(db.by_col("INC"))
>>> X.append(db.by_col("HOVAL"))
>>> X = np.array(X).T

Run an OLS regression.

>>> reg = OLS(y,X)

Calculate the variance inflation factor (VIF). >>> testresult = spreg.vif(reg)

Select the tuple for the income variable.

>>> incvif = testresult[1]

Print the VIF for income.

>>> print("%12.12f"%incvif[0])
1.333117497189

Print the tolerance for income.

>>> print("%12.12f"%incvif[1])
0.750121427487

Repeat for the home value variable.

>>> hovalvif = testresult[2]
>>> print("%12.12f"%hovalvif[0])
1.333117497189
>>> print("%12.12f"%hovalvif[1])
0.750121427487