All functions below accept two objects with pairs of channels (ch1[i] of obj1 with ch2[i] of obj2, returning a matrix of pairs × epochs), or a single object with a list of channels (returning a channels × channels × epochs matrix).
Correlation and Cosine Similarity
The Pearson correlation of two signals is the cosine of the angle between the two mean-centered signal vectors:
The cosine similarity is the cosine of the angle between the (not centered) signal vectors:
\[
CS = \frac{x^T y}{\|x\| \times \|y\|}
\]
Both are in the range \([-1, 1]\): 1 for proportional signals, 0 for orthogonal (uncorrelated) signals and −1 for opposite signals. For signals with a mean of zero (e.g. high-pass filtered EEG), they are nearly equal.
where: \(\vartheta_x\), \(\vartheta_y\) are the instantaneous phases (obtained using the Hilbert transform), \(n\) is the number of samples.
PS is 1 for signals in phase, −1 for signals in anti-phase and 0 for random phase differences (or a constant difference of ±π/2). The phases require narrow-band signals; here the theta band:
The Phase Slope Index (PSI; Nolte et al., 2008) estimates the direction of interaction from the slope of the phase of coherency across frequencies: if one signal leads the other by a fixed time delay, the phase difference grows linearly with frequency. PSI is insensitive to mixtures of independent sources (e.g. volume conduction) and does not require the phase spectrum to be linear.
psi() returns pairs of values (ch1 → ch2, ch2 → ch1) for each channel pair and epoch, calculated over the frequency range flim; a positive value of ch1 → ch2 means that ch1 leads ch2:
The values are small and change sign between epochs; the significance of PSI is usually assessed by normalizing it by its standard deviation (estimated e.g. with the jackknife method) or with surrogate data.
Mutual Information
Mutual information (MI) measures the dependence between two variables: the amount of information about one variable obtained by observing the other. Unlike correlation, it captures non-linear dependencies; it is 0 for independent variables.
mi =mutual_information(e10; ch ="eeg")plot_matrix(mi[:, :, 1]; xlabels =labels(e10), ylabels =labels(e10), title ="Mutual information, epoch 1")
Granger Causality
Signal \(x\)Granger-causes signal \(y\) if the past of \(x\) improves the prediction of \(y\) beyond what the past of \(y\) alone provides. Both are modeled with a vector autoregressive (VAR) model; the Granger causality is the log ratio of the residual variance of \(y\) predicted from its own past to the residual variance when the past of \(x\) is added.
granger() fits the VAR model (order chosen by BIC, up to maxorder) to all pairs of the selected channels and returns the Granger causality (gc[i, j]: i → j), the F statistic and p-values (also FDR-adjusted):
With 100 epochs of 2560 samples, even very small Granger causality values are statistically significant (all adjusted p-values are < 0.001), so the significance alone is not informative; the BIC chose the maximum order (20 samples, 78 ms), so a higher maxorder could be tested.
granger_spectral() decomposes the Granger causality by frequency:
Tip: in the scalp EEG, volume conduction and the common reference produce spurious Granger causality; it is more reliable for source-space or current source density (Laplacian) data. See the notes in the documentation of granger().
References
Nolte, G., Ziehe, A., Nikulin, V. 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. Physical Review Letters, 100(23), 234101.
Ding, M., Chen, Y., & Bressler, S. L. (2006). Granger causality: basic theory and application to neuroscience. In: Handbook of Time Series Analysis. Wiley.