6.11.5. statsmodels.sandbox.tsa.movstat¶
using scipy signal and numpy correlate to calculate some time series statistics
original developer notes
see also scikits.timeseries (movstat is partially inspired by it) added 2009-08-29 timeseries moving stats are in c, autocorrelation similar to here I thought I saw moving stats somewhere in python, maybe not)
TODO
moving statistics - filters don’t handle boundary conditions nicely (correctly ?) e.g. minimum order filter uses 0 for out of bounds value -> append and prepend with last resp. first value - enhance for nd arrays, with axis = 0
Note: Equivalence for 1D signals >>> np.all(signal.correlate(x,[1,1,1],’valid’)==np.correlate(x,[1,1,1])) True >>> np.all(ndimage.filters.correlate(x,[1,1,1], origin = -1)[:-3+1]==np.correlate(x,[1,1,1])) True
# multidimensional, but, it looks like it uses common filter across time series, no VAR ndimage.filters.correlate(np.vstack([x,x]),np.array([[1,1,1],[0,0,0]]), origin = 1) ndimage.filters.correlate(x,[1,1,1],origin = 1)) ndimage.filters.correlate(np.vstack([x,x]),np.array([[0.5,0.5,0.5],[0.5,0.5,0.5]]), origin = 1)
>>> np.all(ndimage.filters.correlate(np.vstack([x,x]),np.array([[1,1,1],[0,0,0]]), origin = 1)[0]==ndimage.filters.correlate(x,[1,1,1],origin = 1))
True
>>> np.all(ndimage.filters.correlate(np.vstack([x,x]),np.array([[0.5,0.5,0.5],[0.5,0.5,0.5]]), origin = 1)[0]==ndimage.filters.correlate(x,[1,1,1],origin = 1))
update 2009-09-06: cosmetic changes, rearrangements