{"action":"created","issue":{"url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2376","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2376/labels{/name}","comments_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2376/comments","events_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2376/events","html_url":"https://github.com/statsmodels/statsmodels/issues/2376","id":71664527,"number":2376,"title":"statsmodels.stats.outliers_influence.variance_inflation_factor is wrong","user":{"login":"littlecuocuo","id":12158086,"avatar_url":"https://avatars.githubusercontent.com/u/12158086?v=3","gravatar_id":"","url":"https://api.github.com/users/littlecuocuo","html_url":"https://github.com/littlecuocuo","followers_url":"https://api.github.com/users/littlecuocuo/followers","following_url":"https://api.github.com/users/littlecuocuo/following{/other_user}","gists_url":"https://api.github.com/users/littlecuocuo/gists{/gist_id}","starred_url":"https://api.github.com/users/littlecuocuo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/littlecuocuo/subscriptions","organizations_url":"https://api.github.com/users/littlecuocuo/orgs","repos_url":"https://api.github.com/users/littlecuocuo/repos","events_url":"https://api.github.com/users/littlecuocuo/events{/privacy}","received_events_url":"https://api.github.com/users/littlecuocuo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/comp-regression","name":"comp-regression","color":"ededed"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/comp-stats","name":"comp-stats","color":"ededed"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/prio-high","name":"prio-high","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/statsmodels/statsmodels/milestones/9","html_url":"https://github.com/statsmodels/statsmodels/milestones/0.8","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/milestones/9/labels","id":930392,"number":9,"title":"0.8","description":"","creator":{"login":"josef-pkt","id":440735,"avatar_url":"https://avatars.githubusercontent.com/u/440735?v=3","gravatar_id":"","url":"https://api.github.com/users/josef-pkt","html_url":"https://github.com/josef-pkt","followers_url":"https://api.github.com/users/josef-pkt/followers","following_url":"https://api.github.com/users/josef-pkt/following{/other_user}","gists_url":"https://api.github.com/users/josef-pkt/gists{/gist_id}","starred_url":"https://api.github.com/users/josef-pkt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josef-pkt/subscriptions","organizations_url":"https://api.github.com/users/josef-pkt/orgs","repos_url":"https://api.github.com/users/josef-pkt/repos","events_url":"https://api.github.com/users/josef-pkt/events{/privacy}","received_events_url":"https://api.github.com/users/josef-pkt/received_events","type":"User","site_admin":false},"open_issues":96,"closed_issues":2,"state":"open","created_at":"2015-01-11T13:17:39Z","updated_at":"2015-04-28T18:46:24Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-04-28T18:20:42Z","updated_at":"2015-04-29T01:47:41Z","closed_at":null,"body":"\r\nIn the source code, \r\nthe line below doesnt take the constant term (interception) into account. \r\n r_squared_i = OLS(x_i, x_noti).fit().rsquared\r\n\r\n\r\nFor example, data is:\r\n                     mpg cyl  disp  hp drat    wt  qsec vs am gear carb\r\nMazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4\r\nMazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4\r\nDatsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1\r\nHornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1\r\nHornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2\r\nValiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1\r\nDuster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4\r\nMerc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2\r\nMerc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2\r\nMerc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4\r\nMerc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4\r\nMerc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3\r\nMerc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3\r\nMerc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3\r\nCadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4\r\nLincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4\r\nChrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4\r\nFiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1\r\nHonda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2\r\nToyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1\r\nToyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1\r\nDodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2\r\nAMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2\r\nCamaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4\r\nPontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2\r\nFiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1\r\nPorsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2\r\nLotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2\r\nFord Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4\r\nFerrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6\r\nMaserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8\r\nVolvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2\r\n\r\n\r\nFor regression, \r\nfit <- lm(mpg~disp+hp+wt+drat, data=mtcars)\r\nvif( fit ) should give \r\n    disp       hp       wt     drat \r\n8.209402 2.894373 5.096601 2.279547 \r\n\r\nBut vif( df[:, ['disp', 'hp', 'wt','drat'].values(), 0 )   will give 37.1154 instead of 8.209"},"comment":{"url":"https://api.github.com/repos/statsmodels/statsmodels/issues/comments/97281897","html_url":"https://github.com/statsmodels/statsmodels/issues/2376#issuecomment-97281897","issue_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2376","id":97281897,"user":{"login":"josef-pkt","id":440735,"avatar_url":"https://avatars.githubusercontent.com/u/440735?v=3","gravatar_id":"","url":"https://api.github.com/users/josef-pkt","html_url":"https://github.com/josef-pkt","followers_url":"https://api.github.com/users/josef-pkt/followers","following_url":"https://api.github.com/users/josef-pkt/following{/other_user}","gists_url":"https://api.github.com/users/josef-pkt/gists{/gist_id}","starred_url":"https://api.github.com/users/josef-pkt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josef-pkt/subscriptions","organizations_url":"https://api.github.com/users/josef-pkt/orgs","repos_url":"https://api.github.com/users/josef-pkt/repos","events_url":"https://api.github.com/users/josef-pkt/events{/privacy}","received_events_url":"https://api.github.com/users/josef-pkt/received_events","type":"User","site_admin":false},"created_at":"2015-04-29T01:47:41Z","updated_at":"2015-04-29T01:47:41Z","body":"because of numerical precision noise, inv with singular x might not fail\r\n\r\nexample: last column is sum of two previous columns\r\n\r\n```\r\n>>> print(np.diag(np.linalg.inv(np.corrcoef(x, rowvar=0))))\r\n[  1.92082630e+00   1.03596594e+17   1.51839078e+17   4.85464792e+17]\r\n>>> np.corrcoef(x, rowvar=0)\r\narray([[ 1.        ,  0.67527981,  0.68024677,  0.69237878],\r\n       [ 0.67527981,  1.        ,  0.91704006,  0.97481165],\r\n       [ 0.68024677,  0.91704006,  1.        ,  0.98288449],\r\n       [ 0.69237878,  0.97481165,  0.98288449,  1.        ]])\r\n>>> np.linalg.eigvals(np.corrcoef(x, rowvar=0))\r\narray([  3.48044421e+00,   4.36352260e-01,   8.32035298e-02,\r\n        -8.45900126e-17])\r\n>>> np.linalg.matrix_rank(np.corrcoef(x, rowvar=0))\r\n3\r\n```\r\n\r\nusing pinv is very misleading for interpretation as vif (they don't indicate singularity because of regularization)\r\n\r\n```\r\n>>> print(np.diag(np.linalg.pinv(np.corrcoef(x, rowvar=0))))\r\n[ 1.9208263   6.59928679  5.82713172  0.25052213]\r\n```\r\n\r\n"}}