Multivariate reduced-rank VECM with trace and maximum-eigenvalue rank tests.
Supply a vector of k levels. For L lagged differences, project ΔYₜ and Yₜ₋₁ off the same lagged differences and optional unrestricted intercept. Specify regression='none' or 'constant'. Use n=w−L−1. Rank-revealing QR removes nuisance columns. Thin SVD of the two residual matrices and of their left-subspace overlap gives squared canonical correlations λ in decreasing order. At rank r the trace statistic is −n Σᵢ≥ᵣ log(1−λᵢ), and maximum eigenvalue is −n log(1−λᵣ). Large values reject. Each outer entry of beta and alpha is one cointegrating and adjustment vector. With selected rank r use the first r paired entries to form Π=Σαᵢβᵢ′; residualized level scores have unit sample second moment. Signs are arbitrary. trace_rank and max_rank stop at the first nonrejection at 5%. Critical values are asymptotic statsmodels coint_tables values for remaining dimensions 1–12. Larger systems can return statistics with partial tables and no selected rank. Singular designs yield empty vectors. Ingest O(k), read O(wq²+q³) time and O(wq+q²) space for q=k(L+2)+1. Compared to statsmodels coint_johansen at matched positive lag order. Zero lags uses Yₜ₋₁ explicitly.
Call model.vecm(rank) after warm-up to fit the restricted VECM at any specified rank from zero through k. It returns Π and an ordered list of Γ matrices in dependent-variable-by-predictor order, an unrestricted intercept when selected, and the maximum-likelihood innovation covariance E′E/n. It refits the nuisance coefficients conditional on the selected long-run space. The tests compare Π, Γ, the intercept and covariance with statsmodels VECM at ranks zero, one and full rank.
The econometric conventions specify input validation, warm-up, reset, result fields, numerical rank and critical-value order.
Python example
import random
import rtta
rng = random.Random(42)
model = rtta.JohansenCointegration(window=64, series=2, lags=1)
for i in range(64):
value = rng.gauss(0, 1)
predictor = rng.gauss(0, 1)
result = model.update([value, predictor])
print(result.trace_statistics)
Reference
Johansen (1991), Estimation and Hypothesis Testing of Cointegration Vectors in Gaussian Vector Autoregressive Models. MacKinnon, Haug and Michelis, numerical distribution functions for likelihood ratio tests.
