SpectrumEstimate.confidence_interval#

SpectrumEstimate.confidence_interval(name, *, alpha=0.05)[source]#

Pointwise 1 - alpha band for one spectrum from the chi-squared approximation.

From \(\nu \hat f / f \sim \chi^2_\nu\),

\[\Bigl[\frac{\nu \hat f(\omega)}{\chi^2_{\nu, 1-\alpha/2}},\; \frac{\nu \hat f(\omega)}{\chi^2_{\nu, \alpha/2}}\Bigr],\]

a band of constant ratio across frequencies, which is why spectra are plotted on a log scale. The band is pointwise, not simultaneous.

Parameters:
  • name (str) – The series label.

  • alpha (float) – Tail mass, strictly inside (0, 1).

Return type:

tuple[NDArray[double], NDArray[double]]

Returns:

(lower, upper) arrays of shape (n,).

Raises:

SpecificationError – If alpha is not inside (0, 1) or the label is unknown.

Example

>>> from scipy.stats import chi2
>>> rng = np.random.default_rng(0)
>>> est = MultitaperSpectrum(rng.standard_normal(512)).compute()
>>> lower, upper = est.confidence_interval("y")
>>> nu = est.degrees_of_freedom
>>> ratio = chi2.ppf(0.975, nu) / chi2.ppf(0.025, nu)
>>> bool(np.allclose(upper / lower, ratio))
True
>>> est.confidence_interval("y", alpha=1.0)
Traceback (most recent call last):
    ...
cultivars.exceptions.SpecificationError: alpha must lie strictly inside (0, 1); got 1.0.