statsmodels.tsa.tsatools.lagmat2ds#

statsmodels.tsa.tsatools.lagmat2ds(x, maxlag0, maxlagex=None, dropex=0, trim='forward', use_pandas=False)[source]#

Generate lagmatrix for 2d array, columns arranged by variables

Parameters:
xndarray, Series, or DataFrame

Data, 1d or 2d. Observations in rows and variables in columns.

maxlag0int

The first variable all lags from zero to maxlag are included.

maxlagexint, optional

The max lag for all other variables all lags from zero to maxlag are included. If None, defaults to maxlag0.

dropexint, optional

Exclude first dropex lags from other variables. For all variables, except the first, lags from dropex to maxlagex are included.

trim{‘forward’, ‘backward’, ‘both’, ‘none’}, optional

The trimming method to use.

  • ‘forward’ : trim invalid observations in front.

  • ‘backward’ : trim invalid initial observations.

  • ‘both’ : trim invalid observations on both sides.

  • ‘none’ : no trimming of observations.

use_pandasbool, optional

If true, returns a DataFrame when the input is a pandas Series or DataFrame. If false, return numpy ndarrays.

Returns:
ndarray or DataFrame

The array with lagged observations, columns ordered by variable. A DataFrame is returned if x is a pandas Series or DataFrame and use_pandas is True.

Notes

Inefficient implementation for unequal lags, implemented for convenience.