TimeSeriesCausality.jl
This is a Julia implementation of the Phase Slope Index and Granger Causality methods. Please refer to http://doc.ml.tu-berlin.de/causality for more information.
Outline
- TimeSeriesCausality.jl
- Phase Slope Index
- Granger Causality Estimation
- Granger method vs. Phase-Slope-Index
Functions
Phase Slope Index (PSI) estimation psi_est
:
TimeSeriesCausality.psi_est
— Functionpsi_est(data, seglen ; segshift, eplen, freqlist, method,
nboot, segave, subave, detrend)
calculates phase slope index (PSI)
Arguments
data::AbstractArray
: NxM array for N data points in M channelsseglen::Integer
: segment length (determines the frequency resolution). If definingfreqlist
,seglen
must be the same as sampling frequency.
optional arguments
segshift::Integer
: number of bins by which neighboring segments are shifted (default isseglen / 2
)eplen::Integer
: length of epochs (default is number of samples)freqlist::AbstractArray
: a UnitRange or 2D-Array where each column is a frequency band (default is full range). Note that the DC component (0th frequency of FFT) is discarded, andfreqlist
shall only include integer values.method::String
: standard deviation estimation method (default is"jackknife"
)subave::Bool
: iftrue
, subtract average across Cross Spectra segments (default isfalse
)segave::Bool
: iftrue
, average across Cross Spectra segments (default istrue
)nboot::Integer
: number of bootstrap resampling iterations (default is100
)detrend::Bool
: iftrue
, performs a 0th-order detrend across raw segments (default isfalse
)window::Function
: window function with interval length as sole necessary argument (default isHanning
)verbose::Bool
: iftrue
, warnings and info logs would be echoed. (default isfalse
)
Returns
psi::AbstractArray
: Phase Slope Index with shape(channel, channel, frequency bands)
psi_std::AbstractArray
: PSI estimated standard deviation with shape(channel, channel, frequency bands)
Granger Causality estimation granger_est
:
TimeSeriesCausality.granger_est
— Functiongranger_est(data, seglen; order, method, verbose)
Granger's method of causal relation approximation
Arguments
data::AbstractArray
: Nx2 array for N data points in 2 channels.seglen::Integer
: segment length.
optional arguments
method::String
: standard deviation estimation method (default is"jackknife"
)order::Int
: Model order. Assumed time delay order of interest (default isn_samples / 2
)verbose::Bool
: iftrue
, warnings and info logs would be echoed.
Returns
Grind::Float64
: Granger causality indexGrind_std::Float64
: estimated standard deviation of error
Internal variables:
- Covs: Concatenated covariance mats of different orders
- Acoef: Design (A) matrix coefficients
- Perr: Prediction Error
- Σ: Measures the accuracy of the autoregressive prediction
References:
- C. W. J. Granger (1969). Investigating causal relations by econometric models and cross-spectral methods, Econometrica, 37, 424-438.
- M. Ding et al. (2006). Granger Causality: Basic Theory and Application to Neuroscience available online: https://arxiv.org/abs/q-bio/0608035
Citation
Please cite the following paper if you use the PSI code in published work:
Nolte, G., Ziehe, A., Nikulin, V., Schlögl, A., Krämer, N., Brismar, T., & Müller, K.R. (2008), Robustly Estimating the Flow Direction of Information in Complex Physical Systems, Phys. Rev. Lett., 100, 234101.
Acknowledgement
This work was funded by the German Federal Ministry of Education and Research (BMBF) in the project ALICE III under grant ref. 01IS18049B.