SparseVARResult.granger_adjacency#

SparseVARResult.granger_adjacency(threshold=0.0)[source]#

The directed Granger network the support draws.

Entry [i, j] is True when some lag of variable j enters variable i’s equation with magnitude above threshold – j Granger-causes i in the selected model. A statement about the selected support, not a hypothesis test.

Parameters:

threshold (float) – Magnitude below which an entry is read as absent.

Return type:

NDArray[bool]

Returns:

A (k, k) boolean matrix with a False diagonal.

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> k, n = 6, 300
>>> first = 0.5 * np.eye(k)
>>> first[1, 0], first[3, 2] = 0.3, -0.3
>>> y = np.zeros((n, k))
>>> for t in range(1, n):
...     y[t] = first @ y[t - 1] + rng.standard_normal(k)
>>> res = SparseVAR(y, order=1).fit(penalty="mcp")
>>> edges = res.granger_adjacency(threshold=0.15)
>>> edges.dtype, bool(edges.diagonal().any())
(dtype('bool'), False)
>>> [(i, j) for i in range(k) for j in range(k) if edges[i, j]]
[(1, 0), (3, 2)]
>>> int(res.granger_adjacency().sum()) >= int(edges.sum())
True