Eden-Kramer-Lab / spectral_connectivity

Frequency domain estimation and functional and directed connectivity analysis tools for electrophysiological data
GNU General Public License v3.0
121 stars 43 forks source link

Puzzled about trial averaging - isn't coherence symmetric #57

Closed mschart closed 7 months ago

mschart commented 7 months ago

Hi there,

Thanks a lot for providing this superb toolbox! We are analyzing ephys data with it and wondered about the symmetry of coherence when probing it via shuffling the input data.

Let's say our signal with trial structure is of shape 2 channels x 500 trials x 800 observations. Now computing coherence gives this on top row. Now when taking the same data but swapping randomly the channel order, independently for each trial, we find the same shape of the frequency-dependent coherence, however the magnitude decreased substantially.

Given that coherence should be a symmetric measure, we wonder if something in the trial averaging could have caused that amplitude drop.

image

For spectral granger - an asymmetric measure - also the shape of the result changed, as expected:

image

If you have any thoughts as of why that amplitude dropped for the shuffled data we'd be glad to hear them!

Many thanks!

emilyps14 commented 7 months ago

Hi @mschart!

While magnitude squared coherence is symmetric, the averaging across trials happens over the complex-valued coherency, which isn't symmetric -- coh(X,Y)=coh(Y,X) [where is complex conjugate). So if the two signals are sometimes swapped for different trials, it will change the trial average.

Does that make sense?

mschart commented 7 months ago

Fantastic, glad to read that, thanks a lot!