Monday, May 23, 2011

5/6 - 5/20: Getting Acclimated and VARRresults.reorder() function

Just finished up the official first two weeks of GSoC. I spent most of the first week attempting to get a feel for how all of the time series methods for statsmodels are organized. Once I felt comfortable within the VAR package, I began work on adding a reorder() function to the VARResults class, which allows the user to specify the order of the endogenous variables in a vector auto-regression system. While the order of the variables plays no role in estimating the system, if the shocks are to be identified, variable order is used to specify the within period impact of shocks to individual variables in the system.

For example, let us say that we have a 3-variable VAR system, originally ordered realGDP, realcons, and realinv, contained within the VARResults class 'res'. Reordering the variables in the system is as simple as follows:

In [1]: import scikits.statsmodels.api as sm In [2]: import numpy as np In [3]: mdata = sm.datasets.macrodata.load().data In [4]: mdata = mdata[['realgdp','realcons','realinv']] In [5]: names = mdata.dtype.names In [6]: data = mdata.view((float,3)) In [7]: from scikits.statsmodels.tsa.api import VAR In [8]: res = VAR(data, names=names).fit(maxlags=3,ic=None) In [9]: res.names Out[9]: ['realgdp', 'realcons', 'realinv'] In [10]: res_re = res.reorder(['realinv','realcons','realgdp']) In [11]: res_re.names Out[11]: ['realinv', 'realcons', 'realgdp']

The reorder function reuses all of the results from the original VAR class, but rearranges them to be in line with the new system. If working with large a # of observations, the computational advantage becomes useful pretty quickly. For example, with a 100,000 observation system with three variables, re-estimating the system after changing the variable order took 3.37 seconds, while using the reorder function took 0.57 seconds.

In the next few weeks I am planning on adding more impulse response function error band estimation methods. The current package only includes analytical error bands.