Other Connectivity Measures

Initialize NeuroAnalyzer
using NeuroAnalyzer
using CairoMakie
CairoMakie.activate!(type = "png")
# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of
# NeuroAnalyzer figures: remove it
delete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)
using DataFrames
using Statistics
NeuroAnalyzer.progress_bar = false

# Makie figure and axis settings matching NeuroAnalyzer plots
fig_size = (900, 450)
ax_style = (titlesize = 18,
            xlabelsize = 18,
            ylabelsize = 18,
            xticklabelsize = 12,
            yticklabelsize = 12,
            xticks = LinearTicks(10),
            xminorticksvisible = true,
            xminorticks = IntervalsBetween(10),
            xautolimitmargin = (0, 0),
            yautolimitmargin = (0.1, 0.1))

# resting-state EEG, EEG channels only, 10-second epochs
eeg = load_neuro("files/eeg/eeg.hdf")
eeg = keep_channel(eeg; ch = "eeg")
e10 = epoch(eeg; ep_len = 10)
# theta band (4-8 Hz): the dominant rhythm of this recording
e10_theta = NeuroAnalyzer.filter(e10;
                                 ch = "eeg",
                                 fprototype = :butterworth,
                                 ftype = :bp,
                                 cutoff = (4, 8),
                                 order = 4)
# channel pairs: ch1[i] with ch2[i]
ch1 = ["Fp1", "C3", "O1"]
ch2 = ["Fp2", "C4", "O2"]
pairs_lbl = ch1 .* "-" .* ch2
avg(x) = vec(mean(x; dims = 2))

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:

\[ r_{xy} = \frac{(x - \bar{x})^T (y - \bar{y})}{\|x - \bar{x}\| \times \|y - \bar{y}\|} \]

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.

cr = corr(e10, e10; ch1 = ch1, ch2 = ch2)
cs = cosim(e10, e10; ch1 = ch1, ch2 = ch2)
DataFrame(pair = pairs_lbl,
          correlation = avg(cr),
          cosine_similarity = avg(cs))
3×3 DataFrame
Row pair correlation cosine_similarity
String Float64 Float64
1 Fp1-Fp2 -0.0163053 -0.0145604
2 C3-C4 0.551068 0.551427
3 O1-O2 0.824895 0.824892

Phase Synchronization Analysis

Phase Synchronization Analysis (PSA) is the mean cosine of the difference of the instantaneous phases of two signals:

\[ PS = \frac{1}{n} \sum_{t=1}^{n} \cos(\vartheta_x(t) - \vartheta_y(t)) \]

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:

ps = psa(e10_theta, e10_theta; ch1 = ch1, ch2 = ch2)
DataFrame(pair = pairs_lbl, ps = avg(ps))
3×2 DataFrame
Row pair ps
String Float64
1 Fp1-Fp2 -0.165299
2 C3-C4 0.428192
3 O1-O2 0.685038

Phase Slope Index

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:

p = psi(e10, e10; ch1 = ch1, ch2 = ch2, flim = (4, 8))
DataFrame(pair = pairs_lbl,
          psi_1_to_2 = avg(first.(p)),
          psi_2_to_1 = avg(last.(p)))
3×3 DataFrame
Row pair psi_1_to_2 psi_2_to_1
String Float64 Float64
1 Fp1-Fp2 -0.0182869 0.0182869
2 C3-C4 -0.0099418 0.0099418
3 O1-O2 -0.0162004 0.0162004

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.

mutual_information() uses the maximum likelihood estimator of InformationMeasures.jl:

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):

ch = ["Fp1", "C3", "O1", "O2"]
g = granger(e10; ch = ch)
println("Model order: ", g.order)
# rows: from, columns: to
hcat(DataFrame(from = ch), DataFrame(g.gc, ch))
Model order: 20
4×5 DataFrame
Row from Fp1 C3 O1 O2
String Float64 Float64 Float64 Float64
1 Fp1 0.0 0.0124295 0.0168569 0.0193689
2 C3 0.0123922 0.0 0.00996924 0.0121853
3 O1 0.0109461 0.00829906 0.0 0.00406483
4 O2 0.0133033 0.00515065 0.00990625 0.0

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:

gs = granger_spectral(e10; ch = ["O1", "O2"])
fig = Figure(size = fig_size)
ax = Axis(fig[1, 1];
          ax_style...,
          xlabel = "Frequency [Hz]",
          ylabel = "Granger causality",
          title = "Spectral Granger causality")
lines!(ax, gs.frq, gs.gc[1, 2, :]; label = "O1 → O2")
lines!(ax, gs.frq, gs.gc[2, 1, :]; label = "O2 → O1")
xlims!(ax, 0, 40)
axislegend(ax)
fig

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

  1. 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.
  2. Ding, M., Chen, Y., & Bressler, S. L. (2006). Granger causality: basic theory and application to neuroscience. In: Handbook of Time Series Analysis. Wiley.