pyeeg.utils.lag_matrix

pyeeg.utils.lag_matrix(data, lag_samples=(-1, 0, 1), filling=nan, drop_missing=False)

Helper function to create a matrix of lagged time series.

The lag can be arbitrarily spaced. Check other functions to create series of lags whether they are contiguous or sparsely spanning a time window lag_span() and lag_sparse().

Parameters:
  • data (ndarray (nsamples x nfeats)) – Multivariate data

  • lag_samples (list) – Shift in _samples_ to be applied to data. Negative shifts are lagged in the past, positive shits in the future, and a shift of 0 represents the data array as it is in the input data.

  • filling (float) – What value to use to fill entries which are not defined (Default: NaN).

  • drop_missing (bool) – Whether to drop rows where filling occured.

Returns:

lagged – Matrix of lagged time series.

Return type:

ndarray (nsamples_new x nfeats*len(lag_samples))

Raises:

ValueError – If filling is set by user and drop_missing is True (it should be one or the other, the error is raised to avoid this confusion by users).

Example

>>> data = np.asarray([[1,2,3,4,5,6],[7,8,9,10,11,12]]).T
>>> out = lag_matrix(data, (0,1))
>>> out
array([[ 1.,  7.,  2.,  8.],
        [ 2.,  8.,  3.,  9.],
        [ 3.,  9.,  4., 10.],
        [ 4., 10.,  5., 11.],
        [ 5., 11.,  6., 12.],
        [ 6., 12., nan, nan]])