spectral_connectivity.statistics.coherence_fisher_z_transform#
- coherence_fisher_z_transform(coherency1: NDArray[complexfloating] | complex, n_obs1: int, coherency2: NDArray[complexfloating] | complex = 0, n_obs2: int = 0) NDArray[floating][source]#
Transform coherence magnitude to approximately normal distribution.
Applies Fisher’s z-transformation to coherence magnitudes, which approximately normalizes the distribution for statistical testing. Can compute single-sample test against zero or two-sample test.
- Parameters:
coherency1 (NDArray[complexfloating] or complex, shape (...,)) – Complex coherency values between signals,
Connectivity.coherency(), or their magnitudes. A scalar is accepted and gives a scalar (0-d) result. Do not passmagnitude_squared_coherence(): its values are already squared, and they are read as magnitudes, so the z-scores are wrong with no error (take the square root first).n_obs1 (int) – Number of observations for coherency1 (n_tapers * n_trials).
coherency2 (NDArray[complexfloating] or float, default=0) – Second coherency for comparison, in the same form as
coherency1. If 0, tests against null hypothesis.n_obs2 (int, default=0) – Number of observations for coherency2 (n_tapers * n_trials).
- Returns:
fisher_z_transform – Z-scores for statistical testing. If coherency2=0, tests coherency1 against zero. Otherwise, tests difference coherency1 - coherency2.
- Return type:
NDArray[floating], shape (…,)
Examples
>>> import numpy as np >>> # Compare two coherences (the intended two-sample use). >>> coh1 = np.array([0.5 + 0.2j, 0.3 + 0.1j]) >>> coh2 = np.array([0.3 + 0.15j, 0.4 + 0.05j]) >>> diff_z = coherence_fisher_z_transform(coh1, 100, coh2, 120) >>> >>> # To test a single coherence against ZERO, use the exact null instead: >>> from spectral_connectivity.statistics import coherence_significance_pvalue >>> coherence = np.array([0.1 + 0.05j, 0.3 + 0.2j, 0.8 + 0.1j]) >>> p_values = coherence_significance_pvalue(coherence, n_observations=100)
Notes
The transformation uses bias correction based on the number of observations to improve the normal approximation for small sample sizes.
The Fisher approximation is derived around a non-zero operating point. To test a single coherence against zero coherence, prefer
coherence_significance_pvalue(), which uses the exact null distribution; the Fisher one-sample form (thecoherency2=0, n_obs2=0default) is miscalibrated at that boundary and over-rejects the null.The bias and variance terms assume complex Fourier coefficients. At the 0 Hz bin and, for an even FFT length, the Nyquist bin of a real signal the coefficients are real,
arctanh(|C|)has about twice the variance, and this test is not calibrated: comparing two equal coherences it rejected 9-18% at a nominal 5% in simulation (8-40 observations). Leave those bins out, or test each against zero withcoherence_significance_pvalue(..., real_valued=True).