-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the option to measure connectivity over time to spectral_connectivity() #17
Comments
@Avoide I updated your code example to inclue syntax coloring. I'll try to add to the discussion on monday! |
Hi @larsoner / @mmagnuski , May I know whether this issue of calculating over time and suggestion by the OP has been incorporate in recent mne version? |
No, but the connectivity measures are moved to a separate repository now - mne-connectivity. It would be good to discuss this issue there once the transition is over |
I am still available for discussing this issue, although having someone more experienced in programming is probably needed for the actual incorporation. I'm still quite new to python and haven't used github before, so I didn't start at pull request. |
Hi @Avoide thanks for making this issue in the first place. I haven't had a chance to look at your code in depth yet, but for what it's worth, I am open to trying to get this to work over time. Your proposal implementation if it works over time doesn't need to work on the existing Lmk if you have time to start making a PR. Otherwise, I may not be able to fully implement this until a few weeks at least. |
@adam2392 I just tried using the function spectral_connectivity_time, but I am a bit in doubt about the API. After using the function on some dummy data with: If I want to boil the information down to (n_channels, n_channels, n_freq), i.e. the same output as mne.connectivity.spectral_connectivity, can I just take the np.mean over the first and last axis? However when I do this, the diagonal for PLV is not one as I would expect. I also tried using the PLV on some randomly generated data and got very high PLV values despite taking the average over 100 runs, but perhaps I am using it wrongly. I attached some code using random data and also my own implementation as comparison.
|
Describe the new feature or enhancement
Hi all,
mne-tools/mne-python#7937 indicated there was an error in the PLI implementation and I also had the same problem when working with resting-state epoched data. But after looking more into it I found out it is not really an error but instead two different ways to analyze connectivity: over time or over trials.
Mike X Cohen explains the difference quite nicely in his video here:
Youtube Link
I also commented in that issue, but are now creating a standalone feature request.
The current PLI and PLV implementation in spectral_connectivity() is connectivity over trials, which are suited for ERP data. But for resting-state data it does not make sense to analyze connectivity over trials but should instead be over time.
Describe your proposed implementation
I tried implementing my own version to calculate PLV and wPLI over time and you can see a simple working example here:
Notice I added the option to choose what kind of data should be used. If data_option = 0 then the expected output is that PLV across trials are 1 since I just repeated the first epoch in all other epochs, while if data_option = 1 the PLV across time should be 1 as I use 10Hz sine waves with different phase differences.
It is still quite rough and not optimized but should give an idea of the procedure.
I am not completely certain about my implementation but the wPLI is calculated by following equation 1 in [1] and weighing by the absolute magnitude of the phase differences as described by [2]. PLV was calculated according to the equation in [3]. According to mne-tools/mne-python#8305 this equation should be equivalent to what is being used in spectral_connectivity() already, but my implementation over time gives another PLV than spectral_connectivity().
It would be helpful if anyone could have a look. After optimizing it the feature should probably just be added as an option to spectral_connectivity() and does not need its own version.
Describe possible alternatives
I don't know any alternatives as this suggestion is just about a slight different way of calculating the connectivity over time instead of over trials.
[1] Hardmeier, Martin, Florian Hatz, Habib Bousleiman, Christian Schindler, Cornelis Jan Stam, and Peter Fuhr. 2014. “Reproducibility of Functional Connectivity and Graph Measures Based on the Phase Lag Index (PLI) and Weighted Phase Lag Index (WPLI) Derived from High Resolution EEG.” PLoS ONE 9 (10). https://doi.org/10.1371/journal.pone.0108648.
[2] Vinck, Martin, Robert Oostenveld, Marijn Van Wingerden, Franscesco Battaglia, and Cyriel M.A. Pennartz. 2011. “An Improved Index of Phase-Synchronization for Electrophysiological Data in the Presence of Volume-Conduction, Noise and Sample-Size Bias.” NeuroImage 55 (4): 1548–65. https://doi.org/10.1016/j.neuroimage.2011.01.055.
[3] Lachaux, Jean Philippe, Eugenio Rodriguez, Jacques Martinerie, and Francisco J. Varela. 1999. “Measuring Phase Synchrony in Brain Signals.” Human Brain Mapping 8 (4): 194–208. https://doi.org/10.1002/(SICI)1097-0193(1999)8:4<194::AID-HBM4>3.0.CO;2-C.
The text was updated successfully, but these errors were encountered: