Пример #1
0
 def test_fit(self):
     """Test all Pac methods."""
     pha = np.random.rand(2, 7, 1024)
     amp = np.random.rand(3, 7, 1024)
     nmeth, nsuro, nnorm = 5, 4, 5
     p = Pac(verbose=False)
     for k in range(nmeth):
         for i in range(nsuro):
             for j in range(nnorm):
                 p.idpac = (k + 1, i, j)
                 p.fit(pha, amp, n_jobs=1, n_perm=10)
                 if (i >= 1) and (k + 1 != 4):
                     for mcp in ['maxstat', 'fdr', 'bonferroni']:
                         p.infer_pvalues(mcp=mcp)
Пример #2
0
# distribution of surrogates. In this example, we used the method proposed by
# Bahramisharif et al. 2013 :cite:`bahramisharif2013propagating` and also
# recommended by Aru et al. 2015 :cite:`aru2015untangling`. This method
# consists in swapping two time blocks of amplitudes cut at a random time
# point. Then, we used the method :class:`tensorpac.Pac.infer_pvalues` in order
# to get the corrected p-values across all possible (phase, amplitude)
# frequency pairs.

# define the Pac object
p = Pac(idpac=(2, 2, 0), f_pha=(2, 15, 2, .2), f_amp=(60, 120, 5, 1))
# compute true pac and surrogates
n_perm = 200  # number of permutations
xpac = p.filterfit(sf, data, n_perm=n_perm, n_jobs=-1,
                   random_state=0).squeeze()
# get the corrected p-values
pval = p.infer_pvalues(p=0.05)
# get the mean pac values where it's detected as significant
xpac_smean = xpac[pval < .05].mean()

# if you want to see how the surrogates looks like, you can have to access
# using :class:`tensorpac.Pac.surrogates`
surro = p.surrogates.squeeze()
print(f"Surrogates shape (n_perm, n_amp, n_pha) : {surro.shape}")
# get the maximum of the surrogates across (phase, amplitude) pairs
surro_max = surro.max(axis=(1, 2))

plt.figure(figsize=(16, 5))
plt.subplot(131)
p.comodulogram(xpac,
               title=str(p),
               cmap='Spectral_r',
Пример #3
0
# multiple times (e.g 200 or 1000 times) in order to obtained the distribution.
# Finally, the p-value is inferred by computing the proportion exceeded by the
# true coupling. In addition, the correction for multiple comparison is
# obtained using the FDR.

# still using the Gaussian-Copula PAC but this time, we also select the method
# for computing the permutations
p_obj.idpac = (6, 2, 0)
# compute pac and 200 surrogates
pac_prep = p_obj.fit(pha_p[..., time_prep],
                     amp_p[..., time_prep],
                     n_perm=200,
                     random_state=0)
# get the p-values
mcp = 'maxstat'
pvalues = p_obj.infer_pvalues(p=0.05, mcp=mcp)

###############################################################################

# sphinx_gallery_thumbnail_number = 7
plt.figure(figsize=(8, 6))
title = (r"Significant alpha$\Leftrightarrow$gamma coupling occurring during "
         f"the motor planning phase\n(p<0.05, {mcp}-corrected for multiple "
         "comparisons)")
# plot the non-significant pac in gray
pac_prep_ns = pac_prep.mean(-1).copy()
pac_prep_ns[pvalues < .05] = np.nan
p_obj.comodulogram(pac_prep_ns,
                   cmap='gray',
                   vmin=np.nanmin(pac_prep_ns),
                   vmax=np.nanmax(pac_prep_ns),
Пример #4
0
# distribution of surrogates. In this example, we used the method proposed by
# Tort et al. 2010 :cite:`tort2010measuring`. This method consists in swapping
# phase and amplitude trials. Then, we used the method
# :class:`tensorpac.Pac.infer_pvalues` in order to get the corrected p-values
# across all possible (phase, amplitude) frequency pairs.

# define the Pac object
p = Pac(idpac=(1, 1, 0), f_pha='mres', f_amp='mres')
# compute true pac and surrogates
n_perm = 200  # number of permutations
xpac = p.filterfit(sf, data, n_perm=n_perm, n_jobs=-1).squeeze()

plt.figure(figsize=(16, 5))
for n_mcp, mcp in enumerate(['maxstat', 'fdr', 'bonferroni']):
    # get the corrected p-values
    pval = p.infer_pvalues(p=0.05, mcp=mcp)
    # set to gray non significant p-values and in color significant values
    pac_ns = xpac.copy()
    pac_ns[pval <= .05] = np.nan
    pac_s = xpac.copy()
    pac_s[pval > .05] = np.nan

    plt.subplot(1, 3, n_mcp + 1)
    p.comodulogram(pac_ns, cmap='gray', colorbar=False, vmin=np.nanmin(pac_ns),
                   vmax=np.nanmax(pac_ns))
    p.comodulogram(pac_s, title=f'MCP={mcp}', cmap='viridis',
                   vmin=np.nanmin(pac_s), vmax=np.nanmax(pac_s))
    plt.gca().invert_yaxis()

plt.tight_layout()
p.show()