SpectralDensityResult.coherence#
- SpectralDensityResult.coherence(first, second)[source]#
Squared coherence between two variables, in
[0, 1].\[C_{ij}(\omega) = \frac{|f_{ij}(\omega)|^2}{f_{ii}(\omega)\, f_{jj}(\omega)},\]the frequency-domain analogue of a squared correlation – how much of the two variables’ power at each frequency is shared. Symmetric, and silent about direction; the directional reading belongs to
SpectralCausality.- Parameters:
- Return type:
- Returns:
A real
(n,)array in[0, 1].- Raises:
SpecificationError – If either label is unknown.
Example
>>> import numpy as np >>> from cultivars.multivariate.reduced_form.vector_autoregression import VAR >>> rng = np.random.default_rng(0) >>> y = np.zeros((500, 2)) >>> for t in range(1, 500): ... y[t, 0] = 0.5 * y[t - 1, 0] + 0.4 * y[t - 1, 1] + rng.standard_normal() ... y[t, 1] = 0.5 * y[t - 1, 1] + rng.standard_normal() >>> res = VAR(y, order=1, names=("gdp", "rate")).fit() >>> density = SpectralDensity(res, n_frequencies=64).compute() >>> forward = density.coherence("gdp", "rate") >>> bool(np.allclose(forward, density.coherence("rate", "gdp"))) True >>> bool(np.all((forward >= 0.0) & (forward <= 1.0))) True