ConditionalSpectralCausality#
- class cultivars.spectral.causality.ConditionalSpectralCausality(result, restricted, *, n_frequencies=256)[source]
Bases:
objectGeweke’s (1984) conditional causality, from two fitted models.
The conditional measure mathematically requires the restricted system – the model with the cause excluded – and there is no view-only shortcut, so that model is an explicit argument the caller fits. With \(\Psi(\omega)\) the full system’s transfer function, \(\Sigma\) its innovation covariance, and \(Q(\omega) = I - \sum_l B_l e^{-i\omega l}\) the restricted system’s lag polynomial embedded in the full dimension with the cause’s row and column left as the identity, the full model’s innovations are mapped through the restricted polynomial,
\[G(\omega) = Q(\omega)\, \Psi(\omega)\, P,\]where \(P\) is the Cholesky factor of \(\Sigma\) with the cause’s shock ordered last, the conservative convention that credits every shared innovation to the other variables first. Row \(y\) of \(G\) then splits the restricted innovation power of effect \(y\) into the part from every shock but the cause’s and the part from the cause’s, and the measure is the log ratio of the whole to the former. In population the whole equals \(\Sigma^{r}_{yy}\) at every frequency; the largest relative departure is reported as
consistency.- Parameters:
result (
ClosedSystemResult) – The fitted full system.restricted (
ClosedSystemResult) – A fitted closed system on the same variables minus exactly one – the cause – in the same relative order. The true restricted process is generally VARMA even when the full system is a finite VAR, so give this model a generous lag order and read the result’sconsistencydiagnostic; a too-short restricted model is the usual reason the curves and the time-domain measure disagree.n_frequencies (
int) – Grid points on[0, pi], endpoints included.
- Variables:
_result – The fitted full system.
_restricted – The fitted restricted system.
_cause_index – The cause’s column in the full system.
_n_frequencies – The grid size \(n\).
- Raises:
SpecificationError – If the two systems’ variables do not differ by exactly one, order included, or the grid is too small.
Note
Which variable is the cause is inferred from the names: the one the full system has and the restricted lacks. The two models are fitted separately by the caller and nothing here enforces that they were fitted to the same sample; a restricted model on a different window is a different process, and the consistency diagnostic will say so loudly.
See also
ConditionalSpectralCausalityResult– the recordcompute()returns.SpectralCausality– the unconditional pairwise measures from one model.
References
Geweke, J. (1984). Measures of conditional linear dependence and feedback between time series. Journal of the American Statistical Association, 79(388), 907-915.
Chen, Y., Bressler, S. L., & Ding, M. (2006). Frequency decomposition of conditional Granger causality and application to multivariate neural field potential data. Journal of Neuroscience Methods, 150(2), 228-237.
Example
>>> import numpy as np >>> from cultivars.multivariate.reduced_form.vector_autoregression import VAR >>> rng = np.random.default_rng(0) >>> y = np.zeros((600, 3)) >>> for t in range(1, 600): ... 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() ... y[t, 2] = 0.5 * y[t - 1, 2] + rng.standard_normal() >>> full = VAR(y, order=1).fit() >>> restricted = VAR(y[:, [0, 2]], order=1, names=("y1", "y3")).fit() >>> conditional = ConditionalSpectralCausality(full, restricted).compute() >>> conditional.cause 'y2' >>> bool(conditional.integrated()[0] > 0.05) True
The restricted system must be the full one minus exactly one variable, in order:
>>> swapped = VAR(y[:, [2, 0]], order=1, names=("y3", "y1")).fit() >>> ConditionalSpectralCausality(full, swapped) Traceback (most recent call last): ... cultivars.exceptions.SpecificationError: the restricted system must contain the full ...