Initialize NeuroAnalyzer
using NeuroAnalyzer
using Statistics
NeuroAnalyzer.Random.seed!(1)using NeuroAnalyzer
using Statistics
NeuroAnalyzer.Random.seed!(1)Brain connectivity describes how brain regions are connected and interact:
Connectivity in EEG/MEG is usually frequency-specific (e.g. alpha, beta or gamma band) and dynamic (it changes with the cognitive state, the task and over time). It is used to study the organization of brain networks, cognitive processes that rely on the cooperation of distributed regions, and their disruption in neurological and psychiatric disorders (e.g. epilepsy, schizophrenia, dementia).
Phase synchronization (a consistent phase relation between oscillations) is thought to support communication between regions. Phase-based measures use the instantaneous phases of narrowband signals (band-pass filtered and Hilbert-transformed, or from wavelets).
Inter-trial phase clustering (ITPC) uses the same formula as ISPC, but across trials at one channel: it measures the consistency of the phase relative to an event (phase locking to the stimulus), not connectivity between regions. ITPC
Coherence is the frequency-domain correlation between two signals: the normalized cross-spectrum, \(C_{xy}(f) = S_{xy}(f) / \sqrt{S_{xx}(f) S_{yy}(f)}\), estimated over epochs (or segments). It depends on both the phase consistency and the amplitude correlation.
See Coherence.
Amplitude-based measures capture correlations of power (amplitude envelopes) between regions, which may reflect co-activation even without phase synchronization.
Correlation, covariance, cosine similarity, mutual information and synchronization likelihood (a non-linear measure of generalized synchronization) describe dependencies regardless of frequency, see Other Methods.
Granger causality: a signal \(x\) “Granger-causes” \(y\) if the past of \(x\) improves the prediction of \(y\) beyond the past of \(y\) itself (autoregressive models); spectral versions give directed connectivity per frequency. Other measures: the phase slope index, directed PLI, partial directed coherence, transfer entropy.
The main problem of sensor-level EEG/MEG connectivity is volume conduction (and field spread): the activity of a single source is recorded by many electrodes at the same time, without delay, so neighbouring channels are correlated and phase-synchronized even without any interaction between brain regions. The common reference adds further shared signal to all channels.
Because volume conduction is instantaneous, it produces phase differences of 0 (or π). Measures based on the imaginary part of the cross-spectrum or on non-zero phase lags (PLI, wPLI, iPLV, imaginary coherence, orthogonalized AEC) ignore it; the price is that true zero-lag interactions are ignored as well.
Simulated example: two channels recording a 10 Hz oscillation in 30 two-second epochs, with independent noise, band-pass filtered at 8–12 Hz:
fs = 256
n = 2 * fs
n_ep = 30
t = (0:(n - 1)) ./ fs
function simulate(lag)
a = zeros(n, n_ep)
b = zeros(n, n_ep)
for ep in 1:n_ep
φ = 2π * rand() # random phase in each epoch
src = sin.(2π * 10 .* t .+ φ)
a[:, ep] = src .+ 0.5 .* randn(n)
b[:, ep] = (lag == 0 ? 0.8 .* src : sin.(2π * 10 .* t .+ φ .- lag)) .+
0.5 .* randn(n)
end
obj = create_object(; data_type = "eeg")
obj.header.recording[:sampling_rate] = fs
add_channel!(obj;
data = permutedims(cat(a, b; dims = 3), (3, 1, 2)),
label = ["A", "B"],
type = ["eeg", "eeg"],
unit = ["μV", "μV"])
create_time!(obj; fs = fs)
NeuroAnalyzer.filter!(obj;
ch = "all",
fprototype = :fir,
ftype = :bp,
cutoff = (8, 12),
bw = 2)
return obj
endfor (name, lag) in (("zero lag", 0), ("lag π/4", π / 4))
obj = simulate(lag)
pv = mean(plv(obj, obj; ch1 = "A", ch2 = "B").pv)
pl = mean(pli(obj, obj; ch1 = "A", ch2 = "B").pv)
wp = wpli(obj, obj; ch1 = "A", ch2 = "B", across_epochs = true).pv[1]
c = coherence(obj, obj; ch1 = "A", ch2 = "B")
i10 = argmin(abs.(c.f .- 10))
println(rpad(name, 9),
" PLV: ", round(pv; digits = 2),
" PLI: ", round(pl; digits = 2),
" wPLI: ", round(wp; digits = 2),
" coherence: ", round(c.msc[1, i10]; digits = 2),
" |imag. coherence|: ", round(abs(c.imcoh[1, i10]); digits = 2))
endzero lag PLV: 0.99 PLI: 0.3 wPLI: 0.07 coherence: 0.97 |imag. coherence|: 0.0
lag π/4 PLV: 0.97 PLI: 0.98 wPLI: 1.0 coherence: 0.97 |imag. coherence|: 0.7
PLV and coherence are high in both cases and cannot distinguish volume conduction from a true interaction. PLI, wPLI and imaginary coherence are high only for the lagged coupling.
PLI is calculated within each epoch (across its time points) and averaged over epochs; for the zero-lag case it is not exactly 0: within a short epoch of a narrowband signal, noise shifts the phase difference to one side of zero for long stretches. wPLI and imaginary coherence are calculated across epochs (wpli(...; across_epochs = true)), where such random shifts cancel out; debiased = true further removes the positive bias of wPLI caused by a limited number of epochs.
Other ways to reduce volume conduction:
Graph theory describes the large-scale organization of brain networks from connectivity matrices:
| Metric | Description | Use |
|---|---|---|
| Degree / strength | number (or sum of weights) of the connections of a node | identifying hubs |
| Clustering coefficient | how strongly the neighbours of a node are connected with each other | local (segregated) processing |
| Characteristic path length | average shortest path between all pairs of nodes | global (integrated) processing |
| Global efficiency | average inverse shortest path length | integration (robust to disconnected nodes) |
| Modularity | strength of the division of the network into modules (communities) | functional modules |
| Small-worldness | high clustering with a short path length, relative to random networks | efficient network organization |
Graph measures depend strongly on the connectivity measure, the number of nodes, thresholding and normalization; they should be compared with appropriate random (null) networks.
Preprocessing:
Biases:
Statistics:
| Challenge | Description | Approach |
|---|---|---|
| Volume conduction | one source recorded by many channels gives spurious zero-lag connectivity | lag-based measures (PLI, wPLI, imaginary coherence), Laplacian/CSD, source space |
| Reference | the shared reference adds common signal | average reference, Laplacian, source space |
| Common input | a third region drives both regions | multivariate (partial, conditional) measures |
| Number of epochs | measures are biased with few epochs | equal epoch numbers, debiased measures |
| Power differences | connectivity estimates depend on the signal-to-noise ratio | control for power, report power |
| Non-stationarity | connectivity changes over time | time-resolved (sliding window) connectivity |
| Artifacts | eye, muscle and line-noise artifacts are shared by many channels | careful preprocessing |
| Directionality | undirected measures do not show the direction of interactions | Granger causality, PSI, dPLI, transfer entropy |
| Measure | Type | Frequency-specific | Directed | Insensitive to zero-lag volume conduction |
|---|---|---|---|---|
| PLV / ISPC | phase | yes | no | no |
| iPLV | phase | yes | no | yes |
| PLI | phase | yes | no | yes |
| wPLI | phase | yes | no | yes |
| dPLI | phase | yes | yes | yes |
| PSI | phase | yes | yes | yes |
| Coherence | spectral | yes | no | no |
| Imaginary coherence | spectral | yes | no | yes |
| AEC | amplitude | yes | no | no (yes with orthogonalization) |
| Correlation | general | no (unless filtered) | no | no |
| Mutual information, synchronization likelihood | non-linear | no (unless filtered) | no | no |
| Granger causality | directed | yes (spectral version) | yes | partly |
| ITPC | phase consistency across trials (not connectivity) | yes | – | – |