Module granger

Source
Expand description

Granger causality testing for embedding trajectories.

Tests whether entity A’s movements in embedding space precede entity B’s. Uses a VAR(L) model on dimensionality-reduced trajectories.

§Algorithm

  1. Align trajectories to a common time grid (linear interpolation)
  2. For each dimension d:
    • Fit restricted model: B_d(t) = Σ β_l · B_d(t-l) + ε
    • Fit unrestricted model: B_d(t) = Σ β_l · B_d(t-l) + Σ γ_l · A_d(t-l) + ε
    • F-test: does the unrestricted model significantly improve?
  3. Combine per-dimension p-values via Fisher’s method

§References

  • Granger, C.W.J. (1969). Investigating causal relations. Econometrica, 37(3).
  • Fisher, R.A. (1925). Statistical methods for research workers.

Structs§

GrangerResult
Result of a Granger causality test.

Enums§

GrangerDirection
Direction of Granger causality.

Functions§

align_trajectories 🔒
Align two trajectories to a common time grid via linear interpolation.
cholesky_solve 🔒
Solve Ax = b where A is symmetric positive definite via Cholesky.
erfc 🔒
Complementary error function approximation.
f_statistic 🔒
Compute F-statistic from restricted and unrestricted RSS.
f_to_p 🔒
Approximate p-value from F-statistic using the F-distribution.
fisher_combine 🔒
Fisher’s method: combine independent p-values.
fit_and_rss 🔒
Fit a simple autoregressive model and return residual sum of squares.
granger_causality
Test Granger causality between two embedding trajectories.
interpolate_at 🔒
Linear interpolation of a trajectory at a specific timestamp.
ln_beta 🔒
Log of the Beta function: ln(B(a,b)) = ln(Gamma(a)) + ln(Gamma(b)) - ln(Gamma(a+b))
ln_gamma 🔒
Stirling’s approximation for ln(Gamma(x)) for x > 0.
ols_granger_single_dim 🔒
Fit OLS for a single dimension and compute residual sum of squares.
regularized_incomplete_beta 🔒
Regularized incomplete beta function via continued fraction (Lentz’s method).
solve_ols 🔒
Solve OLS via normal equations with regularization.
test_direction 🔒
Test one direction: does cause Granger-cause effect?