4.8.10.1.3. statsmodels.tsa.varma_process.lagmat¶
-
statsmodels.tsa.varma_process.
lagmat
(x, maxlag, trim='forward', original='ex')[source]¶ create 2d array of lags
Parameters: x : array_like, 1d or 2d
data; if 2d, observation in rows and variables in columns
maxlag : int or sequence of ints
all lags from zero to maxlag are included
trim : str {‘forward’, ‘backward’, ‘both’, ‘none’} or None
- ‘forward’ : trim invalid observations in front
- ‘backward’ : trim invalid initial observations
- ‘both’ : trim invalid observations on both sides
- ‘none’, None : no trimming of observations
original : str {‘ex’,’sep’,’in’}
‘ex’ : drops the original array returning only the lagged values.
‘in’ : returns the original array and the lagged values as a single array.
- ‘sep’ : returns a tuple (original array, lagged values). The original
array is truncated to have the same number of rows as the returned lagmat.
Returns: lagmat : 2d array
array with lagged observations
y : 2d array, optional
Only returned if original == ‘sep’
Notes
TODO: * allow list of lags additional to maxlag * create varnames for columns
Examples
>>> from statsmodels.tsa.tsatools import lagmat >>> import numpy as np >>> X = np.arange(1,7).reshape(-1,2) >>> lagmat(X, maxlag=2, trim="forward", original='in') array([[ 1., 2., 0., 0., 0., 0.], [ 3., 4., 1., 2., 0., 0.], [ 5., 6., 3., 4., 1., 2.]])
>>> lagmat(X, maxlag=2, trim="backward", original='in') array([[ 5., 6., 3., 4., 1., 2.], [ 0., 0., 5., 6., 3., 4.], [ 0., 0., 0., 0., 5., 6.]])
>>> lagmat(X, maxlag=2, trim="both", original='in') array([[ 5., 6., 3., 4., 1., 2.]])
>>> lagmat(X, maxlag=2, trim="none", original='in') array([[ 1., 2., 0., 0., 0., 0.], [ 3., 4., 1., 2., 0., 0.], [ 5., 6., 3., 4., 1., 2.], [ 0., 0., 5., 6., 3., 4.], [ 0., 0., 0., 0., 5., 6.]])