Toolbox

Tigramite in Python: PCMCI for Causal Discovery in Time Series

1 What Problem Does Tigramite Solve?

Zyadatar causal inference tools economists ke liye cross-sectional ya panel settings ke liye design kiye gaye hain: hum kisi treatment ka outcome par asar units ke darmiyan variation ko istemal karte hue identify karte hain, quasi-experimental designs ka fayda uthate hue. Lekin bahut se economic sawalat bunyadi taur par time-series ki nature ke hote hain: Kya monetary policy inflation ka sabab banti hai? Kya oil price shocks recessions paida karte hain? Kya Twitter sentiment shocks predict asset prices ko predict karte hain?   

Time-series settings mein, standard tools (VAR, Granger causality) predictive relationships ko test karte hain lekin causal ones ko saaf taur par identify nahi karte. Granger causality, mashhoor taur par, causation ko prediction ke saath mila deti hai: variable X "Granger-causes" Y agar lagged X, lagged Y par condition karne ke baad Y ko predict kare, lekin ye genuine causation ke bajaye mukhtalif lag structures ke saath ek common cause ka natija bhi ho sakta hai.  

Tigramite [Runge et al., 2019] ek Python package hai jo time series mein causal discovery ke liye PCMCI algorithm implement karta hai. PCMCI Peter and Clark Momentary Conditional Independence tests for conditional independence relationships among lagged variables to infer causal structure, exploiting temporal ordering to orient edges in the resulting causal graph. Ise multivariate time series ke liye design kiya gaya hai jis mein paidaishi taur par bahut se variables ho sakte hain aur ye linear aur nonlinear dono tarah ki dependencies ko handle karta hai.  

2 The PCMCI Algorithm

2.1 The Setting

Farz karein Xₜ = (Xₜ¹, Xₜ², ..., Xₜᴺ) aik multivariate time series hai N variables ki jo T time points par observe ki gayi hain. Causal structure ko aik time-series DAG ke taur par dikhaya jata hai: nodes {Xₜ₋ᵣʲ : j = 1, ..., N; τ = 0, 1, ..., τₘₐₓ} par aik directed graph, jahan Xₜ₋ᵣʲ se Xₜᵏ ki taraf arrow ka matlab hai ke Xʲ, lag τ par Xᵏ ka sabab banti hai. Temporal ordering ye yaqeen dilati hai ke mazi ke variables hi mustaqbil ke variables ka sabab ban sakte hain, jo cross-sectional causal discovery ki aik ahem pechidgi ko hal karti hai. Algorithm ko sirf contemporaneous edges (lag τ = 0) ko orient karne ki zaroorat hoti hai, jis ke liye mazeed assumptions darkaar hoti hain.  

2.2 Step 1: Momentary Conditional Independence (MCI) Test

PCMCI replaces the standard conditional independence tests of the PC algorithm with momentary conditional independence (MCI) tests. For a candidate link from Xₜ₋ᵣʲ to Xₜᵏ the MCI test checks whether:   

AMCE(dd') = E[Yi(Dk = d') − Yi(Dk = d)]

Jahan 𝒫(Xₜᵏ), Xₜᵏ ke "parents" (causes at shorter lags) ka set hai aur 𝒫(Xₜ₋ᵣʲ), Xₜ₋ᵣʲ ke parents ka set hai. Source aur target variable dono ke parents par condition karna common causes aur autocorrelation ke asar ko khatam kar deta hai, jis se test makhsoos taur par farzi direct causal link ke liye ban jata hai.  

2.3 Step 2: PC-Step (Parent Identification)

MCI testing se pehle, PCMCI aik PC-step chalata hai jo barhti hui conditioning set sizes ke saath conditional independence tests ki aik sequence ka istemal karte hue har variable ke parents ki pehchan karta hai. Ye tamam mumkin conditioning sets ko test karne ke muqable mein computational taur par zyada efficient hai aur time-series setting par apply kiye gaye PC algorithm ke skeleton phase ke barabar hai.  

2.4 Step 3: Multiple Testing Correction

N variables aur τₘₐₓ lags ke saath, PCMCI N² × τₘₐₓ links tak test karta hai. Multiple testing is handled by the false discovery rate (FDR) correction of Benjamini and Hochberg [1995], controlling the expected proportion of false discoveries at a specified level q.  

3 Installation and Setup

Listing 1: Installing Tigramite   

# Install via pip pip install tigramite # Key imports import numpy as np import matplotlib.pyplot as plt from tigramite import data_processing as pp from tigramite import plotting as tp from tigramite.pcmci import PCMCI from tigramite.independence_tests.parcorr import ParCorr from tigramite.independence_tests.gpdc import GPDC

4 A Minimal Working Example: Macroeconomic Variables

Hum aik makhsoos causal structure ke saath teen macroeconomic time series simulate karte hain: output growth aik-period lag ke saath inflation ka sabab banti hai, aur interest rate contemporaneously inflation ko respond karta hai.  

Listing 2: Simulating data and running PCMCI   

np.random.seed(123) T = 500 # time periods N = 3 # variables: output (0), inflation (1), interest rate (2) data = np.zeros((T, N)) # Output growth: AR(1) with own lag for t in range(1, T): data[t, 0] = 0.5 * data[t-1, 0] + np.random.randn() # Inflation: driven by lagged output + own persistence for t in range(1, T): data[t, 1] = (0.4 * data[t-1, 1] + 0.6 * data[t-1, 0] + np.random.randn()) # output causes inflation # Interest rate: responds to current inflation for t in range(0, T): data[t, 2] = (0.8 * data[t, 1] + np.random.randn() * 0.3) # Taylor rule # Create Tigramite dataframe var_names = ["Output", "Inflation", "Interest"] dataframe = pp.DataFrame(data, var_names=var_names) # Run PCMCI with partial correlation test (linear) pcmci = PCMCI(dataframe=dataframe, cond_ind_test=ParCorr(significance='analytic'), verbosity=1) results = pcmci.run_pcmci(tau_min=0, tau_max=3, # test lags 0 to 3 alpha_level=0.05, fdr_method='fdr_bh') # Benjamini-Hochberg FDR # Print significant links pcmci.print_significant_links(p_matrix=results['p_matrix'], val_matrix=results['val_matrix'], alpha_level=0.05)

Listing 3: Visualising the estimated causal graph   

# Plot time-series graph tp.plot_time_series_graph(figsize=(8, 4), val_matrix=results['val_matrix'], graph=results['graph'], var_names=var_names, link_colorbar_label='MCI coefficient') plt.savefig("macro_causal_graph.png", dpi=150, bbox_inches='tight')

5 Nonlinear Dependencies: GPDC Test

Jab relationships nonlinear hon, to linear partial correlation test (ParCorr) sachi links ko miss kar dega aur false positives paida kar sakta hai. Tigramite provides a Gaussian Process Distance Correlation (GPDC) test for nonlinear conditional independence:   

Listing 4: Nonlinear PCMCI with GPDC   

# Replace linear test with nonlinear GP-based test # Note: GPDC is slower, recommended for N <= 10 variables pcmci_nl = PCMCI(dataframe=dataframe, cond_ind_test=GPDC(significance='analytic'), verbosity=0) results_nl = pcmci_nl.run_pcmci(tau_min=0, tau_max=2, alpha_level=0.05)

6 Key Options and Pitfalls

6.1 Lag Maximum and Computation

PCMCI scales quadratically in the number of variables and linearly in the lag maximum τₘₐₓ. With N = 5 variables and τₘₐₓ = 4, there are 5² × 4 = 100 potential links to test. With N = 20 and τₘₐₓ = 4, this grows to 1600 tests. For large N, use PCMCI+ (the extended version, run_pcmciplus) which is computationally more efficient.  

6.2 Stationarity

PCMCI assumes stationary time series. Unit-root processes (random walks) will generate spurious links. Always test for and remove unit roots before running PCMCI (e.g., by first-differencing integrated series).  

6.3 Contemporaneous Causation

At lag τ = 0, time ordering does not identify the direction of causation. PCMCI identifies contemporaneous links but cannot orient them using temporal ordering alone. The PCMCI+ algorithm uses orientation rules based on colliders and Meek rules to orient some contemporaneous edges, but this requires the faithfulness assumption.  

6.4 Comparison to VAR and Granger Causality

Table 1: Comparison: Granger Causality, VAR, and PCMCI   

Table 1: Comparison: Granger Causality, VAR, and PCMCI
Method Controls for autocorrelation Handles nonlinearity Outputs
Granger causality Via regression No (standard) p-values per link
VAR Yes No IRFs, variance decomposition
PCMCI Yes (via MCI conditioning) Yes (GPDC) Causal graph + p-values

PCMCI's key advantage is that the MCI conditioning step explicitly controls for the autocorrelation of both source and target variables, reducing false positives that plague standard Granger causality tests when series are highly persistent.  

7 Applications in Economics

Tigramite has been applied in climate science (its original domain) and increasingly in economics. Relevant applications include:  

  • Identifying causal pathways among macroeconomic variables in high-dimensional VARs.  
  • Disentangling whether commodity prices cause exchange rates or vice versa in small open economies.  
  • Detecting lagged causal links in financial contagion across markets.  

For economic policy analysis, PCMCI is best viewed as a hypothesis-generation tool: it identifies candidate causal links that can then be validated using structural identification strategies (IV, natural experiments). The causal graph it produces encodes testable conditional independence restrictions, which can be examined using standard data-driven methods.  

8 Conclusion

Tigramite's PCMCI algorithm brings rigorous conditional independence testing to time-series causal discovery. Its MCI formulation explicitly handles autocorrelation and common-cause bias, making it more reliable than standard Granger causality for identifying causal structure in multivariate time series. As panel datasets with long time dimensions become more common in economics, tools like PCMCI will become increasingly relevant for exploratory causal analysis.  

References

  1. Benjamini, Y. and Hochberg, Y. (1995). Controlling the false discovery rate: A practical and powerful approach to multiple testing. Journal of the Royal Statistical Society: Series B, 57(1):289-300.  
  2. Runge, J., Nowack, P., Kretschmer, M., Flaxman, S., and Sejdinovic, D. (2019). Detecting and quantifying causal associations in large nonlinear time series datasets. Science Advances, 5(11):eaau4996.  
  3. Runge, J. (2018). Causal network reconstruction from time series: From theoretical assumptions to practical estimation. Chaos, 28(7):075310.  
  4. Spirtes, P., Glymour, C., and Scheines, R. (2000). Causation, Prediction, and Search. MIT Press, 2nd edition.  
  5. Pearl, J. (2009). Causality: Models, Reasoning, and Inference. Cambridge University Press, 2nd edition.  
  6. Granger, C. W. J. (1969). Investigating causal relations by econometric models and cross-spectral methods. Econometrica, 37(3):424-438.  

Continue Reading

Browse All Sections →
Home
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.

Article Title