Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fit an ARMAX model using statsmodels

How do I use the statsmodels ARMA process to fit a difference equation of the form.

y[k] = - a1 * y[k-1] + b0 * u[k] + b1 * u[k-1] + c0 * e[k] + c1 * e[k-1]

I'm not shure how to set up the exog matrix. E.g.

import statsmodels.api as sm
# some stupid data

y = np.random.randn(100)
u = np.ones((100,2))
armax = sm.tsa.ARMA(y, order=(1, 1), exog=u).fit()

results in

ValueError: could not broadcast input array from shape (2) into shape (3)

It's probably easy to solve but I'm new to the field.

Thanks.

(I'm using statsmodels 0.6)

like image 877
P3trus Avatar asked Nov 21 '14 08:11

P3trus


1 Answers

The issue here is that you're passing two constant columns, then telling fit to add another constant column with trend='nc'. Admittedly, we should fail more gracefully here, but you need to try something like

u = np.random.randn(100, 2)

Instead of the constant exog.

like image 183
jseabold Avatar answered Sep 18 '22 15:09

jseabold