I have two nested OLSes:
>>> f1 = 'Y ~ np.log(X + 1) + X + np.log(X) + np.exp(-X) + np.sqrt(X) + np.power(X, 4)'
>>> f2 = 'Y ~ np.log(X + 1) + X + np.log(X) + np.exp(-X) + np.sqrt(X) + np.power(X, 4) + np.power(X, -1) + np.power(X, -2) + np.power(X, 2) + np.power(X, 3) + np.exp(X) + np.power(X, -3)'
When analysing this dataset (17M) with statsmodels I have discovered that the bigger model has larger sum of squared residuals (SSR):
>>> ssr1 = sm.ols(formula=f1, data=DF).fit().ssr
>>> ssr2 = sm.ols(formula=f2, data=DF).fit().ssr
>>> ssr1 - ssr2
-1037.4640076523647
Same happens with sklearn.
As OLS is expected to minimize SSR, I am surprised that inclusion of extra regressors increased it. As regressors of f2
are a superset of those of f1
, ssr2
may be at least as small as ssr1
by simply setting coefficients of all extra parameters to 0.
So why OLS fails to minimize SSR? Is it some numerical artefact which may be ignored or something more serious?
VIF for f1
:
np.log(X + 1) 13567.4057637
X 11541.1910286
np.log(X) 446.977604585
np.exp(-X) 38.674353333
np.sqrt(X) 53077.4595776
np.power(X, 4) 34.2445023554
VIF for f2
:
np.log(X + 1) 28942.1737842
X 180304.260711
np.log(X) 121.384763923
np.exp(-X) 22.2770600233
np.sqrt(X) 319544.359507
np.power(X, 4) 4606.23688654
np.power(X, -1) 113.759877386
np.power(X, -2) 2452.98781276
np.power(X, 2) 19895.5099527
np.power(X, 3) 24609.1808767
np.exp(X) 3.45225568589
np.power(X, -3) 1605.22900297