the variables obeys the causal structure depicted in figure 1. Here, the mediators and confounders measured at time $t_{k - 1}$ are time-varying confounders of the relationship between the mediator measured at time $t_k$ and the outcome. To derive the treatment weights (step 1), we first considered a logistic (treatment) model adjusting for the main effects of all baseline covariates. To assess the potential of covariate-covariate interactions, we used a LASSO variable selection process (R package glmnet) to select the most important interaction terms from the set of all possible two-by-two covariate interactions. The chosen interactions were then added into the treatment model. The tuning parameter in the LASSO was selected by leave-one-out cross-validation.

To derive the mediation weights (step 3), we first considered a logistic (mediator) model adjusting for $t_k$, $M_{k-1}$, $L_k$ and the main effects of all baseline covariates. To assess whether the conditional distribution of $M_k$ had a residual dependence upon the history of $M$ and $L$ that preceded the time $t_{k-1}$ (for $M$) and $t_k$ (for $L$), we used the LASSO to determine the first post-baseline measurement of $M$ and $L$ that were predictive for $M_k$, conditional on the later measurements. This measurement and all measurements 