SlowGuess/NeurIPS_2023_OCR huggingface dataset:
$$
p (\mathcal {D}) = \prod_ {a \in \{0, 1 \}} \left[ \exp (- \Lambda^ {(a)}) \prod_ {i = 1} ^ {I ^ {(a)}} \underbrace {\lambda^ {(a)} \left(t _ {i} , m _ {i} \mid \mathcal {H} _ {<   t _ {i}}\right)} _ {\text {m e d i a t o r i n t e n s i t y}} \prod_ {j = 1} ^ {J ^ {(a)}} \underbrace {p ^ {(a)} \left(y _ {j} \mid t _ {j} , \mathcal {H} _ {<   t _ {j}}\right)} _ {\text {o u t c o m e m o d e l}} \right], \tag {8}
$$
where we denote the conditional intensity function of the mediator MPP by  $\lambda^{(a)}(t_i, m_i \mid \mathcal{H}_{< t_i})$ , and the point process integral term by  $\Lambda^{(a)} = \int_0^T \lambda^{(a)}(\tau \mid \mathcal{H}_{< \tau}) \, \mathrm{d}\tau$ .
4.1 Mediator Intensity (O)
The mediator intensity  $\lambda(t_i, m_i \mid \mathcal{H}_{<t_i})$  is defined as a combination of the mediator time intensity  $\lambda(t_i \mid \mathcal{H}_{<t_i})$  and the mediator mark or dosage density  $p(m_i \mid t_i, \mathcal{H}_{<t_i})$ :  $\lambda(t_i, m_i \mid \mathcal{H}_{<t_i}) = \lambda(t_i \mid \mathcal{H}_{<t_i}) p(m_i \mid t_i, \mathcal{H}_{<t_i})$ . Similar to [Hizli et al., 2023], we model the time intensity  $\lambda(t_i \mid \mathcal{H}_{<t_i})$  as the squared sum of three components  $\{\beta_0, g_m, g_o\}$ , to ensure non-negativity:
$$
\lambda (\tau \mid \mathcal {H} _ {<   \tau}) = \left(\underbrace {\beta_ {0}} _ {\text {P P b a s i l e n c e}} + \underbrace {g _ {m} (\tau ; \mathbf {m})} _ {\text {m e d i a t o r e f f e c t}} + \underbrace {g _ {o} (\tau ; \mathbf {o})} _ {\text {o u t c o m e e f f e c t}}\right) ^ {2}, \tag {9}
$$
where  $\mathbf{m}$  contains past mediators (meal times and sizes) and  $\mathbf{o}$  contains past outcomes (glucose). The constant  $\beta_0$  serves as a basic Poisson process baseline. The mediator-effect function  $g_{m}$  and the outcome-effect function  $g_{o}$  model how the intensity depends on the past mediators and outcomes, respectively. The components  $g_{m}$  and  $g_{o}$  are time-dependent functions with GP priors:  $g_{m}, g_{o} \sim \mathcal{GP}$ . The mediator dosage density  $p(m_i \mid t_i, \mathcal{H}_{<t_i})$  is also modeled with an independent GP prior:  $m_i(t_i) \sim \mathcal{GP}$ .
4.2 Outcome Model (●)
We model the outcome process  $\mathbf{Y} = \{Y(\tau \mid \mathcal{H}_{<\tau}) : \tau \in [0, T]\}$  as a conditional GP prior, that is, a sum of three independent functions [Schulam and Saria, 2017, Hizli et al., 2023]:
$$
Y (\tau \mid \mathcal {H} _ {<   \tau}) = \underbrace {f _ {b} (\tau)} _ {\text {b a s e l i n e}} + \underbrace {f _ {m} (\tau ; \mathbf {m})} _ {\text {m e d i a t o r r e s p o n s e}} + \underbrace {u _ {Y} (\tau)} _ {\text {n o i s e}}, \tag {10}
$$
where the baseline and the mediator response have  $\mathbf{GP}$  priors,  $f_{b}, f_{m} \sim \mathcal{GP}$ , similar to Hizh et al. [2023], while the noise is sampled independently from a zero-mean Gaussian variable  $u_{Y}(\tau) \sim \mathcal{N}(0, \sigma_{y}^{2})$ . The mediator response function  $f_{m}$  models the dependence of the future outcomes on the past mediators. We assume that the effects of nearby mediators simply sum up:  $f_{m}(\tau; \mathbf{m}) = \sum_{i: t_{i} \leq \tau} l(m_{i}) f_{m}^{0}(\tau - t_{i})$ , where  $f_{m}^{0} \sim \mathcal{GP}$  describes a shared shape function and the magnitude of the effect depends on the mark  $m_{i}$  through a function  $l(m_{i})$ .
In this section, we validate the ability of our method to separate direct and indirect effects of a healthcare intervention on interacting mediator-outcome processes. First, we show that our model can support clinical decision-making in real-world data from a randomized controlled trial (RCT) about the effect of gastric bypass surgery (treatment) on meal-blood glucose (mediator-outcome) dynamics. Second, as the true causal effects are unknown in the real-world data, we set up a realistic, semi-synthetic simulation study, where we evaluate the performance of our model on two causal tasks: estimating direct and indirect effect trajectories. Our implementation and code to reproduce the study can be found at https://github.com/caglar-hizli/dynamic-causal-mediation.
5.1 Real-World Study
We first show on data from a real-world RCT [Saarinen et al., 2019, Ashrafi et al., 2021] that our model can learn clinically-meaningful direct and indirect effects of bariatric surgery on blood glucose, by analyzing how surgery affects glucose through changed diet (indirectly) or other metabolic processes (directly). For further details, see Appendix C.1.
Dataset. For 15 nondiabetic obesity patients (body mass index,  $\mathrm{BMI} \geq 35\mathrm{kg} / \mathrm{m}^2$ ) undergoing a gastric bypass surgery, a continuous-monitoring device measured the blood glucose of each patient at 15-minute intervals. Patients recorded their meals in a food diary, and the nutrient information was processed into total carbohydrates (sugar + starch) for each meal. Data was collected over two 3-day long periods: (i) pre-surgery and (ii) post-surgery.
Causal Assumptions. Assumption (A1) implies a treatment that is non-informative. The surgery does not depend on patient characteristics (each patient undergoes the surgery), therefore (A1) holds. If this was not the case, we could have used a debiasing method such as inverse probability treatment weighting [Robins et al., 2000a]. Assumptions (A2, A3) imply that (i) path-specific treatments  $A \rightarrow M$  and  $A \rightarrow Y$  affect only their target path and (ii) there is no unobserved confounding between mediators and outcomes. They do not exactly hold in the study. For (i), one way to realize  $A \rightarrow M$  is a dietary intervention that only changes the diet; however, it might not be possible to change the rest of the metabolic processes through  $A \rightarrow Y$  without affecting the diet. For (ii), demographic factors such as age, gender, body weight, and height could be potential confounder variables that could bias the estimation of surgery effects. Moreover, there can be unobserved processes such as exercising habits that affect both meals and blood glucose, even though the impact of confounders other than meals on blood glucose is likely modest for nondiabetics, since blood glucose is known to be relatively stable between meals [Ashrafi et al., 2021].
5.1.1 Bariatric Surgery Regulates Glucose Through Meals and Other Metabolic Processes
To visualize the effect of the surgery on meal-blood glucose dynamics, we show 1-day long meal-glucose measurements for one patient together with predicted glucose trajectories from our outcome model in both pre- and post-surgery periods in Fig. 1. For blood glucose, we see, after the surgery, (i) the baseline declines, and (ii) a meal produces a faster rise and decline. For meals, we see, after the surgery, the patient eats (i) more frequently and (ii) less carbohydrate per meal.
5.1.2 Direct and Indirect Effects of the Surgery on Meal Response Curves
We compare the predicted glucose baseline  $f_{b}$  and the predicted meal response  $f_{m}$  for all patients in Fig. 4. In Fig. 4a, after the surgery, the glucose baseline declines in agreement with previous findings [Dirksen et al., 2012, Jacobsen et al., 2013]. In Fig. 4b, we see meal responses corresponding to four hypothetical scenarios. In the upper-left, we predict a typical presurgery meal response and highlight the area under this curve by shaded grey. In the upper-right, we predict the hypothetical meal response by considering only the surgical effect on metabolism, while keep
ing the diet in its natural pre-surgery state. Here, the meal response increases to a higher peak and declines back to the baseline faster than the shaded pre-surgery response, as previously described
(a) Baseline progression.
(b) Meal response functions.
Figure 4: Pre- vs. post-surgery predicted glucose progressions: (a) Baseline, (b) Meal response.
[Jacobsen et al., 2013, Bojsen-Møller et al., 2014]. Moreover, the response model captures the decline under the baseline around  $2\mathrm{h}$  after a meal and a correction afterwards, which is a clinicallymeaningful estimation suggesting overshooting of the glucose lowering due to the higher secretion of insulin after the surgery [Jacobsen et al., 2013, Bojsen-Møller et al., 2014]. In the lower-left, we predict the hypothetical meal response if patients only followed the post-surgery diet, while their metabolism would be fixed in its natural pre-surgery state. Here, the meal response increases to a lower peak due to a lower carbohydrate intake, while the shape of the response is preserved. In the lower-right, we predict a typical post-surgery response, which increases to a lower peak due to lower carbohydrate intake and declines back to the baseline faster compared to the pre-surgery response due to the high insulin levels.
5.1.3 Surgery Leads to Shorter Meal Intervals and Less Carbohydrate Intake
We compare meal data and predictions from the mediator model between the pre- and post-surgery periods in Fig. 5. The surgery leads to a more regular, low-carb diet due to the post-surgery dietary advice, a reduction in the stomach size, and an increase in appetite-regulating gut hormone levels [Dirksen et al., 2012, Laferrière and Pattou, 2018]. In Fig. 5a, we see that the surgery leads to a more peaky, unimodal distribution for the next meal time, compared to the multimodal pre-surgery distribution. The average time interval until the next meal decreases from  $3.16\mathrm{h}$  to  $2.41\mathrm{h}$ . In Fig. 5b, we see that the post-surgery carbohydrate intake is more concentrated around the mean. The median per-meal carbohydrate intake decreases from  $29.13\mathrm{g}$  to  $11.94\mathrm{g}$ .
5.1.4 Would intervening on the mediator (diet) suffice to regularize glucose progression?
As shown in Figs. 1, 4 and 5, the surgery affects glycemia through changing the diet (indirect) and other biological processes (direct). Then, a relevant research question is how much of the surgery effect can be attributed to the changed diet?
This question is crucial in assessing whether surgery affects blood glucose levels independently of dietary changes. If confirmed, it implies that surgery can influence blood glucose through two mechanisms: controlling meal size and independent hormonal changes. Additionally, surgery can also induce too low glucose levels (hypoglycemia), if the glucose peak after the meal induces too high insulin secretion [Lee et al., 2016].
To measure the contribution of direct and indirect causal paths, we use two metrics: (i) the percentage time spent in hypoglycemia  $(\mathrm{HG})\% T_{\mathrm{HG}} = \{t:y(t)\leq 3.9\mathrm{mmol / l}\} /T,$  and (ii) the percentage time spent in above-normal-glycemia ANG  $\% T_{\mathrm{ANG}} = \{t$ $y(t)\geq 5.6\mathrm{mmol / l}\} /T.$  We estimate direct, indirect and total effects on  $\% T_{\mathrm{HG}}$  and  $\% T_{\mathrm{ANG}}$  as in Eqs.4 to 6.We show the results in Table 1. In the empirical data,  $\% T_{\mathrm{HG}}$  increased 27.5 points, while  $\% T_{\mathrm{ANG}}$  decreased 27.0 points. For the estimation of direct and indirect effects, we train our joint model on the RCT data set and use samples
from the posterior to obtain a Monte Carlo approximation. The results suggest that the contribution of the changed diet (indirect, NIE) to the total effect in  $\% T_{\mathrm{HG}}$  and  $\% T_{\mathrm{ANG}}$  is much smaller compared to other metabolic processes (direct, NDE). Our computational exploration of these effects from observational data is supported empirically by Laferrère et al. [2008], who study the effects of two
(a) Next meal arrival time.
Figure 5: Pre- vs. post-surgery data (histograms) and model posterior (kernel density estimate, dashed) for (a) next meal time and (b) (log) carbohydrate intake.
(b) Carbohydrate intake.
Table 1: NDE, NIE and TE results for % time spent in hypoglycemia  $\% T_{\mathrm{HG}}$  and in above-normal-glycemia  $\% T_{\mathrm{ANG}}$ , to investigate how much of the surgery effect can be attributed to a changed diet?
DATA
TYPE	CAUSAL
EFFECT	Δ%THG	Δ%TANG
Empirical data	TE	+27.5	-27.0
Simulation	TE	+24.4 ± 0.2	-28.0 ± 0.5
NDE	+24.7 ± 0.2	-26.4 ± 0.5
NIE	-0.3 ± 0.2	-1.5 ± 0.3
Table 2: Mean squared error (MSE, mean ± std.dev. across 10 runs) for NDE, NIE and TE.
JOINT
MODEL	MODEL COMPONENTS	CAUSAL QUERY (MSE ↓)
A→Y	MEDIATOR	RESPONSE	NDE(˜a)	NIE(˜a)	TE(˜a)
M1	✓	Non-interact. (L15)	Parametric (S17)	0.22 ± 0.02	0.12 ± 0.01	0.31 ± 0.02
M2	✓	Non-interact. (L15)	Non-param. (H22)	0.04 ± 0.00	0.15 ± 0.01	0.16 ± 0.02
M3	✓	Interacting (H22)	Parametric (S17)	0.23 ± 0.02	0.11 ± 0.01	0.31 ± 0.02
Z21-1	✓	Interacting (H22)	Parametric (Z21)	0.07 ± 0.00	0.09 ± 0.01	0.16 ± 0.01
Z21-2	✓	ORACLE	Parametric (Z21)	0.07 ± 0.00	0.04 ± 0.00	0.11 ± 0.01
H22	X	Interacting (H22)	Non-param. (H22)	-	-	1.14 ± 0.07
Our	✓	Interacting (H22)	Non-param. (H22)	0.02 ± 0.00	0.09 ± 0.01	0.10 ± 0.01
different interventions — namely, dietary changes and surgical procedures — on individuals who had lost equal amounts of weight. In the study, the blood glucose response to a fixed carbohydrate meal shows a more pronounced decline in the surgery group compared to the control group. Because all patients received the same meal, this decline corresponds to the direct effect. This direct effect can be attributed to a range of intricate hormonal influences, including the involvement of gut hormones like GLP-1, alongside heightened insulin peaks subsequent to surgical intervention.
5.2 Semi-Synthetic Simulation Study
In this section, we set up a semi-synthetic simulation study to evaluate the proposed method on two causal tasks: estimating (i) natural direct effect (NDE) and (ii) natural indirect effect (NIE). For further details and additional results on sensitivity analysis, see Appendices C.2 and D.
**Simulator.** We train our joint model on the real-world RCT data set, and then use the learned model as the ground-truth meal-blood glucose simulator. One joint model is learned for each of the pre- and post-surgery periods. For the meal simulator, we use a mediator model learned on all patients. For the glucose simulator, we use an outcome model learned on a subset of three patients with distinct baselines and meal response functions to enable individualization between synthetic patients.
Semi-synthetic dataset. We use the ground-truth simulators to sample meal-glucose trajectories for 50 synthetic patients. As in the RCT in Section 5.1, we assume each patient undergoes the surgery in the semi-synthetic scenario while being observed in pre- and post-surgery periods. For the training set, we sample 1-day long trajectories for pre- and post-surgery periods. For the test set, we sample three interventional trajectories for each patient for the subsequent 1-day, corresponding to three interventional distributions resulting from the following interventions:  $\{[\emptyset ,\emptyset ],[\emptyset ,\tilde{t}_a],[\tilde{t}_a,\tilde{t}_a]\}$ . Then, the ground-truth NIE and NDE trajectories are calculated as in Eqs. (4) and (5), respectively.
**Benchmarks.** We compare methods with respect to their abilities in (i) allowing for an external intervention that jointly affects mediator and outcome processes, and (ii) capturing non-linear, long-range dependencies between these processes. For (i), we add a benchmark model [H22, Hizli et al., 2023] that excludes the direct arrows from the treatment to the outcomes  $(A\rightarrow Y)$ . For (ii), we combine different interacting/non-interacting mediator models and parametric/non-parametric response functions to obtain baseline methods that include the direct arrows  $(A\rightarrow Y)$ . The methods Z21-1 and Z21-2 are named after a longitudinal causal mediation method [Zeng et al., 2021] with linear, instantaneous effects from mediator to outcome [Parametric (Z21), Zeng et al., 2021] (Fig. 2a). Additionally, we include a parametric response [Parametric (S17), Schulam and Saria, 2017] (M1, M3), and a non-parametric response [Non-parametric (H22), Hizli et al., 2023] (M2). The non-interacting mediator model is chosen as a history-independent, non-homogeneous Poisson process [Non-interacting (L15), Lloyd et al., 2015] (M1, M2), while the interacting mediator model is chosen as a history-dependent, non-parametric point process model [Interacting (H22), Hizli et al., 2023] (M3, Z21-1). In the joint model Z21-2, we further combine the parametric response model by Zeng et al. [2021] (Parametric (Z21)) with the ground-truth (ORACLE) mediator sequence.
Metric. On the test set, we report the mean squared error (MSE) between ground-truth and estimated trajectories. To sample comparable glucose trajectories, three interventional trajectories are simulated with fixed noise variables for meal (point process) sampling for all methods, as in Hizli et al. [2023].
Results. MSE results are shown in Table 2. For the natural direct effect, formalized as  $\mathrm{NDE}(\tilde{t}_a) = \mathbf{Y}_{>\tilde{t}_a}[\tilde{t}_a,\tilde{t}_a] - \mathbf{Y}_{>\tilde{t}_a}[\emptyset ,\tilde{t}_a]$ , we answer the causal query: How differently will the glucose progress if we change only the metabolic processes other than the diet, while keeping the diet at its natural post-surgery value? We see that our joint model performs the best compared to the other methods. The models with the non-parametric response produce better NDE trajectories than the models with the parametric response, which fail to capture the glucose baseline and the meal response well. For the natural indirect effect, formalized as  $\mathrm{NIE}(\tilde{t}_a) = \mathbf{Y}_{>\tilde{t}_a}[\emptyset ,\tilde{t}_a] - \mathbf{Y}_{\tilde{t}_a}[\emptyset ,\emptyset ]$ , we answer the causal query: How will the glucose progress if we change only the diet, while keeping the rest of the metabolic processes at their natural pre-surgery state? The oracle model Z21-2 that directly uses the mediator sequences sampled from the ground-truth simulator performs better than other methods. Our joint model performs better than the other methods that predict the mediator sequence, and it performs the same compared to the model Z21-1 which also uses the interacting mediator model. In contrast to the NDE results, the performance on the NIE improves with respect to the expressiveness of the mediator model, e.g. models with the interacting point process (M3, Z21-1, Our) perform better than the models with the non-interacting mediator (M1, M2). Similarly, the oracle model that has access to the ground-truth mediator sequences performs the best. For the total effect, formalized as  $\mathrm{TE}(\tilde{t}_a) = \mathbf{Y}_{>\tilde{t}_a}[\tilde{t}_a,\tilde{t}_a] - \mathbf{Y}_{\tilde{t}_a}[\emptyset ,\emptyset ]$ , our joint model performs similar to the model Z21-2 that has access to the ground-truth mediators, while performing better than all the rest.
As required for causal inference, our identifiability result relies on causal assumptions, which may not hold in an observational study and are not statistically testable. For example, our assumption that there are no unobserved confounders between the mediator and outcome processes may not hold. To understand the sensitivity to this assumption, we performed an additional preliminary analysis in Appendix D, which can be refined in future work by extending the sensitivity analysis methods used in the static setting [Robins et al., 2000b]. In addition, our method relies on a hypothetical division of a treatment into path-specific treatments which solely affect the variables in their own path. This may not be possible in reality, e.g., it is not trivial to come up with a treatment that changes all the other metabolic processes without affecting the diet in our surgery-diet-blood glucose example.
In our real-world application, we focus on the dynamic causal mediation problem where the sequence of meals is the mediator of the effect of surgery on blood glucose. In this definition, the rest of the metabolic processes, e.g., gut hormones, weight loss, hepatic insulin sensitivity, or any other mediator through which the surgery could affect blood glucose, are included in the direct effect. An extension to multiple mediators and an explicit quantification of the corresponding path-specific effects will be an interesting future direction, especially from a medical point of view. In the semi-synthetic study, our joint model matches the functional class of the simulator; in future work, it would be valuable to further analyze the effect of model misspecification.
From a modeling perspective, the main limitation is scalability of the outcome model to a larger number of data points (see Appendix B.5 for details). This can be improved using separate sets of inducing points for the baseline function and the treatment response function. Alternatively, the GP models describing the components of our joint distribution (Eq. (8)) could be replaced by other model classes (e.g., neural networks). Our dynamic causal mediation framework does not put any fundamental limitations on the dimensionality of mediators or outcome.
We investigated temporal causal mediation in complex healthcare time-series by defining direct and indirect effects as stochastic processes instead of static random variables. Theoretically, we provided causal assumptions required for identifiability. To estimate the effects, we proposed a non-parametric mediator-outcome model that allows for an external intervention jointly affecting mediator and outcome sequences, while capturing time-delayed interactions between them. Despite the limitations, in a real-world study about the effect of bariatric surgery on meal-blood glucose dynamics, our method identified clinically-meaningful direct and indirect effects. This demonstrates how the model can be used for gaining insights from observational data without tedious or expensive experiments and supports its use for generating novel, testable research hypotheses. We believe that our method can lead to insightful analyses also in other domains such as epidemiology, public policy, and beyond.
Tyler J VanderWeele and Eric J Tchetgen Tchetgen. Mediation analysis with time varying exposures and mediators. Journal of the Royal Statistical Society Series B: Statistical Methodology, 79(3): 917-938, 2017.
Stijn Vansteelandt, Martin Linder, Sjouke Vandenberghe, Johan Steen, and Jesper Madsen. Mediation analysis of time-to-event endpoints accounting for repeatedly measured mediators subject to time-varying confounding. *Statistics in Medicine*, 38(24):4828-4840, 2019.
Christopher KI Williams and Carl Edward Rasmussen. Gaussian processes for machine learning, volume 2. MIT press Cambridge, MA, 2006.
Alan C Wittgrove, G Wesley Clark, and Laurier J Tremblay. Laparoscopic gastric bypass, Roux-en-Y: preliminary report of five cases. Obesity surgery, 4(4):353-357, 1994.
Patrick Wyatt, Sarah E Berry, Graham Finlayson, Ruairi O'Driscoll, George Hadjigeorgiou, David A Drew, Haya Al Khatib, Long H Nguyen, Inbar Linenberg, Andrew T Chan, et al. Postprandial glycaemic dips predict appetite and energy intake in healthy individuals. Nature Metabolism, 3(4): 523-529, 2021.
Yanbo Xu, Yanxun Xu, and Suchi Saria. A Bayesian nonparametric approach for estimating individualized treatment-response curves. In Machine Learning for Healthcare Conference, pages 282-300. PMLR, 2016.
Shuxi Zeng, Stacy Rosenbaum, Susan C Alberts, Elizabeth A Archie, and Fan Li. Causal mediation analysis for sparse and irregular longitudinal data. Annals of Applied Statistics, 15(2):747-767, 2021.
Guangyi Zhang, Reza A. Ashrafi, Anne Juuti, Kirsi Pietilainen, and Pekka Marttinen. Errors-in-variables modeling of personalized treatment-response trajectories. IEEE J. Biomed. Health Informatics, 25(1):201-208, 2021.
Yizhou Zhang, Defu Cao, and Yan Liu. Counterfactual neural temporal point process for estimating causal influence of misinformation on social media. Advances in Neural Information Processing Systems, 35:10643-10655, 2022.
Wenjing Zheng and Mark van der Laan. Longitudinal mediation analysis with time-varying mediators and exposures, with application to survival outcomes. Journal of Causal Inference, 5(2), 2017.
A Causal Assumptions and Identifiability
A.1 Static Causal Mediation