Variance Inflation Factor in Python : <p>I'm trying to calculate the variance inflation factor (VIF) for each column in a simple dataset in python: </p>

<pre><code>a b c d
1 2 4 4
1 2 6 3
2 3 7 4
3 2 8 5
4 1 9 4
</code></pre>

<p>I have already done this in R using the vif function from the <a href="https://cran.r-project.org/web/packages/usdm/usdm.pdf" rel="noreferrer">usdm library</a> which gives the following results:</p>

<pre><code>a &lt;- c(1, 1, 2, 3, 4)
b &lt;- c(2, 2, 3, 2, 1)
c &lt;- c(4, 6, 7, 8, 9)
d &lt;- c(4, 3, 4, 5, 4)

df &lt;- data.frame(a, b, c, d)
vif_df &lt;- vif(df)
print(vif_df)

Variables   VIF
   a        22.95
   b        3.00
   c        12.95
   d        3.00
</code></pre>

<p>However, when I do the same in python using the <a href="http://statsmodels.sourceforge.net/devel/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html" rel="noreferrer">statsmodel vif function</a>, my results are:</p>

<pre><code>a = [1, 1, 2, 3, 4]
b = [2, 2, 3, 2, 1]
c = [4, 6, 7, 8, 9]
d = [4, 3, 4, 5, 4]

ck = np.column_stack([a, b, c, d])

vif = [variance_inflation_factor(ck, i) for i in range(ck.shape[1])]
print(vif)

Variables   VIF
   a        47.136986301369774
   b        28.931506849315081
   c        80.31506849315096
   d        40.438356164383549
</code></pre>

<p>The results are vastly different, even though the inputs are the same. In general, results from the statsmodel VIF function seem to be wrong, but I'm not sure if this is because of the way I am calling it or if it is an issue with the function itself. </p>

<p>I was hoping someone could help me figure out whether I was incorrectly calling the statsmodel function or explain the discrepancies in the results. If it's an issue with the function then are there any VIF alternatives in python?</p>
