spectral_connectivity.statistics.power_confidence_intervals#

power_confidence_intervals(n_tapers: int, power: ndarray[tuple[int, ...], dtype[floating]] | float = 1, ci: float = 0.95) → tuple[ndarray[tuple[int, ...], dtype[floating]] | float, ndarray[tuple[int, ...], dtype[floating]] | float][source]#

Compute confidence intervals for multitaper power spectrum estimates.

Uses chi-squared distribution to compute confidence bounds for power spectral density estimates from multitaper analysis.

Parameters:
  • n_tapers (int) – Number of independent observations averaged into each power estimate: tapers times trials (Connectivity.n_observations), not the taper count alone unless a single trial was averaged. It sets the chi-squared degrees of freedom 2 * n_tapers, as in power_bias() and power_variance(). Passing only the taper count for a multi-trial average makes the interval far too wide (about 100% coverage instead of 95% for 5 tapers x 5 trials).

  • power (NDArray[floating] or float, default=1) – Power spectrum estimates. Can be array of values or scalar.

  • ci (float, default=0.95) – Confidence level, must be in range [0.5, 1.0).

Returns:

  • lower_bound (NDArray[floating]) – Lower confidence bounds for power estimates.

  • upper_bound (NDArray[floating]) – Upper confidence bounds for power estimates.

Examples

>>> import numpy as np
>>> # Single power estimate from 5 observations (5 tapers x 1 trial)
>>> lower, upper = power_confidence_intervals(n_tapers=5, power=1.0, ci=0.95)
>>> print(f"95% CI: [{lower:.3f}, {upper:.3f}]")
95% CI: [0.488, 3.080]
>>> # Averaging 5 tapers x 5 trials gives 25 observations, a much tighter interval
>>> lower, upper = power_confidence_intervals(n_tapers=25, power=1.0, ci=0.95)
>>> print(f"95% CI: [{lower:.3f}, {upper:.3f}]")
95% CI: [0.700, 1.545]
>>> # Multiple power estimates
>>> power_vals = np.array([0.5, 1.0, 2.0, 5.0])
>>> lower, upper = power_confidence_intervals(5, power_vals, 0.95)
>>> np.round(lower, 3).tolist()
[0.244, 0.488, 0.976, 2.441]

References

[1]

Kramer, M.A., and Eden, U.T. (2016). Case studies in neural data analysis: a guide for the practicing neuroscientist (MIT Press).