How to implement Vector Auto-Regression in Python?
Asked Answered
O

1

6

I want to implement vector autoregression in python. My data is saved as a list of 3 lists. I found this - http://statsmodels.sourceforge.net/stable/vector_ar.html#var, but could not figure out the proper way to implement.

Suppose tsdata - a list of 3 lists of length 100 each, is my data. I tried

varmodel = ts.VAR(tsdata)

results = varmodel.fit(maxlags=5, ic='aic')

But the above is not working.

Update: I have changed the list of lists to a column stack according to suggestions below. It is working fine now. So tsdata, which was a list of lists is changed to

tsdata  = np.column_stack(tsdata)
Olivine answered 21/8, 2013 at 4:9 Comment(5)
Please elaborate on "it is not working." When I execute VAR(data_as_lists).fit(maxlags=5, ic='aic').summary() I get output -- unclear whether said output is sensible. Even so, your data should probably be a pandas DataFrame with a DatetimeIndex.Cleodell
my guess is that it's because a list of list has the wrong shape, variables are in rows and observation in columns, when it is converted to an array. try np.column_stack on the list of listsTerryn
Where is tsdata in your code? You mention it in the question, but all I see is resid.Francinafrancine
It should have been tsdata in the code as well. Corrected the typo. Will try np.column_stack.Olivine
Philip, thanks for your suggestions. It worked.Olivine
H
0

Changing the list of lists to a column stack (as @Josef suggests) may solve your problem. For that, one might use numpy.column_stack as follows

tsdata  = np.column_stack(tsdata)
Hengelo answered 22/5, 2021 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.