ESTIMATING COUNTERFACTUAL TREATMENT OUTCOMES OVER TIME THROUGH ADVERSARIALLY BALANCED REPRESENTATIONS
Year: 2020

Abstract:
Identifying when to give treatments to patients and how to select among multiple treatments over time are important medical problems with a few existing solutions. In this paper, we introduce the Counterfactual Recurrent Network (CRN), a novel sequence-to-sequence model that leverages the increasingly available patient observational data to estimate treatment effects over time and answer such medical questions. To handle the bias from time-varying confounders, covariates affecting the treatment assignment policy in the observational data, CRN uses domain adversarial training to build balancing representations of the patient history. At each timestep, CRN constructs a treatment invariant representation which removes the association between patient history and treatment assignments and thus can be reliably used for making counterfactual predictions. On a simulated model of tumour growth, with varying degree of time-dependent confounding, we show how our model achieves lower error in estimating counterfactuals and in choosing the correct treatment and timing of treatment than current state-of-the-art methods.

heading: 1 INTRODUCTION
text: As clinical decision-makers are often faced with the problem of choosing between treatment alternatives for patients, reliably estimating their effects is paramount. While clinical trials represent the gold standard for causal inference, they are expensive, have a few patients and narrow inclusion criteria (Booth & Tannock, 2014). Leveraging the increasingly available observational data about patients, such as electronic health records, represents a more viable alternative for estimating treatment effects.
A large number of methods have been proposed for performing causal inference using observational data in the static setting (Johansson et al., 2016; Shalit et al., 2017; Alaa & van der Schaar, 2017; Li & Fu, 2017; Yoon et al., 2018; Alaa & van der Schaar, 2018; Yao et al., 2018) and only a few methods address the longitudinal setting (Xu et al., 2016; Roy et al., 2016; Soleimani et al., 2017; Schulam & Saria, 2017; Lim et al., 2018). However, estimating the effects of treatments over time poses unique opportunities such as understanding how diseases evolve under different treatment plans, how individual patients respond to medication over time, but also which are optimal timings for assigning treatments, thus providing new tools to improve clinical decision support systems.
The biggest challenge when estimating the effects of time-dependent treatments from observational data involves correctly handling the time-dependent confounders: patient covariates that are affected by past treatments which then influence future treatments and outcomes (Platt et al., 2009). For instance, consider that treatment A is given when a certain patient covariate (e.g. white blood cell
count) has been outside of normal range values for several consecutive timesteps. Suppose also that this patient covariate was itself affected by the past administration of treatment B. If these patients are more likely to die, without adjusting for the time-dependent confounding (e.g. the changes in the white blood cell count over time), we will incorrectly conclude that treatment A is harmful to patients. Moreover, estimating the effect of a different sequence of treatments on the patient outcome would require not only adjusting for the bias at the current step (in treatment A), but also for the bias introduced by the previous application of treatment B.
Existing methods for causal inference in the static setting cannot be applied in this longitudinal setting since they are designed to handle the cross-sectional set-up, where the treatment and outcome depend only on a static value of the patient covariates. If we consider again the above example, these methods would not be able to model how the changes in patient covariates over time affect the assignment of treatments and they would also not be able to estimate the effect of a sequence of treatments on the patient outcome (e.g. sequential application of treatment A followed by treatment B). Different models that can handle these temporal dependencies in the observational data and varying-length patient histories are needed for estimating treatment effects over time.
Time-dependent confounders are present in observational data because doctors follow policies: the history of the patients’ covariates and the patients’ response to past treatments are used to decide future treatments (Mansournia et al., 2012). The direct use of supervised learning methods will be biased by the treatment policies present in the observational data and will not be able to correctly estimate counterfactuals for different treatment assignment policies.
Standard methods for adjusting for time-varying confounding and estimating the effects of timevarying exposures are based on ideas from epidemiology. The most widely used among these are Marginal Structural Models (MSMs) (Robins et al., 2000; Mansournia et al., 2012) which use the inverse probability of treatment weighting (IPTW) to adjust for the time-dependent confounding bias. Through IPTW, MSMs create a pseudo-population where the probability of treatment does not depend on the time-varying confounders. However, MSMs are not robust to model misspecification in computing the IPTWs. MSMs can also give high-variance estimates due to extreme weights; computing the IPTW involves dividing by probability of assigning a treatment conditional on patient history which can be numerically unstable if the probability is small.
We introduce the Counterfactual Recurrent Network (CRN), a novel sequence-to-sequence architecture for estimating treatment effects over time. CRN leverages recent advances in representation learning (Bengio et al., 2012) and domain adversarial training (Ganin et al., 2016) to overcome the problems of existing methods for causal inference over time. Our main contributions are as follows.
Treatment invariant representations over time. CRN constructs treatment invariant representations at each timestep in order to break the association between patient history and treatment assignment and thus removes the bias from time-dependent confounders. For this, CRN uses domain adversarial training (Ganin et al., 2016; Li et al., 2018; Sebag et al., 2019) to trade-off between build-
ing this balancing representation and predicting patient outcomes. We show that these representations remove the bias from time-varying confounders and can be reliably used for estimating counterfactual outcomes. This represents the first work that introduces ideas from domain adaptation to the area of estimating treatment effects over time. In addition, by building balancing representations, we propose a novel way of removing the bias introduced by time-varying confounders.
Counterfactual estimation of future outcomes. To estimate counterfactual outcomes for treatment plans (and not just single treatments), we integrate the domain adversarial training procedure as part of a sequence-to-sequence architecture. CRN consists of an encoder network which builds treatment invariant representations of the patient history that are used to initialize the decoder. The decoder network estimates outcomes under an intended sequence of future treatments, while also updating the balanced representation. By performing counterfactual estimation of future treatment outcomes, CRN can be used to answer critical medical questions such as deciding when to give treatments to patients, when to start and stop treatment regimes, and also how to select from multiple treatments over time. We illustrate in Figure 1 the applicability of our method in choosing optimal cancer treatments.
In our experiments, we evaluate CRN in a realistic set-up using a model of tumour growth (Geng et al., 2017). We show that CRN achieves better performance in predicting counterfactual outcomes, but also in choosing the right treatment and timing of treatment than current state-of-the-art methods.

heading: 2 RELATED WORK
text: We focus on methods for estimating treatment effects over time and for building balancing representations for causal inference. A more in-depth review of related work is in Appendix A.
Treatment effects over time. Standard methods for estimating the effects of time-varying exposures were first developed in the epidemiology literature and include the g-computation formula, Structural Nested Models and Marginal Structural Models (MSMs) (Robins, 1986; 1994; Robins et al., 2000; Robins & Hernán, 2008). Originally, these methods have used predictors performing logistic/linear regression which makes them unsuitable for handling complex time-dependencies (Hernán et al., 2001; Mansournia et al., 2012; Mortimer et al., 2005). To address these limitations, methods that use Bayesian non-parametrics or recurrent neural networks as part of these frameworks have been proposed. (Xu et al., 2016; Roy et al., 2016; Lim et al., 2018).
To begin with, Xu et al. (2016) use Gaussian processes to model discrete patient outcomes as a generalized mixed-effects model and uses the g-computation method to handle time-varying confounders. Soleimani et al. (2017) extend the approach in Xu et al. (2016) to the continuous time-setting and model treatment responses using linear time-invariant dynamical systems. Roy et al. (2016) use Dirichlet and Gaussian processes to model the observational data and estimate the IPTW in Marginal Structural Models. Schulam & Saria (2017) build upon work from Lok et al. (2008); Arjas & Parner (2004) and use marked point processes and Gaussian processes to learn causal effects in continuous-time data. These Bayesian non-parametric methods make strong assumptions about model structure and consequently cannot handle well heterogeneous treatment effects arising from baseline variables (Soleimani et al., 2017; Schulam & Saria, 2017) and multiple treatment outcomes (Xu et al., 2016; Schulam & Saria, 2017).
The work most related to ours is the one of Lim et al. (2018) which improves on the standard MSMs by using recurrent neural networks to estimate the inverse probability of treatment weights (IPTWs). Lim et al. (2018) introduces Recurrent Marginal Structural Networks (RMSNs) which also use a sequence-to-sequence deep learning architecture to forecast treatment responses in a similar fashion to our model. However, RMSNs require training additional RNNs to estimate the propensity weights and does not overcome the fundamental problems with IPTWs, such as the high-variance of the weights. Conversely, CRN takes advantage of the recent advances in machine learning, in particular, representation learning to propose a novel way of handling time-varying confounders.
Balancing representations for treatment effect estimation. Balancing the distribution of control and treated groups has been used for counterfactual estimation in the static setting. The methods proposed in the static setting for balancing representations are based on using discrepancy measures in the representation space between treated and untreated patients, which do not generalize to multiple treatments (Johansson et al., 2016; Shalit et al., 2017; Li & Fu, 2017; Yao et al., 2018). Moreover, due to the sequential assignment of treatments in the longitudinal setting, and due to the change of
patient covariates over time according to previous treatments, the methods for the static setting are not directly applicable to the time-varying setting (Hernán et al., 2000; Mansournia et al., 2012).

heading: 3 PROBLEM FORMULATION
text: Consider an observational datasetD = { {x(i)t ,a(i)t ,y(i)t+1}T (i) t=1 ∪{v(i)} }N i=1 consisting of information about N independent patients. For each patient (i), we observe time-dependent covariates X(i)t ∈ Xt, treatment received A(i)t ∈ {A1, . . . AK} = A and outcomes Y(i)t+1 ∈ Yt+1 for T (i) discrete timesteps. The patient can also have baseline covariates V(i) ∈ V such as gender and genetic information. Note that the outcome Y(i)t+1 will be part of the observed covariates X (i) t+1. For simplicity, the patient superscript (i) will be omitted unless explicitly needed.
We adopt the potential outcomes framework proposed by (Neyman, 1923; Rubin, 1978) and extended by (Robins & Hernán, 2008) to account for time-varying treatments. Let Y[ā] be the potential outcomes, either factual or counterfactual, for each possible course of treatment ā. Let H̄t = (X̄t, Āt−1,V) represent the history of the patient covariates X̄t = (X1, . . . ,Xt), treatment assignments Āt = (A1, . . . ,At) and static features V. We want to estimate:
E(Yt+τ [ā(t, t+ τ − 1)]|H̄t), (1) where ā(t, t+ τ − 1) = [at, . . .at+τ−1] represents a possible sequence of treatments from timestep t just until before the potential outcome Yt+τ is observed. We make the standard assumptions (Robins et al., 2000; Lim et al., 2018) needed to identify the treatment effects: consistency, positivity and no hidden confounders (sequential strong ignorability). See Appendix B for more more details.

heading: 4 COUNTERFACTUAL RECURRENT NETWORK
text: The observational data can be used to train a supervised learning model to forecast: E(Yt+τ | Ā(t, t+ τ − 1) = ā(t, t+ τ − 1), H̄t). However, without adjusting for the bias introduced by timevarying confounders, this model cannot be reliably used for making causal predictions (Robins et al., 2000; Robins & Hernán, 2008; Schulam & Saria, 2017). The Counterfactual Recurrent Network (CRN) removes this bias through domain adversarial training and estimates the counterfactual outcomes E(Yt+τ [ā(t, t+ τ − 1)]|H̄t), for any intended future treatment assignment ā(t, t+ τ − 1). Balancing representations. The history H̄t = (X̄t, Āt−1,V) of the patient contains the timevarying confounders X̄t which bias the treatment assignment At ∈ {A1, . . . AK} in the observational dataset. Inverse probability of treatment weighting, as performed by MSMs, creates a pseudopopulation where the probability of treatment At does not depend on the time-varying confounders (Robins et al., 2000). In this paper, we propose instead building a representation of the history H̄t that is not predictive of the treatment At. This way, we remove the association between history, containing the time-varying confounders X̄t, and current treatment At. Robins (1999) shows that in this case, the estimation of counterfactual treatment outcomes is unbiased. See Appendix C for details and for an example of a causal graph with time-dependent confounders.
Let Φ be the representation function that maps the patient history H̄t to a representation space R. To obtain unbiased treatment effects, Φ needs to construct treatment invariant representations such that P (Φ(H̄t) | At = A1) = · · · = P (Φ(H̄t) | At = AK). To achieve this and to estimate counterfactual outcomes under a planned sequence of treatments, we integrate the domain adversarial training framework proposed by Ganin et al. (2016) and extended by Sebag et al. (2019) to the multi-domain learning setting, into a sequence-to-sequence architecture. In our case, the different treatments at each timestep are considered the different domains. Note that the novelty here comes from the use of domain adversarial training to handle the bias from the time-dependent confounders, rather than the use of sequence-to-sequence models, which have already been applied to forecast treatment responses (Lim et al., 2018). Figure 2 illustrates our model architecture.
Encoder. The encoder network uses an RNN, with LSTM unit (Hochreiter & Schmidhuber, 1997), to process the history of treatments Āt−1, covariates X̄t and baseline features V to build a treatment invariant representation Φ(H̄t), but also to predict one-step-ahead outcomes Yt+1. To achieve this, the encoder network aims to maximize the loss of the treatment classifier Ga and minimize the loss
of the outcome predictor network Gy . This way, the balanced representation Φ(H̄t) is not predictive of the assigned treatment At, but is discriminative enough to estimate the outcome Yt+1. To train this model using gradient descent, we use the Gradient Reversal Layer (Ganin et al., 2016).
Decoder. The decoder network uses the balanced representation computed by the encoder to initialize the state of an RNN that predicts the counterfactual outcomes for a sequence of future treatments. During training, the decoder uses as input the outcomes from the observational data (Yt+1, . . .Yt+τ−1), the static patient features V and the intended sequence of treatments ā(t, t+ τ − 1). The decoder is trained in a similar way to the encoder to update the balanced representation and to estimate the outcomes. During testing, we do not have access to ground-truth outcomes; thus, the outcomes predicted by the decoder (Ŷt+1, . . . Ŷt+τ−1) are auto-regressively used instead as inputs. By running the decoder with different treatment settings, and by auto-regressively feeding back the outcomes, we can determine when to start and end different treatments, which is the optimal time to give the treatment and which treatments to give over time to obtain the best patient outcomes.
The representation Φ(H̄t) is built by applying a fully connected layer, with Exponential Linear Unit (ELU) activation to the output of the LSTM. The treatment classifier Ga and the predictor network Gy consist of a hidden layer each, also with ELU activation. The output layer of Ga uses softmax activation, while the output layer of Gy uses linear activation for continuous predictions. For categorical outcomes, softmax activation can be used. We follow an approach similar to Lim et al. (2018) and we split the encoder and decoder training into separate steps. See Appendix E for details.
The encoder and decoder networks use variational dropout (Gal & Ghahramani, 2016) such that the CRN can also give uncertainty intervals for the treatment outcomes. This is particularity important in the estimation of treatment effects, since the model predictions should only be used when they have high confidence. Our model can also be modified to allow for irregular samplings of observations by using a PhasedLSTM (Neil et al., 2016).

heading: 5 ADVERSARIALLY BALANCED REPRESENTATION OVER TIME
text: At each timestep t, let the K different possible treatments At ∈ {A1, . . . AK} represent our domains. As described in Section 4, to remove the bias from time-dependent confounders, we build a representation of history H̄t that is invariant across treatments: P (Φ(H̄t) | A1) = · · · = P (Φ(H̄t) | AK). This requirement can be enforced by minimizing the distance in the distribution of Φ(H̄t) between any two pairs of treatments. Kifer et al. (2004); Ben-David et al. (2007), propose measuring the disparity between distributions based on their separability by a discriminatively-trained classifier. Let the symmetric hypothesis classH consist of the set of symmetric multiclass classifiers, such as neural network architectures. TheH-divergence between all pairs of two distributions is defined in terms of the capacity of the hypothesis classH to discriminate between examples from the multiple distributions. Empirically, minimizing theH−divergence involves building a representation where examples from the multiple domains are as indistinguishable as possible (Ben-David et al., 2007; Li et al., 2018; Sebag et al., 2019). Ganin et al. (2016) use this idea to propose an adversarial framework
for domain adaptation involving building a representation which achieves maximum error on a domain classifier and minimum error on an outcome predictor. Similarly, in our case, we use domain adversarial training to build a representation of the patient history Φ(H̄t) that is both invariant to the treatment given at timestep t, At and that achieves low error in estimating the outcome Yt+1.
Let Ga(Φ(H̄t); θa) be the treatment classifier with parameters θa and let Gja(Φ(H̄t); θa) be the output corresponding to treatment Aj . Let Gy(Φ(H̄t); θy) be the predictor network with parameters θy. The representation function Φ is parameterized by the parameters θr in the RNN: Φ(H̄t; θr). Figure 3 shows the adversarial training procedure used.
For timestep t and patient (i), let L(i)t,a(θr, θa) be the treatment (domain) loss and let L(i)t,y(θr, θy) the outcome loss, defined as follows: L(i)t,a(θr, θa) = − K∑ j=1 I{a(i)t =aj} log(G j a(Φ(H̄t; θr); θa))
(2)
L(i)t,y(θr, θy) = ‖Y(i)t+1 − (Gy(Φ(H̄t; θr), θy))‖2. (3)
If the outcome is binary, the cross-entropy loss can be used instead for Lt,y. To build treatment invariant representations and to also estimate patient outcomes, we aim to maximize treatment loss and minimize outcome loss.
Thus, the overall loss L(i)t,y at timestep t is given by:
L(i)t (θr, θy, θa) = N∑ i=1 L(i)t,y(θr, θy)− λL(i)t,a(θr, θa), (4)
where the hyperparameter λ controls this trade-off between domain discrimination and outcome prediction. We use the standard procedure for training domain adversarial networks from Ganin et al. (2016) and we start off with an initial value for λ and use an exponentially increasing schedule during training. To train the model using backpropagation, we use the Gradient Reversal Layer (GRL) (Ganin et al., 2016). For more details about the training procedure, see Appendix E.
By using the objective L(i)t (θr, θy, θa), we reach the saddle point (θ̂r, θ̂y, θ̂a) that achieves the equilibrium between domain discrimination and outcome estimation.
(θ̂r, θ̂y) = arg min θr,θy L(i)t (θr, θy, θ̂a) θ̂a = arg max θa L(i)t (θ̂r, θ̂y, θa). (5)
The result stated in Theorem 1 proves that the treatment (domain) loss part of our objective (from equation 2) aims to remove the time-dependent confounding bias.
Theorem 1. Let t ∈ {1, 2, . . . }. For each j = 1, ...,K, let Pj denote the distribution of H̄t conditional on At = Aj and let PΦj denote the distribution of Φ(H̄t) conditional on At = Aj . Let Gja denote the output of Ga corresponding to treatment Aj . Then the minimax game defined by
min Φ max Ga K∑ j=1 EH̄t∼Pj [ log(Gja(Φ(H̄t); θa)) ]
subject to K∑ j=1 Gja(Φ(H̄t)) = 1 (6)
has a global minimum which is attained if and only if PΦ1 = P Φ 2 = ... = P Φ K , i.e. when the learned representations are invariant across all treatments.
Proof. This result is a restatement of the one in Li et al. (2018). For details, see the Appendix D.
A good representation allows us to obtain a low error in estimating counterfactuals for all treatments, while at the same time to minimize theH-divergence between induced marginal distributions of all the domains. We use an algorithm that directly minimizes a combination of theH−divergence and the empirical training margin.

heading: 6 EXPERIMENTS
text: In real datasets, counterfactual outcomes and the degree of time-dependent confounding are not known (Schulam & Saria, 2017; Lim et al., 2018). To validate the CRN1, we evaluate it on a Pharmacokinetic-Pharmacodynamic model of tumour growth (Geng et al., 2017), which uses a stateof-the-art bio-mathematical model to simulate the combined effects of chemotherapy and radiotherapy in lung cancer patients. The same model was used by Lim et al. (2018) to evaluate RMSNs.
Model of tumour growth The volume of tumour t days after diagnosis is modelled as follows: V (t+ 1) = ( 1 + ρlog ( K V (t) ) ︸ ︷︷ ︸
Tumor growth
− βcC(t)︸ ︷︷ ︸ Chemotherapy
− ( αrd(t) + βrd(t) 2 )︸ ︷︷ ︸
Radiotherapy
+ et︸︷︷︸ Noise
) V (t)
(7)
whereK, ρ, βc, αr, βr, et are sampled as described in Geng et al. (2017). To incorporate heterogeneity in patient responses, the prior means for βc and αr are adjusted to create patient subgroups, which are used as baseline features. The chemotherapy concentration C(t) and radiotherapy dose d(t) are modelled as described in Appendix F. Time-varying confounding is introduced by modelling chemotherapy and radiotherapy assignment as Bernoulli random variables, with probabilities pc and pr depending on the tumour diameter: pc(t) = σ ( γc
Dmax (D̄(t)− δc)
) and pr(t) = σ ( γr
Dmax (D̄(t)− δr) )
where D̄(t) is the average diameter over the last 15 days, Dmax = 13cm, σ(·) is the sigmoid and δc = δr = Dmax/2. The amount of time-dependent confounding is controlled through γc, γr; the higher γ? is, the more important the history is in assigning treatments. At each timestep, there are four treatment options: no treatment, chemotherapy, radiotherapy, combined chemotherapy and radiotherapy. For details about data simulation, see Appendix F.
Benchmarks We used the following benchmarks for performance comparison: Marginal Structural Models (MSMs) (Robins et al., 2000), which use logistic regression for estimating the IPTWs and linear regression for prediction (see Appendix G for details). We also compare against the Recurrent Marginal Structural Networks (RMSNs) Lim et al. (2018), which is the current state-of-the-art model in estimating treatment responses. RMSNs use RNNs to estimate the IPTWs and the patient outcomes (details in Appendix H). To show that standard supervised learning models do not handle the timevarying confounders we compare against an RNN and a linear regression model, which receive as input treatments and covariates to predict the outcome (see Appendix I for details). Our model architecture follows the description in Sections 4 and 5, with full training details and hyperparameter optimization in Appendix J. To show the importance of adversarial training, we also benchmark against CRN (λ = 0) a model with the same architecture, but with λ = 0, i.e our model architecture without adversarial training.

heading: 6.1 EVALUATE MODELS ON COUNTERFACTUAL PREDICTIONS
text: Previous methods focused on evaluating the error only for factual outcomes (observed patient outcomes) (Lim et al., 2018). However, to build decision support systems, we need to evaluate how well the models estimate the counterfactual outcomes, i.e patient outcomes under alternative treatment options. The parameters γc and γr control the treatment assignment policy, i.e. the degree of time-dependent confounding present in the data. We evaluate the benchmarks under different degrees of time-dependent confounding by setting γ = γc = γr. For each γ we simulate a 10000 patients for training, 1000 for validation (hyperparameter tuning) and 1000 for out-of-sample testing. For the patients in the test set, for each time t, we also simulate counterfactuals Yt+1, represented by tumour volume V (t+ 1), under all possible treatment options.
1The implementation of the model can be found at https://bitbucket.org/mvdschaar/ mlforhealthlabpub/src/master/alg/counterfactual_recurrent_network/ and at https://github.com/ioanabica/Counterfactual-Recurrent-Network.
Figure 4 (a) shows the normalized root mean squared error (RMSE) for one-step ahead estimation of counterfactuals with varying degree of time-dependent confounding γ. The RMSE is normalized by the maximum tumour volume: Vmax = 1150cm3. The linear and MSM models provide a baseline for performance as they achieve the highest RMSE. While the use of IPTW in MSMs helps when γ increases, using linear modelling has severe limitations. When there is no time-dependent confounding, the machine learning methods achieve similar performance, close to 0.6% RMSE. As the bias in the dataset increases, the harder it becomes for the RNN and the CRN (λ = 0) to generalize to estimate outcomes of treatments not matching the training policy. When γ = 10, CRN improves by 48.1% on the same model architecture without domain adversarial training CRN (λ = 0).
Our proposed model achieves the lowest RMSE across all values of γ. Compared to RMSNs, CRN improves by ∼ 17% when γ > 6. To highlight the gains of our method even for smaller γ, Figure 4 (b) shows the RMSE for five-step ahead prediction (with counterfactuals generated as described in Section 6.2 and Appendix L). RMSNs also use a decoder for sequence prediction. However, RMSNs require training additional RNNs to estimate the IPTW, which are used to weight each sample during the decoder training. For τ -step ahead prediction, IPTW involves multiplying τ weights which can result in high variance. The results in Figure 4 (b) show the problems with using IPTW to handle the time-dependent confounding bias. See Appendix K for more results on multi-step ahead prediction.
Balancing representation: To evaluate whether the CRN has indeed learnt treatment invariant represenations, for γ = 5, we illustrate in Figure 5 the T-SNE embeddings of the balancing representations Φ(H̄t) built by the CRN encoder for test patients. We color each point by the treatment At ∈ {no treatment, chemotherapy, radiotherapy, combined chemotherapy and radiotherapy} received at timestep t to highlight the invariance of Φ(H̄t) across the different treatments. In Figure 5(b), we show Φ(H̄t) only for chemotherapy and radiotherapy for better understanding.

heading: 6.2 EVALUATE RECOMMENDING THE RIGHT TREATMENT AND TIMING OF TREATMENT
text: Evaluating the models just in terms of the RMSE on counterfactual estimation is also not enough for assessing their reliability when used as part of decision support systems. In this section we assess how well the models can select the correct treatment and timing of treatment for several forecasting horizons τ . We generate test sets consisting of 1000 patients where for each horizon τ and for each time t in a patient’s trajectory, there are τ options for giving chemotherapy at one of t, . . . t+ τ − 1 and τ options for giving radiotherapy at one of t, . . . t+ τ − 1. At the rest of the future timesteps, no treatment is applied. These 2τ treatment plans are assessed in terms of the tumour volume outcome Yt+τ . We select the treatment (chemotherapy or radiotherapy) that achieves lowest Yt+τ , and within the correct treatment the timing with lowest Yt+τ . We also compute the normalized RMSE for
predicting Yt+τ . See Appendix L for more details about the test set. The models are evaluated for 3 settings of γc and γr.
Table 1 shows the results for this evaluation set-up. The treatment accuracy denotes the percentage of patients for which the correct treatment was selected, while the treatment timing accuracy is the percentage for which the correct timing was selected. Note that when γc = 0 and γr = 5, RMSN and MSM select the wrong treatment timing for projection horizons τ > 4. CRN performs similarly among the different policies present in the observational data and achieve the lowest RMSE and highest accuracy in selecting the correct treatment and timing of treatment.
In Appendix M we also show the applicability of the CRN in more complex medical scenarios involving real data. We provide experimental results based on the Medical Information Mart for Intensive Care (MIMIC III) database (Johnson et al., 2016) consisting of electronic health records from patients in the ICU.

heading: 7 CONCLUSION
text: Despite its wide applicability, the problem of causal inference for time-dependent treatments has been relatively less studied compared to problem of causal inference in the static setting. Both new methods and theory are necessary to be able to harness the full potential of observational data for learning individualized effects of complex treatment scenarios. Further work in this direction is needed for proposing alternative methods for handling time-dependent confounders, for modelling combinations of treatments assigned over time or for estimating the individualized effects of time-dependent treatments with associated dosage.
In this paper, we introduced the Counterfactual Recurrent Network (CRN), a model that estimates individualized effects of treatments over time using a novel way of handling the bias from timedependent confounders through adversarial training. Using a model of tumour growth, we validated CRN in realistic medical scenarios and we showed improvements over existing state-of-the-art methods. We also showed the applicability of the CRN a real dataset consiting of patient electronic health records. The counterfactual predictions of CRN have the potential to be used as part of clinical decision support systems to address relevant medical challenges involving selecting the best treatments for patients over time, identify optimal treatment timings but also when the treatment is no longer needed. In future work, we will aim to build better balancing representations and to provide theoretical guarantees for the expected error on the counterfactuals.

heading: ACKNOWLEDGMENTS
text: We would like to thank the reviewers for their valuable feedback. The research presented in this paper was supported by The Alan Turing Institute, under the EPSRC grant EP/N510129/1 and by the US Office of Naval Research (ONR).

heading: A EXTENDED RELATED WORK
text: Causal inference in the static setting: A large number of methods have been proposed to learn treatment effects from observational data in the static setting. In this case, it is needed to adjust for the selection bias; bias caused by the fact that, in the observational dataset, the treatment assignments depend on the patient features. Several ways of handling the selection bias involve using propensity matching (Austin, 2011; Imai & Ratkovic, 2014; Abadie & Imbens, 2016), building representations where treated and un-treated populations had similar distributions (Johansson et al., 2016; Shalit et al., 2017; Li & Fu, 2017; Yao et al., 2018) or performing propensity-aware hyperparameter tuning (Alaa & van der Schaar, 2017; 2018). However, these methods for the static setting cannot be extended directly to time-varying treatments (Hernán et al., 2000; Schisterman et al., 2009).
Learning optimal policies: A related problem to ours involves learning the optimal treatment policies from logged data (Swaminathan & Joachims, 2015a;b; Atan et al., 2018). That is, learning the treatment option that would give the best reward. Note the difference to the causal inference setting considered in this paper, where the aim is to learn the counterfactual patient outcomes under all possible treatment options. Learning all of the counterfactual outcomes is a harder problem and can also be used for finding the optimal treatment.
A method for learning optimal policies, proposed by Atan et al. (2018) uses domain adversarial training to build a representation that is invariant to the following two domains: observational data and simulated randomized clinical trial data, where the treatments have equal probabilities. Atan et al. (2018) only considers the static setting and aims to choose the optimal treatment instead of estimating all of the counterfactual outcomes. In our paper the aim is to eliminate the bias from the time-dependent confounders and reliably estimate all of the potential outcomes; thus, at each timestep t we build a representation that is invariant to the treatment.
Off-policy evaluation in reinforcement learning: In reinforcement learning, a similar problem to ours is off-policy evaluation, which uses retrospective observational data, also known as logged bandit feedback (Hoiles & Van Der Schaar, 2016; Păduraru et al., 2013; Doroudi et al., 2017). In this case, the retrospective observational data consists of sequences of states, actions and rewards which were generated by an agent operating under an unknown policy. The off-policy evaluation methods aim to use this data to estimate the expected reward of a target policy. These methods use algorithms based on importance sampling (Precup, 2000; Thomas et al., 2015; Guo et al., 2017), action-value function approximation (model based) (Hallak et al., 2015) or doubly robust combination of both approaches (Jiang & Li, 2015). Nevertheless, these methods focus on obtaining average rewards of policies, while in our case the aim is to estimate individualized patient outcomes for future treatments.

heading: B ASSUMPTIONS
text: The standard assumptions needed for identifying the treatment effects are (Robins & Hernán, 2008; Lim et al., 2018; Schulam & Saria, 2017):
Assumption 1: Consistency. If At = at for a given patient, then the potential outcome for treatment at is the same as the observed (factual) outcome: Yt+1[at] = Yt+1.
Assumption 2: Positivity (Overlap) (Imai & Van Dyk, 2004): If P (Āt−1 = āt−1, X̄t = x̄t) 6= 0 then P (At = at | Āt−1 = āt−1, X̄t = x̄t) > 0 for all āt. Assumption 3: Sequential strong ignorability. Yt+1[at] ⊥⊥ At | Āt−1, X̄t,∀at ∈ A,∀t. Assumption 2 means that, for each timestep, each treatment has non-zero probability of being assigned. Assumption 3 means that there are no hidden confounders, that is, all of covariates affecting both the treatment assignment and the outcomes are present in the the observational dataset. Note that while assumption 3 is standard across all methods for estimating treatment effects, it is not testable in practice (Robins et al., 2000; Pearl et al., 2009).

heading: C TIME-DEPENDENT CONFOUNDING
text: Figure 6 illustrates the causal graphs for a time-varying exposures with 2-steps (Robins et al., 2000). In Figure 6 (a), the covariate X is a time-dependent confounder because it affects the treatment assignments and at the same time, its value is changed by past treatments (Mansournia et al., 2017), as illustrated by the red arrows. Thus, the treatment probabilities at each time t depend on the history of covariate X and past treatments. Note that U0 and U1 are hidden variables which only affect the covariates, i.e. they do not have arrows into the treatments. Thus, the no hidden confounders assumption (Assumption 3) is satisfied.
Figure 6 (a) and (b) illustrate the two cases when there is no bias from time-dependent confounding. In Figure 6 (a) the treatment probabilities are independent, while in Figure 6 (b) they depend on past treatments.
Marginal Structural Models Robins et al. (2000). To remove the association between timedependent confounders and time-varying treatments, Marginal Structural Models propose using inverse probability of treatment weighting (IPTW). Without loss of generality, consider the use of MSMs with univariate treatments, baseline variables and outcomes. The outcome after t timesteps is parametrized as follows: E[Yt+1 | a1, . . .at, V ] = g(a1, . . .an, V ; θ), where g(·) is usually a linear function with parameters θ. To remove the bias from the time-dependent confounders present in the observational dataset, in the regression model g(·) MSMs weights each patients using either stabilized weights:
SW (t) = t∏ l=1 f(Al | Āl−1) f(Al | X̄l, Āl−1,V)
(8)
or unstabilized weights:
W (t) = t∏ l=1
1
f(Al | X̄l, Āl−1,V) , (9)
where f(·) represents the conditional probability mass function for discrete treatments.
Inverse probability of treatment weighting (IPTW) creates a pseudo-population where each member consists of themselves and W − 1 (or SW − 1) copies added though weighting. In this pseudopopulation, Robins Robins (1999) shows that X̄t does not predict treatment At, thus removing the bias from time-dependent confounders.
When using unstabilized weights W , the causal graph in the pseudo-population is the one in Figure 6 (a) where P (At | X̄t, Āt−1, V ) = P (At). On the other hand, when using stabilized weights SW , causal graph in the pseudo-population is the one in Figure 6 (b) where P (At | X̄t, Āt−1, V ) = P (At | Āt−1). Counterfactual Recurrent Networks. Instead of using IPTW, we proposed building a representation of X̄t, Āt−1, V that is not predictive of treatment At. At timestep t, we have k different possible treatments At ∈ {A1, . . . AK}. We build a representation of the history and covariates and treatments that has the same distribution across the different possible treatments: P (Φ(X̄t, Āt−1,V) | At = A1) = · · · = P (Φ(X̄t, Āt−1,V) | At = AK). By breaking the association between past exposure and current treatments At, we satisfy the causal graph in Figure 6 (a) and thus we remove the bias from time-dependent confounders.

heading: D PROOF OF THEOREM 1
text: We first prove the following proposition. Proposition 1. For fixed Φ, let x′ = Φ(h̄t). Then the optimal prediction probabilities of Ga are given by
Gja ∗ (x′) = PΦj (x ′)∑K
i=1 P Φ i (x
′) . (10)
Proof. For fixed Φ, the optimal prediction probabilities are given by
G∗a = arg max Ga K∑ j=1 ∫ x′ log(Gja(x ′))PΦj (x ′)dx′ subject to K∑ j=1 Gja(x ′) = 1 . (11)
Maximising the value function pointwise and applying Lagrange multiplies, we get
G∗a = arg max Ga K∑ j=1 log(Gja(x ′))PΦj (x ′) + λ ( K∑ j=1 Gja(x ′)− 1 ) . (12)
Setting the derivative (w.r.t. Gja ∗ (x′)) to 0 and solving for Gja ∗ (x′) we get
Gja ∗ (x′) = −
PΦj (x ′)
λ (13)
where λ can now be solved for using the constraint to be λ = −∑Ki=1 PΦi (x′). This gives the result.
Proof. (of Theorem 1) By substituting the expression from Proposition 1 into the minimax game defined in Eq. 6, the objective for Φ becomes
min Φ K∑ j=1 Ex′∼PΦj [ log ( PΦj (x ′)∑K i=1 P Φ i (x ′) )] . (14)
We then note that K∑ j=1 Ex′∼PΦj [ log ( PΦj (x ′)∑K i=1 P Φ i (x ′) )] +K logK = K∑ j=1 ( Ex′∼PΦj [ log ( PΦj (x ′)∑K i=1 P Φ i (x ′) )] + logK ) (15)
= K∑ j=1 Ex′∼PΦj [ log ( PΦj (x ′) 1 K ∑K i=1 P Φ i (x ′) )] (16)
= K∑ j=1 KL ( PΦj (x ′) ∣∣∣∣∣∣∣∣ 1K K∑ i=1 PΦi (x ′) ) (17)
= K · JSD(PΦ1 , ..., PΦK) (18) where KL(·||·) is the Kullback-Leibler divergence and JSD(·, ..., ·) is the multi-distribution JensenShannon Divergence (Li et al., 2018). Since K logK is a constant and the multi-distribution JSD is non-negative and 0 if and only if all distributions are equal, we have that PΦ1 = ... = P Φ K .

heading: E TRAINING PROCEDURE FOR CRN
text: Let D = { {x(i)t ,a(i)t ,y(i)t+1}T (i) t=1 ∪ {v(i)} }N i=1
be an observational dataset consisting of information about N independent patients that we use to train CRN. The encoder and decoder networks part of CRN are trained into two separate steps.
To begin with, the encoder is trained to built treatment invariant representations of the patient history and to perform one-step ahead prediction. After the encoder is optimized, we use it to compute the balancing representation br(i)t for each timestep in the trajectory of patient (i). To train the decoder, we modify the training dataset as follows. For each patient (i), we split their trajectory into shorter sequences of the τmax timesteps of the form:{
br (i) l ∪ {y (i) l+t,a (i) l+t,y (i) l+t+1}τmaxt=1 ∪ v(i)
} , (19)
for l = 1, . . . T (i) − τmax. Thus, each patients contributes with T (i) − τmax examples in the dataset for training the decoder. The different sequences obtained for all patents are randomly grouped into minibatches and used for training.
The pseudocode in Algorithm 1 shows the training procedure used for the encoder and decoder networks part of CRN. The model was implemented in TensorFlow and trained on an NVIDIA Tesla K80 GPU. The Adam optimizer (Kingma & Ba, 2014) was used for training and both the encoder and the decoder are trained for 100 epochs.
Algorithm 1 Pseudo-code for training CRN Input: Training data: D = { {x(i)t ,a(i)t ,y(i)t+1}T (i) t=1 ∪ v(i) }N i=1
(1) Encoder optimization: parameters θE,r, θE,a, θE,y . Learning rate: µ for p = 1, . . . ,max epochs do
λp = 2
1 + exp(−10 · p) − 1 for Batch B = { {x(i)t ,a(i)t ,y(i)t+1}T (i) t=0 ∪ v(i) }|B| i=1 in epoch do
Compute LBE,a(θE,r, θE,a) = 1|B| ∑ i∈B ∑T (i) t=1 L (i) t,a(θE,r, θE,a)
Compute LBE,y(θE,r, θE,y) = 1|B| ∑ i∈B ∑T (i) t=1 L (i) t,y(θE,r, θE,y)
θE,r ← θE,r − µ ( ∂LBE,y(θE,r,θE,y) ∂θE,r − λp ∂L B E,a(θE,r,θE,a) ∂θE,r ) θE,y ← θE,y − µ∂L B E,y(θE,r,θE,y)
∂θE,y
θE,a ← θE,a − µ∂L B E,a(θE,r,θE,a)
∂θE,a
end for end for
(2) Compute the encoder balanced representation and use it to initialize the decoder hidden state. for i = 1, ..., N do
for t = 1, . . . , T (i) do br
(i) t = encoder(x̄ (i) t , ā (i) t−1,v (i); θE,r) end for
end for
(3) Split dataset in sequences of τmax timesteps:{{ br
(i) l ∪ {y (i) l+t,a (i) l+t,y (i) l+t+1}τmaxt=1 ∪ v(i) }T (i)−τmax l=1 }N i=1
(4) Optimize decoder: parameters θD,r, θD,a, θD,y Learning rate: µ for p = 1, . . . , max epochs do
λp = 2
1 + exp(−10 · p) − 1 for Batch B = { br
(i) l ∪ {y (i) l+t,a (i) l+t,y (i) l+t+1}τmaxt=0 ∪ {v(i)} }|B| i=1 in epoch do
Compute LBD,a(θD,r, θD,a) = 1|B| ∑ i∈B ∑τmax t=1 L (i) t,a(θD,r, θD,a)
Compute LBD,y(θD,r, θD,y) = 1|B| ∑ i∈B ∑τmax t=1 L (i) t,y(θD,r, θD,y)
θD,r ← θD,r − µ ( ∂LBD,y(θD,r,θD,y) ∂θD,r − λp ∂L B D,a(θD,r,θD,a) ∂θD,r ) θD,y ← θD,y − µ∂L B D,y(θD,r,θD,y)
∂θD,y
θD,a ← θD,a − µ∂L B D,a(θD,r,θD,a)
∂θD,a
end for end for
Output: Trained CRN encoder (parameters θE,r, θE,a, θE,y) and trained CRN decoder (parameters θD,r, θD,a, θD,y. )

heading: F PHARMACOKINETIC-PHARMACODYNAMIC MODEL OF TUMOUR GROWTH
text: To evaluate the CRN on counterfactual estimation, we need access to the data generation mechanism to build a test set that consists of patient outcomes under all possible treatment options. For this purpose, we use the state-of-the-art pharmacokinetic-pharmacodynamic (PK-PD) model of tumour growth proposed by Geng et al. (2017) and also used by Lim et al. (2018) for evaluating RMSMs. The PK-PD model characterizes patients suffering from non-small cell lung cancer and models the evolution of their tumour under the combined effects of chemotherapy and radiotherapy. In addition, the model includes different distributions of tumour sizes based on the cancer stage at diagnosis.
Model of tumour growth The volume of tumour t days after diagnosis is modelled as follows: V (t+ 1) = ( 1 + ρlog( K
V (t) )︸ ︷︷ ︸
Tumor growth
− βcC(t)︸ ︷︷ ︸ Chemotherapy
− ( αrd(t) + βrd(t) 2 )︸ ︷︷ ︸
Radiotherapy
+ et︸︷︷︸ Noise
) V (t)
(20)
where the parameters K, ρ, βc, αr, βr are sampled from the prior distributions described in (Geng et al., 2017) and et ∼ N (0, 0.012) is a noise term that accounts for randomness in the tumour growth. To incorporate heterogeneity among patient responses, due to, for instance, gender or genetic factors Bartsch et al. (2007), the prior means for βc and αr are adjusted to create three patient subgroups S(i) ∈ {1, 2, 3} as described in Lim et al. (2018). This way, we incorporate in the model of tumour growth specific characteristics that affect the patient’s individualized response to treatments. Thus, the prior mean µβc of βc and the prior mean µαr of αr are augmented as follows.
µ′βc(i) =
{ 1.1µβc , if S (i) = 3
µβc , otherwise µ′αr (i) =
{ 1.1µαr , ifS (i) = 1
µαr , otherwise (21)
where µβc and µαr are the mean parameters from Geng et al. (2017) and µ ′ βc (i) and µ′αr (i) are the parameters used in the data simulation. The patient subgroup S(i) ∈ {1, 2, 3} is used as baseline features.
The chemotherapy drug concentration follows an exponential decay with half life of 1 day:
C(t) = C̃(t) + C(t− 1)/2, (22)
where C̃(t) = 5.0mg/m3 of Vinblastine if chemotherapy is given at time t. d(t) = 2.0Gy fractions of radiotherapy if the radiotherapy treatment is applied at timestep t.
Time-varying confounding is introduced by modelling chemotherapy and radiotherapy assignment as Bernoulli random variables, with probabilities pc and pr depending on the tumour diameter:
pc(t) = σ
( γc
Dmax (D̄(t)− δc)
) pr(t) = σ ( γr
Dmax (D̄(t)− δr)
) , (23)
where D̄(t) is the average tumour diameter over the last 15 days, Dmax = 13cm is the maximum tumour diameter and σ(·) is the sigmoid activation function. The parameters δc and δr are set to δc = δr = Dmax/2 such that there is 0.5 probability of receiving treatment when tumour is half of its maximum size. γc, γr control the amount of time-dependent confounding; the higher γ? is, the more important the history of tumour diameter is in assigning treatments. Thus, at each timestep, there are four treatment options options: no treatment (A1), chemotherpy (A2), radiotherapy (A3), combined chemotherapy and radiotherapy (A4).
Since the work most relevant to ours is the one of Lim et al. (2018) we used the same data simulation and same settings for γ = γc = γr as in their case. When γ = 0, there is no time-dependent confounding and the treatments are randomly assigned. By increasing γ we increase the influence of the volume size history (encoded in D̄(t)) on the treatment probability. For example, assume D̄(t) = 3Dmax
4 . From equation (7), the probability of chemotherapy in this case is pc(t) = σ( γc Dmax (D̄(t)− Dmax 2 )) = σ(0.25γc), where σ(·) is the sigmoid function. When γ = 1, pc(t) = 0.56, when γ = 5, pc(t) = 0.77 and when γ = 10, pc(t) = 0.92 in this example. γ can be increased further to increase the bias. However, the values used in the experiments evaluate the model on a wide range of settings for the time-dependent confounding bias.

heading: G MARGINAL STRUCTURAL MODELS
text: Marginal Structural Models (Robins et al., 2000; Hernán et al., 2001) have been widely used in epidemiology and as part of follow up studies. In our case, we would like to estimate the effects of a sequence of treatments in the future given the current patient history:
E(Yt+τ | Ā(t, t+ τ − 1) = ā(t, t+ τ − 1), H̄t) = g(τ, a(t, t+ τ − 1), H̄t), (24) where g is a generic function and ā(t, t+ τ − 1) = [at, . . .at+τ−1] represents a possible sequence of treatments from timestep t just until before the potential outcome Yt+τ is observed. After removing the bias form time-dependent confounders, E(Yt+τ | Ā(t, t + τ − 1) = ā(t, t + τ − 1), H̄t) = E(Yt+τ [ā(t, t+ τ − 1)]. Note that for implementing MSMs, we encode the treatments at timestep t in the model of tumour growth as At = [At,c, At,d] to indicate the binary application of chemotherapy and radiotherapy. In order to remove the time-dependent confounding bias and estimate future outcomes, we use the stabilized weights of MSMs to weight each patient in the dataset:
SW (t, τ) = t+τ∏ n=t f(An | Ān−1) f(An | Ān−1, X̄n,V) = t+τ∏ n=t ∏ k∈{c,d} f(An,k | Ān−1)∏ k∈{c,d} f(An,k | Ān−1, X̄n,V) , (25)
where f(·) represents the conditional probability mass function for discrete treatments. We adopt the implementation in (Hernán et al., 2001; Howe et al., 2012; Lim et al., 2018) for MSMs and use logistic regression for estimating the propensity weights as follows:
f(At,k | Āt−1) = σ ( k∑ j=1 ωk( t−1∑ i=1 At,j) )
(26)
f(At,k | H̄t) = σ ( ∑ k∈{c,d} φk( t−1∑ i=1 At,k) + w1Xt + w2Xt−1 + w3V )
(27)
where ω?, φ? and w? are regression coefficients, k ∈ {c, d} indicates the chemotherapy or radiotherapy treatments and σ(·) is the sigmoid function. For predicting the outcome, the following regression model is used, where each individual patient is weighted by its propensity score:
g(τ, a(t, t+ τ − 1), H̄t) = ∑
k∈{c,d} βk( t+τ−1∑ n=t An,k) + l1Xt + l2Xt−1 + l3V (28)
where β? and l? are regression coefficients.
MSMs do not require hyperparameter tuning so we use the patients from both the train and validation sets for training.

heading: H RECURRENT MARGINAL STRUCTURAL NETWORKS
text: MSMs are very sensitive to model mis-specification in computing the propensity weights and estimating the outcomes. Recurrent Marginal Structural Models (RMSNs) (Lim et al., 2018) overcome this problem by using recurrent neural networks to estimate the propensity scores and to build the outcome model. RNNs are more robust to changes in the treatment assignment policy. RMSNs were implemented as descried in Lim et al. (2018)2.
For implementing RMSNs, we also encode the treatments at timestep t in the model of tumour growth as At = [At,c, At,d] to indicate the binary application of chemotherapy and radiotherapy. The propensity weights are estimated using recurrent neural networks as follows:
f(At,k | Āt−1) = RNNSWn(Āt−1) f(At,k | X̄t, Āt−1) = RNNSWd(Āt−1, X̄t,V) (29) 2We used the publicly available implementation from https://github.com/sjblim/rmsn_nips_
2018.
For predicting one-step-ahed outcome, R-MSNs use an encoder network:
g(1, a(t, t), H̄t) = RNNE(at, Āt−1, X̄t,V), (30)
where in the loss function, each patient is weighted by their stabilized IPTW.
For estimating the treatment responses for a sequence of treatments in the future, RMSNs use a decoder network:
g(τ, a(t, t+ τ − 1), H̄t) = RNND(at, . . . ,at+τ−1, Āt−1, X̄t,V). (31) See Lim et al. (2018) for more details about the R-MSNs model architecture and training procedure of the propensity weights, encoder and decoder networks. Tables 2 and 3 show the hyperparameter search ranges used to optimize this model for evaluation in our paper. The hyperparameters were selected in the same way as proposed by Lim et al. (2018), based on the error on the factual outcomes in the validation dataset. All of the models are trained using Adam optimizer for 100 epochs.

heading: I BASELINE RNN AND LINEAR MODEL
text: For the baseline linear model, we fit the same regression model used for Marginal Structural Networks, but without using the IPTW. The baseline RNN uses an LSTM unit and, at each timestep, receives as input the current treatment, the patient covariates and the patient static features to perform one-stepahead prediction. To have a model of similar capacity to the CRN (similar number of parameters), we add a fully connected layer on top of the output of the LSTM unit in order to obtain the outcomes. Table 4 shows the hyperparameter search range used to optimize this model. The hyperparameters were selecting according to the error on the factual outcomes in the validation set. We train the baseline RNN using the Adam optimizer for 100 epochs.

heading: J HYPERPARAMETER OPTIMIZATION FOR CRN
text: As described in Appendix C, the dataset for training the decoder are used by splitting the sequences of the patients in the training set. This creates a larger dataset for training (where each patient (i) contributes T (i) − τmax times to the dataset) which requires a different hyperparameter search range. Moreover, the balancing representations computed by the encoder are used to initialize the state of the RNN for the decoder. Thus, the decoder RNN size is equal to the size of the balancing representation size of the encoder. Table 5 shows the hyperparameter search ranges for the encoder and decoder networks in CRN. We selected hyperparameters based on the error of the model on the factual outcomes in the validation dataset. All models are trained for 100 epochs.
In addition, Tables 6 and 7 illustrate the optimal hyperparameters chosen.

heading: K FULL RESULTS FOR COUNTERFACTUAL PREDICTION
text: K.1 MULTI-STEP AHEAD PREDICTION OF COUNTERFACTUALS
Figure 7 shows the normalized RMSE for multiple step-ahead prediction of counterfactuals. The RMSE is normalized by the maximum tumour volume: Vmax = 1150cm3. The counterfactuals in this case are generated as described in Section 6.3 and Appendix I. We notice that performance gains of CRN compared to RMSN increase with the number of future timesteps for which the counterfactuals are estimated.
K.2 DETAILED RESULTS FOR THE COUNTERFACTUAL PREDICTIONS
Tables 8 and 9 show detailed results for the counterfactual predictions.

heading: L TEST SET GENERATION FOR EVALUATING TIMING OF TREATMENT
text: In order to evaluate how well the models select the correct treatment and timing of treatment we simulate counterfactual outcomes as follows. We generate 1000 test samples using the model of tumour growth described in Section 6. Let H̄t be the current history of the patient and let τ be a future time horizon. For each timestep in the future, we have 4 treatment options at: no treatment (A0), chemotherapy (A1), radiotherapy (A2), chemotherapy and radiotherapy. (A3).
Using the model of tumour growth where the outcome Yt+τ is given by the volume of the tumour, we generate the following 2τ counterfactuals:
Chemotherapy application Yt+τ | at = A1,at+1 = A0, . . .at+τ−1 = A0, H̄t (32) Yt+τ | at = A0,at+1 = A1, . . .at+τ−1 = A0, H̄t (33) . . .
Yt+τ | at = A0,at+1 = A0, . . .at+τ−1 = A1, H̄t (34) Radiotherapy application
Yt+τ | at = A2,at+1 = A0, . . .at+τ−1 = A0, H̄t (35) Yt+τ | at = A0,at+1 = A2, . . .at+τ−1 = A0, H̄t (36) . . .
Yt+τ | at = A0,at+1 = A0, . . .at+τ−1 = A2, H̄t (37) We perform this for each patient in the test set and at each time t in the history. For instance, for a patient with 50 timesteps in the model of tumour growth and for time horizon τ = 3, we generate 2 · 3 · 50 = 300 counterfactuals. Using the true generated couterfactual data, we select the treatment that has the lowest Yt+τ among the τ options generated for each treatment. Then, we select the time of applying treatment (among t, t+1, . . . t+τ−1) that resulted in the lowest Yt+τ . For each model, we generate the counterfactuals under the same treatment plans and patient histories. Then, we perform the selection of treatment and timing of treatment in the same way and we compare these with the true ones. Note that in order to account for numerical instability (two outcomes Yt+τ having very similar values), we consider two outcomes the same if they are within = 0.001 of each other.

heading: M RESULTS ON FACTUAL PREDICTION ON MIMIC III
text: Using the Medical Information Mart for Intensive Care (MIMIC III) (Johnson et al., 2016) database consisting of electronic health records from patients in the ICU, we also show how the CRN can be used on a real medical dataset. From MIMIC III we extracted the patients on antibiotics, with trajectories up to 30 timesteps, thus obtaining a dataset with 3487 patients. For each patient, we extracted 25 patient covariates including lab tests and vital signs measured over time, as well as static patient features such as age and gender.
We used a binary treatment at each timestep indicating whether the patient was administered antibiotics or not. Note that for the longitudinal covariates we used aggregate value for each day since the ICU admission. The reason for this is because antibiotic treatment is decided daily for the patient. We split the dataset into 2826/313/348 patients for training, validation and testing respectively. We performed hyperparameter optimization on the validation patient set, using the search ranges in Table 5 and we again selected hyperparameters based on the error on the factual outcomes.
We estimate the individualized effect of antibiotics assigned over time on the patient’s white blood cell count. A high white blood cell count is associated with severe illness and poor outcome for ICU patients (Waheed et al., 2003). Antibiotic administration in the ICU aims to reduce the white blood cell count. However, the effectiveness of the antibiotics treatment in reducing the white blood cell count is highly dependent on the time they are administered with respect to the history of the patient covariates. In this context we again have time-dependent confounders: the patient features change over time and are affected by the previous administration of antibiotics. Moreover, the history of the patient features also determines antibiotics administration and affects future patient outcomes (De Bus et al., 2018; Ali et al., 2019).
In Table 10 we report the root mean squared error for factual prediction of the patients’ white blood cell count for multiple prediction horizons τ . Note that for this dataset we do not have access to counterfactual data, which is why we report error on factual predictions.
We notice that CRN also achieves better performance than RMSN in estimating factual outcomes in a real-world dataset containing electronic health records. In this context, where couterfactual data is not available, domain expert knowledge is required to validate the model’s counterfactual predictions under other antibiotic treatment alternatives. This further medical validation is outside the scope of this paper.

Review summaries:
The paper introduces Counterfactual Recurrent Network (CRN) that is able to estimate the effects of various treatments from longitudinal data. The claim is that the model can decide (i) treatment plan; (ii) optimal time of treatment; and (iii) when to stop treatment. The proposed method attempts to learn time-invariant representations that are not predictive of the next treatment by borrowing ideas from Ganin, et al. (2016)’s work on for domain adversarial training. In fact, this paper is an extension of (Atan et al., 2018) to be applicable for longitudinal data. 

This work addresses the problem of causal inference in time-dependent treatment regimes. To address the problem, the authors propose an extension of the balancing representation for causal inference framework that seeks render the current treatment independent from a representation of the history of treatment and confounders. This is sensibly actualized within an RNN. The authors provide empirical results that demonstrate the proposed method performing very well in comparison to prior art.