Code for the paper "Identification and Inference for Causal Effects in Extremes under General Conditions" by Lisa Leimenstoll and Melanie Schienle.
It includes:
- Simulation studies for causal tail tests in R in
Siumlation_Study/, - Applications to train delays, river flows, and financial data in
Application/
Understanding the propagation of extreme events is important in many economic and environmental applications, yet most econometric methods for causal inference focus on average effects rather than tail behavior. This paper studies the identification of causal relations in extremes and derives resulting estimators and their asymptotic inference. As measure of causal dependence between extreme realizations of variables, we analyze the asymptotic behavior of the Causal Tail Coefficient (CTC) within a linear structural causal model with heavy-tailed regularly varying innovations. In contrast to the existing literature, we allow the variables in the system to exhibit heterogeneous tail indices and consider the presence of potentially heavy-tailed confounders. We derive theoretical results assessing the limiting behavior of the CTC under these conditions and show how differences in tail behavior can help to reach identification of the causal structure. Light-tailed confounders are asymptotically negligible, but sufficiently heavy-tailed confounders can induce extremal dependence patterns that are observationally indistinguishable from direct causal effects. When suitable proxy information is available, identification can be recovered using an adjusted Causal Tail Coefficient. Based on these results, we develop estimation and inference procedures for causal relations in extremes under general conditions. We establish asymptotic properties of the proposed estimators and derive tests for the causal direction and heavy-tailed confounding. Simulation evidence examines their finite-sample performance and provides guidance on their implementation. Applications to climate and financial extremes illustrate how the proposed methods can uncover causal relations that may remain undetected by approaches targeting average dependence.
The R code is organized as follows:
-
functions.R
Helper functions for tail indices, causal tail coefficients, and tests. -
testing_strategy.R
Functions to test for causal tail direction and confounding.
The following scripts in Application/Simulation_Study/ generate the results reported in Section 3 of the paper, ordered according to the section numbering:
-
convergence_simulation.R
Produces the results in Section 5.2 (CTC Estimates: Finite-Sample Rate of Convergence). -
simulation_study_configurations.R
Generates the simulation data for Section 5.3 (Finite-Sample Performance of the Proposed Tests). -
simulation_study_configurations_evaluation.R
Produces the results and plots for Section 5.3 (Finite-Sample Performance of the Proposed Tests). -
confounder_simulation.R
Produces the results in 5.3.3 (Confounder-Test). -
k_simulation.R
Produces the results in 5.1 (Choice of the Tuning Parameter k: Independent Pre-Study). -
lingam_pretest_comp.R
Produces the results in Section 5.2 (CTC Estimates: Finite-Sample Rate of Convergence).
This repository contains three main applications of the causal tail tests, each based on external data sources. The code in this repository does not redistribute the raw data. Instead, we provide scripts to download (where possible) or describe how to obtain the data, and to reproduce the preprocessing steps.
-
Train departure times
Open public transport data from:- opentransportdata.swiss: https://opentransportdata.swiss
(real-time / historical timetable and operational data for Swiss trains), downloaded on 13.08.2024. - Download historical operational data for the relevant period (May 2021–July 2024).
- In the code, this data is read and filtered in:
Application/train_processing/01_filter_train_data_switzerland.R
- opentransportdata.swiss: https://opentransportdata.swiss
-
Precipitation
Hourly precipitation data from:- MeteoSchweiz (MeteoSwiss): https://www.meteoswiss.admin.ch
(Swiss Federal Office of Meteorology and Climatology), downloaded on 14.08.2024. - Obtain hourly precipitation measurements for the Zurich station (e.g. station code
REH) from the MeteoSwiss data portal. - Store these data files under
Application/data/weather/. - Matching of train delays to hourly precipitation is performed in:
Application/train_processing/02_prep_train_data_switzerland.R
- MeteoSchweiz (MeteoSwiss): https://www.meteoswiss.admin.ch
The corresponding R code is located in Application/train_processing/ and Application/.
The final merged dataset is written as Application/data/data_combined_train_weather.csv (not included in the repository).
-
River discharge
- Bayerisches Landesamt für Umwelt (LfU): https://www.lfu.bayern.de
(river gauge data, e.g. Danube at Passau, Main at Würzburg/Schweinfurt)- Donau/Passau, downloaded on 25.11.2024
- Main/Würzburg, downloaded on 26.11.2024
- Main/Schweinfurt, downloaded on 03.09.2025
- Export as CSV and place under
Application/data/
(e.g.passau.csv,wurzburg.csv,schweinfurt.csv).
- Bayerisches Landesamt für Umwelt (LfU): https://www.lfu.bayern.de
-
Precipitation
- Deutscher Wetterdienst (DWD): https://www.dwd.de
(German National Meteorological Service – Climate Data Center, daily precipitation). - Download daily precipitation series for station IDs
03878and05705, and store them underApplication/data/
(e.g.passau_precipitation.txt,wurzburg_precipitation.txt).
- Deutscher Wetterdienst (DWD): https://www.dwd.de
The corresponding R code can be found in:
Application/riverflow_application.R
-
S&P 500 index prices (open, close)
- Yahoo Finance: https://finance.yahoo.com
(symbol^GSPC, accessed in R viaquantmod::getSymbols()).
- Yahoo Finance: https://finance.yahoo.com
-
Bitcoin prices
- Coin Metrics: https://coinmetrics.io
(e.g. daily close prices from their market data CSV/API). - Stored locally (
Application/data/coin-metrics.csv), downloaded on 06.12.2024.
- Coin Metrics: https://coinmetrics.io
-
Volatility and equity indices as confounders
- CBOE Volatility Index (VIX)
- Yahoo Finance: symbol
^VIX, via Rquantmod::getSymbols().
- Yahoo Finance: symbol
- MSCI Europe Index
- MSCI (2023) – daily index levels (MSCI Europe).
- Must be obtained from MSCI’s data services and stored locally
(e.g.Application/data/MSCI_eu.csv), downloaded on 08.05.2025.
- CBOE Volatility Index (VIX)
The main R code for this application is located in:
Application/finance_processing/finance_causal_tail_analysis.R
This project includes adapted versions of code from the following sources:
-
Gnecco et al. (2019) – causalXtreme
- Nicola Gnecco, Nicolai Meinshausen, Jonas Peters, and Sebastian Engelke, 2019.
- Original repository: https://github.com/nicolagnecco/causalXtreme
- License: GPL-3.0
Adapted code in this repository:
Application/Simulation_Study/k_simulation.R
The code is distributed under the same GPL-3.0 license, with minor modifications:- Addition of a second tail index and Pareto distribution in
simulate_data. - Addition of Pareto distribution in
simulate_noise. - In
simulation_0: change of arguments, addition of a second tail index. - Addition of a second tail index and Pareto distribution in
my_args. - Changes of plot labels and adjustment for two tail indices.
- Additional simulation study for the percentage of wrong causal inference between two variables.
- Addition of a second tail index and Pareto distribution in
- An adapted version of the
causal_tail_coefficientfunction is located infunctions.R, with the following modification:- Addition of a
minargument to analyse the lower tail.
- Addition of a
-
Pasche et al. (2020) – ExtremalCausalModelling
- O. C. Pasche, V. Chavez-Demoulin, and A. C. Davison, 2020.
- Original repository: https://github.com/opasche/ExtremalCausalModelling
Adapted code in this repository:
- Adapted functions are located in
functions.R, with minor modifications:- Change of the test statistic in
causal_tail_permutation_testto test two-sided.
- Change of the test statistic in