Question

I want to get the OLS coefficients for an equation like:

y=a+ax1+ax2+...+ax8

I have the code below, but I just get 7 coefficients instead of 8. I was expecting 8 coefficients. Why this is happening?

yy = [498.0, 238.0, 339.0, 172.0, 310.0, 249.0, 195.0, 173.0, 332.0, 204.0]
xx = [[8.333334, 930397626.0, 322654980.0, 2, 161.0, 29.0, 1999.999, 12335088.0],
      [8.333334, 978809835.0, 927942625.0, 3, 85.0, 1.0, 1999.999, 12335088.0],
      [100.0, 1168151674.0, 309743797.0, 4, 208.0, 29.0, 1999.999, 12335088.0],
      [100.0, 903582453.0, 346402518.0, 4, 156.0, 30.0, 1999.999, 12335088.0],
      [8.333334, 930397626.0, 322654980.0, 4, 156.0, 30.0, 1999.999, 12335088.0]]

X = np.array(xx)
Y = np.array(yy)
results = sm.OLS(Y, X).fit()
print results.summary()



             coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
x1             6.2988      2.479      2.541      0.085        -1.592    14.189
x2         -1.108e-05   4.63e-06     -2.392      0.097     -2.58e-05  3.66e-06
x3         -2.061e-05   5.85e-06     -3.521      0.039     -3.92e-05 -1.98e-06
x4           523.1934    208.974      2.504      0.087      -141.854  1188.241
x5            33.2000     17.488      1.898      0.154       -22.455    88.855
x6          -545.1934    168.326     -3.239      0.048     -1080.881    -9.506
x7          3.675e-07   1.11e-07      3.307      0.045      1.39e-08  7.21e-07
const          0.0023      0.001      3.308      0.045      8.61e-05     0.004
Was it helpful?

Solution

You have 8 coefficients.

Assuming that your complete data look similar:

The last one is called const instead of x8 because that column doesn't have any variation and is identified as constant.

You can specify names for the parameters, or you can add a very small noise in one of observation of the last column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top