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

Negative PLI values #14

Closed christian-oreilly closed 4 years ago

christian-oreilly commented 4 years ago

PLI is defined as PLI = |E[sign(Im(Sxy))]| and is, therefore, a positive value. And it case there could be any confusion on this, it is explicitly said in the Stam paper "The PLI ranges between 0 and 1". However, trying your toolbox I obtained negative values in the returned array from Multitaper().phase_lag_index().

from spectral_connectivity import Multitaper, Connectivity
import numpy as np

sfreq = 500
np.random.seed(1)

data = np.random.rand(500, 20)
m = Multitaper(time_series=data,
               sampling_frequency=sfreq,
               time_halfbandwidth_product=8,
               time_window_duration=0.20,
               time_window_step=0.10,
               start_time=0.0)

c = Connectivity.from_multitaper(m)

assert(np.all(c.phase_lag_index() >= 0))

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-1-027228a3414c> in <module>
     13 c = Connectivity.from_multitaper(m)
     14 
---> 15 assert(np.all(c.phase_lag_index() >= 0))

AssertionError: 
edeno commented 4 years ago

Hi @christian-oreilly, thanks for the comment. After looking into it, I implemented the signed version of the PLI. So to obtain the unsigned version, you would just have to take the absolute value of this quantity. I should probably make this more explicit in the documentation to prevent any further confusion.