Ricardo Cavalheiro
Ricardo Cavalheiro

Reputation: 11

error - Multiple Regression OLS class

I having problem to adjust with ols class the equation y = b0 + b1x1 + b2x2

The code:

xs = numpy.loadtxt('teste.csv', skiprows=1, dtype=float, delimiter=';', 
     usecols=(0,1))

y = log(xs[:,0])
x = 1/xs[:,1]
x2 = (1/xs[:,1])**2

mymodel = ols.ols(y,x,'y',['x1', 'x2'])
mymodel.summary()`

I got this error:

print '''% -5s          % -5.6f     % -5.6f     % -5.6f     % -5.6f''' % tuple([self.x_varnm[i],self.b[i],self.se[i],self.t[i],self.p[i]])
IndexError: index out of bounds

Someone can help me?

Upvotes: 1

Views: 121

Answers (1)

Jaime
Jaime

Reputation: 67457

Try defining your x as:

x = 1/xs[:,1:2] # slice to keep (n, 1) shape
x2 = (1/xs[:,1:2])**2
x = np.hstack((x, x2))

You are telling ols to expect a two column matrix for x, but are passing a single one in, hence the error.

Upvotes: 1

Related Questions