New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Var Models #537
Comments
you are mixing working with pandas and working with recarrays. The doc example uses recarrays throughout. I cannot replicate your example because of an exception in date parsing. Also, it is better if you include the full traceback, since I don't know where your exception occurs. If I remove the date parsing, then it works if I convert pandas to recarray
But I think it would be better to work (or make it to work) with pandas all the way. Aside: the VAR documentation hasn't been updated in a while, and doesn't take advantage of the pandas integration, or provide examples for it, I guess. |
Thank you. Traceback: names = mdata.dtype.names Try this for data set: Can I use pandas for var model? |
I think so, but it needs a datetime index. I get an exception with an integer index. (I don't have a timeseries for pandas handy right now.) otherwise you can always use
I don't know what's the substitute for names argument. |
this needs checking for 0.5 What's the status? Do we have pandas support in VAR? |
I don't see why not. If you give a pandas DataFrame to the timeseries models then they expect a DatetimeIndex https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/base/tsa_model.py#L25 The names are done automatically now like the other models. It uses the fields from a recarray or the column names from a DataFrame. |
If it works and we have at least a smoke test, then we can close this issue. (I'm just trying to figure out what the status with some of the issues is.) |
I think this should be covered. Looks like this was a problem with trying to use a DataFrame as a structured array by following the docs not something internal. Maybe leave it open as a reminder to update the docs? Thanks for the maintenance work. Am hoping to be able to pitch in in March after I meet a few deadlines and get a release out the door. We were bad about bug-fixes / features in this release cycle (again) and have some stuff that needs to be released (and, of course, some stuff that's not and might not be ready). |
DOC: Update VAR docs. Closes statsmodels#537.
I have a file fr1.txt. A sample of data:
date, price1,price2,price3
2009-11-09 11:05:21pm,3.2,31.4,22.1
2009-11-09 11:07:23pm,40.5,35.8,38.2
2009-11-09 11:43:10pm,11.9,32.1,58.8
2009-11-10 12:22:07am,22.7,65.9,31.8
2009-11-10 1:43:11am,98.32,54.3,21.5
2009-11-10 2:28:59am,95.2,33.4,21.9
2009-11-11 12:33:39am,51.7,32.1,16.9
2009-11-11 12:34:26am,21.5,15.8,10.2
2009-11-11 12:40:16am,31.4,2.4,21.6
2009-11-11 12:45:22am,5.6,2.2,41.9
The code (using the example of here http://statsmodels.sourceforge.net/devel/vector_ar.html#var)
import numpy as np
import pandas as pd
import datetime as datetime
from statsmodels.tsa.api import VAR, SVAR
import matplotlib.pyplot as plt
import statsmodels.api as sm
parse = lambda x: datetime.datetime.strptime(x, '%Y-%m-%d')
dframe = pd.read_table("fr1.txt", delimiter=",", index_col=0, parse_dates=True, date_parser=parse)
ts = dframe.resample("D")
mdata = ts[['price1','price2','price3']]
names = mdata.dtype.names
data = mdata.view((float,3))
data = np.diff(np.log(data), axis=0)
model = sm.tsa.VAR(data, names=names)
results = model.fit(2)
results.summary()
model.plot()
plt.show()
The error:
AttributeError: 'DataFrame' object has no attribute 'dframe'
The text was updated successfully, but these errors were encountered: