Simulating Data From Marginal Structural Models for a Survival Time Outcome Authors: Shaun R Seaman, Ruth H Keogh Published: 2024 ABSTRACT ABSTRACTMarginal structural models (MSMs) are often used to estimate causal effects of treatments on survival time outcomes from observational data when time‐dependent confounding may be present. They can be fitted using, for example, inverse probability of treatment weighting (IPTW). It is important to evaluate the performance of statistical methods in different scenarios, and simulation studies are a key tool for such evaluations. In such simulation studies, it is common to generate data in such a way that the model of interest is correctly specified, but this is not always straightforward when the model of interest is for potential outcomes, as is an MSM. Methods have been proposed for simulating from MSMs for a survival outcome, but these methods impose restrictions on the data‐generating mechanism. Here, we propose a method that overcomes these restrictions. The MSM can be, for example, a marginal structural logistic model for a discrete survival time or a Cox or additive hazards MSM for a continuous survival time. The hazard of the potential survival time can be conditional on baseline covariates, and the treatment variable can be discrete or continuous. We illustrate the use of the proposed simulation algorithm by carrying out a brief simulation study. This study compares the coverage of confidence intervals calculated in two different ways for causal effect estimates obtained by fitting an MSM via IPTW.Keywords: bootstrap, causal inference, compatible models, congenial models, continuous‐time marginal structural model, sandwich estimator, simulation studies, survival analysis, time‐dependent confounding Introduction In many longitudinal observational studies, a time‐varying treatment and time‐varying covariates are observed for each individual at a number of time points (“visits”) and the aim is to estimate the causal effect of treatment on survival time. Such estimation is often complicated by time‐dependent confounding (Daniel et al. 2013). Marginal structural models (MSMs) are commonly used in this setting (Clare, Dobbins, and Mattick 2019) to estimate causal effects in a way that accounts for time‐dependent confounding. An MSM is a model for the potential outcome that would arise if treatment were assigned according to a particular rule. Here, we focus on MSMs for a survival outcome, which includes Cox MSMs and their discrete‐time analogues (Hernan, Brumback, and Robins 2000; Sterne et al. 2005; Clare, Dobbins, and Mattick 2019). Simulation studies are often used to evaluate the performance of new (and existing) statistical methods in different scenarios (Morris, White, and Crowther 2019; Friedrich and Friede 2024). It is common in such studies to generate data in such a way that the model of interest is correctly specified. It transpires this is not always simple when the model of interest is a model for potential outcomes, as is an MSM (Evans and Didelez 2024). Methods for simulating from Cox MSMs have been proposed by Xiao, Abrahamowicz, and Moodie (2010) and Young et al. (2010). Havercroft and Didelez (2012) and Young and Tchetgen (2014) propose algorithms for simulating from, respectively, logistic MSMs and discrete‐time Cox MSMs. By finely discretizing time, these two algorithms can be used to simulate a continuous failure time from a Cox MSM. Keogh et al. (2021) describe how to simulate from an additive‐hazards MSM. These existing methods impose restrictions on the data‐generating mechanism. Xiao et al. (2010) rely on the failure rate being very low and do not allow for (possibly unobserved) common causes of the time‐dependent confounders and survival process, and (as noted by Young and Tchetgen 2014) the hazard in the implied MSM depends on all past treatments. Havercroft and Didelez (2012) assume the dependence of the survival process on the time‐dependent confounder process arises entirely through the effect of the latter on the treatment process and through a single shared latent variable. This means, for example, that the effect of confounders measured at time 1 on the hazard of failure at time 5, say, is as strong as their effect on the hazard at time 2, rather than being able to diminish over time. Young et al. (2010) seek to generate data in such a way that a Cox MSM, a structural nested accelerated failure time model, and a structural nested failure time model are all correctly specified, so that performance of these three modeling approaches can be compared. Their method is closely related to that of Havercroft and Didelez (2012) but requires that the potential treatment‐free survival time be exponentially distributed and the hazard in the Cox MSM depend only on the most recent treatment; also treatment must be binary. Young and Tchetgen Tchetgen (2014) aim to simulate data in such a way that three other models are correctly specified: a Cox MSM, a parametric model for the treatment given the past, and a parametric model for the hazard given the past. This allows the comparison of two methods for fitting Cox MSMs: inverse probability of treatment weighting (IPTW) and g‐computation. Their data‐generating mechanism assumes there are no baseline confounders and only one time‐dependent confounder, that the hazard at time t depends only on the treatment at the two most recent times and the time‐dependent confounder at the most recent time, and that the time‐dependent confounder at time t depends on the history of treatment and confounder only through treatment at the most recent time. In addition, none of these four data‐simulation methods explicitly allows for an MSM that conditions the hazard on baseline covariates. Keogh et al.'s (2021) proposal for simulating from an additive‐hazards MSM does not impose such restrictions but also does not enable the user easily to specify the values of the parameters of the MSM directly. In this article, we propose an algorithm for simulating from an MSM for a survival time outcome that overcomes these restrictions. This MSM can be, for example, a logistic MSM for a discrete survival time, or a Cox or additive hazards MSM for a continuous survival time. The hazard in the MSM can be conditional on baseline covariates, and the treatment variable can be discrete or continuous. In developing our algorithm, we have broadly followed the general approach proposed by Evans and Didelez (2024) for simulating from causal models. They sketched how this approach might be used to generate from an MSM for survival data but provided few details and then only for the case of one binary confounder with a strong Markov property (see our Supporting Information Section A for details). In Section 2, we introduce notation, define the MSM of interest, and present the causal directed acyclic graph (DAG) assumed to apply. Section 3 describes our proposed algorithm when the survival time is discrete. It requires the specification of a “risk score” function and the correlation parameter of a Gaussian copula. The risk score is a function of the history of the confounders, and the copula expresses the association between this risk score and the potential survival outcome. Application of the algorithm requires the cumulative distribution function (CDF) of the risk score to be known, which it will not be in general. So, in Section 4, we extend our algorithm to estimate this CDF at the same time as simulating the data. Section 5 describes how the algorithm can be adapted for a continuous failure time; this enables simulation from a Cox or additive hazards MSM. A brief simulation study is presented in Section 6, to illustrate the methods described in this article. R code for implementing this study is provided in the Supporting Information (or at https://github.com/shaun2022/simulatingMSM), along with Supporting Information Sections A–M. Section 7 contains a discussion. Setup and Notation Consider a study in which n individuals are observed at regular visits up to the earlier of their failure time and censoring time. Visit times, assumed to be the same for all individuals, are 0,1,…K, and the administrative censoring time is K+1 (which we shall sometimes call “visit K+1”). We denote random variables with capital letters and their values with lower‐case letters. Let Ak denote the treatment received by an individual at visit k (k=0,…,K). This could be discrete or continuous. Let T denote the individual's failure time and Yk=I(T≥k) be an indicator of survival to visit k (k=1,…,K+1), with Y0=1. Let X and B denote two distinct vectors of baseline covariates for an individual. Variables X are baseline confounders and/or treatment effect modifiers that will be conditioned on in the MSM presented below (Equation 1). Variables B are not conditioned on in the MSM and can include any or all of baseline confounders, common causes of the Lk and Yk variables that are not confounders, and instrumental variables. Either of X and B could be empty. Let Lk denote time‐varying confounders for an individual at visit k (k=0,…,K). Let A¯k=(A0,…,Ak) and L¯k=(L0,…,Lk) denote the histories of treatment and time‐dependent confounders up to visit k; and A¯−1=L¯−1=∅. We assume the causal DAG shown in Figure 1. Assumed causal directed acyclic graph (DAG). For simplicity, this is shown for K=1. Variables with a superscript a¯k are potential variables under an intervention that sets treatments A¯k at the first k+1 visits equal to a¯k. For example, Yk+1a¯k=1 if the individual would survive to visit k+1 if their treatments at visits 0,…,k were set to a¯k, and Yk+1a¯k=0 if the individual would fail. We make the usual consistency assumption that Yk=YkA¯k−1 and Lk=LkA¯k−1. Note that this together with the causal DAG implies sequential exchangeability, that is, (Yk+1A¯k−1a_k,…,YK+1A¯k−1a_k)⊥⊥Ak∣X,B,L¯k,A¯k−1,Yk=1 for all a_k=(ak,…,aK). We begin with MSMs for discrete‐time hazard of failure, postponing consideration of MSMs for continuous‐time hazard, for example, Cox MSMs, until Section 5. Consider the following MSM for the hazard at visit k (k=1,…,K+1). where gk(.) is a known function with parameters β. Parameters β can be specific to visit k, common to all k, or a mixture of both. For example, in a logistic MSM (Robins, Hernan, and Brumback 2000), gk(a¯k−1,X;β) could be chosen to be, for example, expit(βk0+β1⊤X+β2ak−1) or expit(βk0+βk1⊤X+βk2ak−2+βk3ak−1+βk4Xak−1). We shall describe a method for simulating data on (X,B,L0,A0,Y1,…,LK,AK,YK+1) for a single individual such that Equation (1) is satisfied for a prespecified choice of functions gk(a¯k−1,X;β) (k=1,…,K+1) and value of β. Algorithm for Simulating Data For simplicity, suppose K=1; we shall consider K≥1 in Section 3.3. The joint distribution of (X,B,L0,A0,Y1,L1,A1,Y2) can be factorized as If we specify the distributions on the right‐hand side of Equation (2), we can sample (X,B,L0,A0,Y1,L1,A1,Y2). A complication is that, by the consistency assumption, Y1=Y1A0 and Y2=Y2A¯1. This means that, for the MSM of Equation (1) to be correctly specified for the chosen functions gk(a¯k−1,X;β) (k=1,2) and value of β, we must choose p(Y1∣X,B,L0,A0) and p(Y2∣X,B,L0,A0,Y1,L1,A1)—or equivalently, p(Y1A0∣X,B,L0,A0) and p(Y2A¯1∣X,B,L0,A0,Y1,L1,A1)—carefully. For example, sampling Y1 from a logistic regression model with covariates X, B, L0, and A0 will typically not satisfy Equation (1). We now describe a suitable method for sampling Y1 and Y2. Sampling Y1 Given (X,B,L0,A0) Consider the task of sampling Y1a0 given (X,B,L0,A0) for any value of a0. If we can do this, then we can sample Y1A0 specifically and set Y equal to it. Let p(Y1a0∣X,B,L0,A0) denote a conditional distribution that satisfies the sequential exchangeability assumption, that is p(Y1a0∣X,B,L0,A0)=p(Y1a0∣X,B,L0). If it also satisfies then Equation (1) will hold for k=1. Our way of choosing a P(Y1a0=0∣X,B,L0) that satisfies Equation (3) involves two components. The first will allow us to reduce the dependence of Y1a0 on B and L0 to dependence on a scalar function of those variables, which we call a “risk score.” The second is a bivariate Gaussian copula (Schepsmeier and Stober 2014) that will describe the association between this risk score and a latent continuous variable (denoted UY1a0 below) that determines Y1a0. Readers unfamiliar with Gaussian copulas can see Supporting Information Section B for an introduction. Let h0a0(x,b,l0) be a scalar continuous function of (x,b,l0) that the user of our algorithm should specify. We call this the “risk score” function for visit 0 because it will rank individuals with the same value of X but different values of (B,L0) according to their potential hazards P(Y1a0=0∣X,B,L0), and we call H0a0=h0a0(X,B,L0) the “risk score” (for visit 0) for an individual (under the intervention that sets A0=a0). Let FH0a0(h∣x) denote the conditional CDF of H0a0 given X=x, and let UH0a0=FH0a0(H0a0∣X) be the random variable obtained by plugging H0a0 and X into this CDF. We call UH0a0 the individual's “risk quantile.” Notice that by a general property of CDFs, UH0a0∣X∼Uniform(0,1). Let Φ(.) denote the CDF of the standard normal distribution and ρ0 (−1<ρ0≤0) be some constant that the user of our algorithm will choose (in principle, ρ0 could be a function of a0, but, for simplicity, we assume it is not). We shall show that satisfies Equation (3) and that the algorithm presented below samples Y1a0 from this distribution. Note that UH0a0, and hence P(Y1a0=0∣X,B,L0), does not change if the risk score function h0a0(x,b,l0) is replaced by ν{h0a0(x,b,l0)}, where ν(.) is any monotonically increasing function. What matters therefore is only the ranking of individuals that h0a0(x,b,l0) provides. This and the fact that the right‐hand side of Equation (4) is an increasing function of UH0a0, which itself is uniformly distributed (given X), justifies naming UH0a0 the “risk quantile.” Parameter ρ0 describes the strength of dependence of P(Y1a0=0∣X,B,L0) on UH0a0. At one extreme, there is no dependence when ρ0=0; at the other, Y1a0≈I{UH0a0