time $t$, conditional on the later measurements. This measurement and all measurements following this one were included into the censoring proportional hazard model. Next, as for the mediator model, we assessed whether there were important (i) treatment-baseline/longitudinal covariate interactions and (ii) baseline covariate-covariate interactions that should be adjusted for. For each step, an independent backward elimination process was performed to select the most important interaction terms from all possible interactions of the same type. The interactions that were chosen in the previous step were always included in the model of the subsequent steps (which implies no exclusion of these terms in the subsequent steps). Note that we used backward elimination for the construction of the censoring models (as opposed to LASSO) due to the lack of prepackaged software that can apply LASSO or other penalized variable selection methods on a counting format survival dataset. Results of the variable selection processes for the treatment, mediator and censoring models are reported in Online Supplementary Material file.

The two natural effect proportional hazard models (i.e. model (1) and (2)) specific for dementia and for death were then fitted using the calculated weights. The confidence intervals of the total, direct and indirect hazard ratios 