Abstract
The increase in the use of mobile and wearable devices now allows dense assessment of mediating processes over time. For example, a pharmacological intervention may have an effect on smoking cessation via reductions in momentary withdrawal symptoms. We define and identify the causal direct and indirect effects in terms of potential outcomes on the mean difference and odds ratio scales, and present a method for estimating and testing the indirect effect of a randomized treatment on a distal binary variable as mediated by the nonparametric trajectory of an intensively measured longitudinal variable (e.g., from ecological momentary assessment).Coverage of a bootstrap test for the indirect effect is demonstrated via simulation. An empirical example is presented based on estimating later smoking abstinence from patterns of craving during smoking cessation treatment. We provide an R package, funmediation, available on CRAN at https://cran.r-project.org/web/packages/funmediation/index.html, to conveniently apply this technique. We conclude by discussing possible extensions to multiple mediators and directions for future research.
Keywords: Ecological momentary assessment, functional regression, indirect effect, mediation, smoking, time-varying effect modeling
1. Introduction
Increasingly, researchers collect intensive longitudinal data on variables which are hypothesized to mediate the effect of an intervention on an end-of-study outcome of interest. For example, in a smoking cessation intervention study, individuals may be randomly assigned to a smoking cessation treatment such as the nicotine patch or varenicline. The first several weeks post-quit day are critical to maintaining smoking abstinence. Withdrawal symptoms (e.g., cravings, negative affect) may fluctuate even within a single day during these early weeks, and these fluctuations may have an effect on maintaining smoking abstinence. An effective smoking cessation treatment may have an effect on smoking abstinence that is due in part to changes in these mediating variables (i.e., due to a reduction in withdrawal symptoms).
Intensive longitudinal data can be collected using ecological momentary assessment (EMA; see Shiffman, Stone, & Hufford, 2008), in which individuals are contacted multiple times per day for several weeks, and asked to report their cravings, affect, and other variables, including use behavior. The data need not be collected using EMA prompts; for example, it may be collected automatically with a mobile or wearable device. EMA data are also collected in other substance use cessation studies, and in weight loss and physical activity studies. In these studies, individuals may be assigned to a behavioral intervention, mediators are measured intensively over time, and the ultimate outcome of interest is whether the behavior change in question has successfully been maintained. The goal of this manuscript is to present and estimate a mediation model to evaluate the process by which a randomized intervention affects an end-of-study outcome via an intensively measured longitudinal process.
Over the last several decades, mediation analysis has been extended from single time point measures of a treatment, X, mediator, M, and outcome, Y, to multiple mediators, and to treatment, mediators, and outcomes that are measured longitudinally (MacKinnon, 2008). More recently, the assumptions needed to define and identify causal effects in the context of mediation have received considerable attention. As mediation is inherently about causal pathways, in which a treatment affects change in a mediator, which in turn affects change in the outcome, the potential outcomes framework has been employed to define and identify causal mediation effects (VanderWeele, 2015).
Only in the last decade has mediation with an intensively measured treatment, mediator, or outcome within the potential outcomes framework been introduced. Specifically, Lindquist (2012) proposed an approach for a mediator measured intensively by functional magnetic resonance imaging (fMRI). Other advancements have included time-varying treatment and time-varying mediators (Huang & Yuan, 2017; Park, Steiner, & Kaplan, 2018; VanderWeele & Tchetgen Tchetgen, 2017), time-varying mediators and outcomes (Huang & Yuan, 2017; Loh et al., 2020; Zeng, Rosenbaum, Archie, Alberts, & Li, 2021), time-varying treatment and mediator with a survival outcome (Vansteelandt, Linder, Vandenberghe, Steen, & Madsen, 2019; Zheng & van der Laan, 2017), and an exogenous (e.g., environmental) time-varying treatment with time-varying mediator and outcome (Bind, Vanderweele, Coull, & Schwartz, 2016). Additionally, Qian, Yoo, Klasnja, Almirall, and Murphy (2019) study the mediation of a short-term effect of a time-varying treatment (see also K. Liu, Saarela, Feldman, & Pullenayegum, 2020). However, here we focus on a single-time distal effect of a single-time treatment, as mediated by a process occurring between those times.
Specifically, we consider a time-invariant treatment, intensively measured mediator, and end-of-study outcome (see Figure 1). This structure most closely resembles that of Lindquist (2012), but he considered only a continuous normally distributed outcome. We propose an extension to a binary outcome, such as smoking abstinence at follow-up in our motivating study. A binary outcome in a causal mediation analysis can be somewhat more complicated, even for a mediator measured at only a single time point (Rijnhart, Twisk, Chinapaw, de Boer, & Heymans, 2017; Rijnhart, Twisk, Eekhout, & Heymans, 2019; Rijnhart, Valente, MacKinnon, Twisk, & Heymans, 2021). Causal effects for numerical outcomes are generally stated as differences in expected values. For binary outcomes, the difference in expected values is interpreted as a difference in probabilities (i.e., risk difference). However, if a risk ratio, odds ratio, or other quantity is desired, then causal mediation effects are defined differently (VanderWeele & Vansteelandt, 2010).
Figure 1.

Simple (left) versus functional (right) mediation with single-time treatment and outcome.
Although VanderWeele and Tchetgen Tchetgen (2017) consider a single time point measurement of a binary outcome and a time-varying mediator, their approach only partially applies in our context because we, like Lindquist (2012) and Zeng et al. (2021), view the mediation process as functional. One approach to fitting a mediation model in a setting with intensive longitudinal measurements is to replace a longitudinal process, M(t) and/or Y(t), with summary statistics such as means, sums, or estimated linear slopes. This parametric summary approach could be made sophisticated by treating intercepts and slopes as subject-level latent random variables (de Stavola, Herle, & Pickles, 2022; Magidson, Blashill, Safren, & Wagner, 2015; Sullivan, Gunzler, Morris, & VanderWeele, 2021). However, as Lindquist (2012) pointed out, it is also possible to take a less parametric approach, avoiding imposing linear shapes on trajectories, using ideas from functional regression (Ramsay & Silverman, 2005). Although Zeng et al. (2021) propose functional mediation for an intensively measured mediator and intensively measured outcome, they do not propose a method for evaluating an intensively measured mediator with an end of study outcome. The functional mediation model proposed in this paper uses an outcome measured at a single point in time and thus, some of the assumptions made by Zeng et al. (2021) are not necessary in the present context. Nevertheless, Lindquist (2012), VanderWeele and Tchetgen Tchetgen (2017), and Zeng et al. (2021) provide foundational ideas to the approach proposed here.
This article is organized as follows. In Section 2, we present our motivating example. In Section 3, we introduce the notation, definitions, and identification assumptions needed in order for the effects to be interpreted as causal. In Section 4, we present estimation of the indirect effect in detail, which we have implemented in an R package, funmediation. In Section 5, we present a simulation study to assess the coverage and power in data simulated to resemble to our real-data example. In Section 6, we analyze the real data using the proposed model. Finally, in Section 7, we discuss limitations, future directions, and conclusions. In Appendix 1, we review the proof by Lindquist (2012) for the identity link function and extend it to a log link function modeling a probability ratio. The more commonly used logistic link can be approximated by a log link in the case of rare outcomes (see Feingold, MacKinnon, & Capaldi, 2019; Rijnhart et al., 2021; VanderWeele & Vansteelandt, 2010).
2. Motivating Example
Our motivating example comes from the Wisconsin Smokers’ Health Study 2 (WSHS2; Baker et al., 2016, ClinicalTrials.gov identifier: NCT01553084). The WSHS2 is a comparative efficacy trial directly comparing the two most effective smoking cessation therapies (varenicline and combination nicotine replacement therapy [cNRT]) with one another and with an active comparator treatment (nicotine patch) (see Baker et al., 2016; Le Foll et al., 2022).
Smokers (n = 1086; 52% women, 67% white, mean age = 48, mean number of cigarettes smoked/day = 17), recruited from Madison and Milwaukee, were randomly assigned to one of the three pharmacotherapies. The outcome considered here is carbon-monoxide (CO)-confirmed self-reported 7-day point-prevalence abstinence at 4 weeks post-target quit day (TQD). Participants completed one morning EMA prompt, one random prompt during the day, and one evening prompt every day for the first 2 weeks post-TQD and then every other day for the remaining 2 weeks of the EMA period. Thus, there are up to 66 EMA measurements that are not equally spaced due to fluctuations in the timing of the prompts and to sporadic missingness. Our proposed approach allows for these irregularly spaced assessments. The goal of our empirical analysis is to examine whether the intervention of interest (varenicline) has an effect on smoking cessation (7-day point-prevalence abstinence at 4 weeks post-TQD) that is mediated by a reduction in craving, compared to any nicotine replacement therapy. Craving is an important predictor of relapse in many substance use disorders (Le Foll et al., 2022; Vafaie & Kober, 2022), and it was assessed at each EMA prompt during the 4 week post-TQD period. It is treated as a time-varying mediator in Section 6.
3. Proposed Approach
3.1. Notation
Consider a sample of individuals, in which each individual is randomly assigned to one of two treatments, , the control or comparison group, or , the active treatment group. Note that this notation is easily extended to more than two treatment conditions. Each individual is assessed at measurement occasions, which may vary across individuals, between times and . At each measurement occasion, , such that , the mediator, is assessed. The end-of-study outcome, denoted , is measured at a distal time point, which is after and common to all individuals. Let denote the complete mediator process for individual from beginning to end of the study interval, including times at which it is not observed. In the context of the potential outcomes framework, we additionally use parentheses to denote the counterfactual outcomes under each treatment condition. Specifically, let be the potential value that the complete mediator process would take for individual , if that individual, perhaps counterfactually, received treatment level . Let be the potential outcome if individual , perhaps counterfactually, is given treatment and mediator process .
We make the stable unit treatment value assumption (SUTVA; Rubin, 1980) of non-interference between individuals. That is, an individual’s potential values on the mediator process are not dependent on any other individual’s treatment assignment and an individual’s potential outcomes are not dependent on any other individual’s treatment assignment or potential values of their mediator process. SUTVA also states that there are not multiple versions of the treatment (see Hernán & Robins, 2020). In addition, we make a consistency assumption, in which the counterfactual outcomes ) and ) are equal to the observed outcomes, and , respectively, when individual i is assigned to treatment level x, and the composition assumption, i.e., (Lindquist, 2012; VanderWeele & Vansteelandt, 2009, 2010). Finally, let denote the potential outcome for individual i given treatment level x and given mediator process, . That is, , a specific mediator process. Where possible, to avoid confusion, we drop the i subscript for simplicity.
3.2. Definitions
In this paper we focus on the natural direct and indirect effects, similar to VanderWeele and Vansteelandt (2010) and Rijnhart et al. (2021). In contrast, VanderWeele and Tchetgen Tchetgen (2017) and Pinto Pereira et al. (2020), focus on the interventional direct and indirect effects; for an explication of differences between these definitions, see Moreno-Betancur and Carlin (2018) and Nguyen, Schmid, and Stuart (2021).
If an identity link is used, the causal effect is most readily expressed in terms of a mean difference. In this case, the average causal total effect of the treatment on the distal end-of-study outcome is defined as:
which can be decomposed into the natural direct effect:
and the natural indirect effect:
obtained by adding and subtracting . The natural direct effect, NDE(0), defines the effect of the treatment on the outcome holding the mediator process to the potential value obtained under the control condition (i.e., ). The natural indirect effect, NIE(1), defines the effect on the outcome of the potential mediator process under treatment vs. the potential mediator process under control while holding treatment level fixed to treated (i.e., ) (see, e.g. VanderWeele, 2015). Alternatively, one could add and subtract to obtain an equivalent decomposition: and . We use the former decomposition, , although the procedures are applicable to the latter as well.
For modeling binary or count data, a log or logistic link may be used instead of an identity link function. That is,
where represents the log or logit link. In this case, the causal effect definitions are on the ratio scale (either rate ratio for the log link or odds ratio for the logit link). For the log link this would be:
| (1) |
Equivalently, the log of each effect is a difference of log probabilities or log odds, respectively.
3.3. Identification Assumptions
In addition to the aforementioned SUTVA, consistency, and composition assumptions, identifying the potential outcomes from the observed data requires the following ignorability assumptions given baseline covariates, C, as shown in Figure 2. In addition, we require the positivity assumption which states that each individual has a positive probability of being assigned to either treatment and to a given mediator process given their covariate values, and . The assumptions allow the identification of the potential outcomes from the observed data. The assumptions are adapted from VanderWeele and Vansteelandt (2010) (see also Imai, Keele, & Yamamoto, 2010), but the first three are analogous to Assumption 1 of Lindquist (2012), and the last is analogous to Assumption 2 of Lindquist (2012).
Conditional on C, the effect of the treatment on the outcome is unconfounded (i. e., there are no unmeasured confounders of the treatment and outcome): .
Conditional on X and C, the effect of the mediator on the outcome is unconfounded (i.e., there are no unmeasured confounders of the mediator and outcome): .
Conditional on C, the effect of the treatment on the mediator is unconfounded (i. e., there are no unmeasured confounders of the treatment and mediator): .
There are no measured or unmeasured confounders of the mediator and outcome that have been influenced by the treatment: for all x and x*.
Figure 2.

Mediation model with functional M, including baseline covariates C.
Assumptions 1–3 are standard sequential ignorability assumptions (Imai et al., 2010). Given randomization to the treatment levels, the first and third assumptions are reasonable. In contrast, Assumption 2 may not hold even when there is randomization to the treatment levels, because there is not randomization to the mediating process; however, if a rich set of potential confounders have been measured, then this assumption may still be reasonable conditional on the measured confounders.
Assumption 4 (often referred to as cross-world independence) may be problematic. Although the outcome occurs at a distal time point in our context, and therefore is not itself a time-varying confounder (e.g., as in Zeng et al., 2021), there may be other potential mediating processes which may violate this assumption. For the present motivating example, other variables were measured during the EMA period, such as smoking cessation self-efficacy, self-reported daily smoking, and smoking cessation fatigue. It may be expected that the treatment may influence these variables, which in turn may affect both the mediating process of interest (i.e., craving) and the outcome, (i.e., abstinence at one month post-TQD). We further discuss possibilities for allowing these additional mediators in Appendix 2.
There are possible alternative assumptions to Assumption 4 when it may be violated (see, e.g. Robins, 2003; VanderWeele, 2015). Rather than assuming that there are no mediator-outcome confounders affected by treatment (i.e., Assumption 4), an alternative identifying assumption is to assume that there are no interactions between treatment assignment and the mediating process. However, this assumption is not as innocuous as it may seem (Robins, 2003). It means that the natural direct and indirect effects are the same in both the treatment and control groups (i.e., NDE(0) = NDE(1) and NIE(0) = NIE(1)). In this case the controlled direct effect, defined as for some specified fixed trajectory for the mediator process, (i.e., , is equal for any level of and is also equal to the NDE. Then the NIE can be parametrically identified as TE−NDE, as in the traditional linear structural equation modeling approach to mediation. However, this lack of interaction may also be difficult to justify. Note that Zeng et al. (2021), Lindquist (2012), and Zhao, Luo, Lindquist, and Caffo (2018) all impose Assumption 4 or the no-interaction assumption.
Lindquist (2012) discusses an alternative approach to estimating the causal effect of the mediator on the outcome, without making Assumption 4. He proposes the intuition of using the ratio of the total effect of X on Y to the effect of X on M as a measure of the strength of mediation through M. This could be described as using X as an instrumental variable for the purposes of the causal effect of M on Y. However, this alternative approach requires an exclusion restriction assumption (no direct effect of X on Y, i.e., complete mediation) which will often be unrealistic. In the current example, it does not seem plausible to assume that reduced craving is the only mechanism by which treatment affects relapse probability.
In any case, identifying the natural direct and indirect effects from the observed data requires strong assumptions. If Assumption 4, the no-interaction assumption, or the exclusion restriction are not realistic, then it may be possible to define interventional direct and indirect effects (see VanderWeele & Tchetgen Tchetgen, 2017), rather than the natural direct and indirect effects considered here. This approach is rather new, and applying it to functional regression requires further methodological research, but it is a promising future direction.
Given Assumptions 1 – 3 and the no-interaction assumption (or Assumption 4), the natural direct and indirect effects can be identified from the observed data. The causal effects can be estimated as functions of the expected values (e.g., of the observed data. Next, we describe the models we use to estimate these quantities.
4. Estimation
In general, the estimation strategy is a two-step process in which first a model is fit to predict the mediator from treatment and baseline covariates, and then another model is fit to predict the outcome from the mediator, treatment, and baseline covariates.
4.1. Model for Mediator
For the identity link, the model for the potential values of the mediator at time for individual if given treatment is:
| (2) |
where is a random process representing measurement-level errors for the mediator, which are assumed to have for all and may be correlated within person, and where , , and are smooth functions of time. By using the consistency assumption, we can simply write the potential value, which is a function of both and treatment level , as when expressing an expected value conditional on .
More generally, we can model as
| (3) |
where is a link function such as log, logit, or identity.
Model (2) or (3) is an application of concurrent function-on-scalar regression (Ramsay & Silverman, 2005) or equivalently the time-varying effect model (TVEM; Hastie & Tibshirani, 1993; Tan, Shiyko, Li, Li, & Dierker, 2012). The link function is treated as given and known, but the functions are not assumed to have any simple parametric form known to the data analyst.
4.2. Model for Outcome
The model for the potential outcome using an identity link is given as:
| (4) |
where the are subject-level errors for the response assumed to have . The subject-level errors for the outcome in (4) are treated as independent of the measurement-level errors for the mediator in (2).
In general, we can model the expected value of the observed outcome, , given treatment , covariate vector , and mediator trajectory , as
| (5) |
where is a link function such as an identity, log, or logit. A model such as (4) and (5) represents scalar-on-function regression (Goldsmith, Bobb, Crainiceanu, Caffo, & Reich, 2011; Lindquist & McKeague, 2009; Ramsay & Silverman, 2005).
4.3. Expression for the Natural Indirect Effect
Using the identity link, and under Assumptions 1–3 and the no treatment-mediator interaction assumption, the NIE(0) and the NIE(1) are equal. Thus, the natural indirect effect is:
Lindquist (2012) proved this for the identity link.
For a binary outcome using a log link,
and the proof is given in Appendix 1. For binary data using a logistic link, it is more difficult to express the decomposition of the total effect into direct and indirect effects in a straightforward way, but the logit link function approximates a log link function when outcomes are rare (see Rijnhart et al., 2021; VanderWeele & Vansteelandt, 2010). In any case, it remains reasonable to use a significance test for as a test for significant mediation, by analogy to the product of coefficients method in traditional mediation analysis. Another option, not pursued here, would be to modify the definition of direct and indirect effects in order to make the logistic link easier to handle theoretically, following either the ideas in Geldhof, Anthony, Selig, and Mendez-Luck (2017) or Doretti, Raggi, and Stanghellini (2021).
The controlled direct effect of on given a fixed mediator trajectory is for the identity link or for the log link. Because of the assumption of no treatment-mediator interaction, the controlled direct effect of given equals both the and .
4.4. Model for Total Effect
Finally, the total effect using an identity link is given as follows:
For the log link, the total effect is additive on a log scale,
but is multiplicative on the ratio scale. Again, a logit link is also possible, although it can make the relationship between direct, indirect, and total effects difficult to express unless the outcome is rare.
4.5. Test for Indirect Effect
To test for an indirect effect, one can test whether a nonparametric bootstrapped confidence interval for includes zero (Lindquist, 2012). In this context, the indirect effect is a scalar, even though its individual effects, and , are functions of .
4.6. Time-varying effect models
Models (2) and (3) can be fit as longitudinal varying-coefficients models, i.e., time-varying effect models (TVEM; see Tan et al., 2012). In general, a TVEM model with a time-varying response variable, , is specified as
for a set of longitudinal predictors observed on a sparse and possibly irregular grid. In this general version, both the covariates and their “effects” (time-specific regression coefficients) are time-varying. However, any of the and/or can be optionally constrained to be constant over time.
Notice that for parsimony and interpretability, and to avoid the curse of dimensionality, TVEM assumes a linear or generalized linear structure at any given time, and that the estimates of and the ’s are smooth but may potentially be nonlinear functions of time. Thus, Models (2) and (3) are included as a special case. The TVEM model is straightforward to fit as a marginal model using working independence and robust standard errors, and a spline approximation to the functional coefficients. Thus, a TVEM marginal model is essentially a generalized estimating equations (Liang & Zeger, 1986) model with some of the parametric terms replaced by splines.
We fit the model by representing the functional coefficients as penalized B-splines (Eilers & Marx, 1996), as implemented in the tvem function of the tvem R package (Dziak, Coffman, Li, Litson, & Chakraborti, 2021). The model is fitted approximately by first constructing a spline basis for the time interval of interest, and then performing a large parametric regression including each function of time in the basis, as well as its product with each coefficient. We use a penalty function on the nonlinear functions of time in order to avoid overfitting and control the level of smoothness versus flexibility of the fitted function. By default, tvem uses cubic B-splines with a maximum of 20 interior knots and a first-order difference penalty on the knot coefficients (see Eilers & Marx, 1996). Penalized truncated power splines (see, e.g., Huang & Yuan, 2017; Tan et al., 2012) are an alternative option.
TVEMs can be viewed as a special case of the varying-coefficient model (Hastie & Tibshirani, 1993) in which the coefficients are indexed by time. The varying coefficients allow the effect of treatment on the mediator to change as a nonparametric function of time. Additional time-varying and time-invariant predictors can also be added to the model. Predictors can be specified to have either time-varying or time-invariant effects. For example, demographic variables or treatment group membership may have time-varying relationships with the outcome variable even if they are themselves not time-varying. In the tvem package, within-subject correlation is accounted for indirectly by using sandwich standard errors, similar to working-independence GEE (Liang & Zeger, 1986). This can be seen as an application of penalized pseudo-likelihood, incorporating the penalty required to regularize the spline functions. The penalty function is tuned by a restricted maximum likelihood (REML) approach (Wood, 2001). This approach shrinks the changes at each knot, acting analogously to an empirical Bayes prior. The prior distribution used in the tvem package is a first- or second-order difference penalty as described in Eilers & Marx (1996), and it acts to shrink the fitted curve towards a straight line (possibly even a flat line with zero slope) unless data suggests otherwise.
4.7. Scalar-on-function regression
Although the underlying process, , is assumed to be a continuous function, practically it is observed at only a finite number of points and potentially has measurement error. For computational purposes, it would be very helpful to have values for on a dense, regular grid without missing values. However, this is not likely to be the case in practice. One option for working around this difficulty, if the amount of missing data is not too great, is by linear interpolation between nonmissing points. Another option is to use spline regression to fit a smoothed curve to the observed data for each participant , and then using these smoothed values to estimate the function. This smoothing could be heuristically justified by supposing that the mediator is measured with error, and that the true trajectory of the mediator was smoother than the trajectory which would have been recorded if all possible measurement occasions on the grid had been observed for all participants. That is, we let at time be a possibly smoothed prediction of the true latent curve underlying , rather than the observed (and presumably error-contaminated) itself (Goldsmith et al., 2011) by incorporating a presmoothing step in the model (see Appendix 1).
After this presmoothing, the fitted model is
| (6) |
Additional scalar (i.e., time-invariant) predictor variables with scalar coefficients may be added to Model (6). The coefficients, both scalar and functional, are estimated following the general method of Goldsmith et al. (2011) using REML. The coefficient functions are represented via the penalized thin plate regression splines approach described by Wood (2003) and Wood (2017). Notice that the presence of within-subject variability is required, because if were constant over for each , then would not be identified. Accordingly, with substantial and meaningful within-subject variability, the functional regression coefficient, , requires regularization using a penalty function and/or a low-dimensional basis restriction.
4.8. Overall indirect effect computation
Once and have been estimated, the indirect effect is operationally defined as the integral . This is approximated by taking the mean of for an evenly spaced grid of points and then rescaling by multiplying it by the width of the time interval of interest.
Next, a nonparametric bootstrap significance test for an overall -value for is obtained. A simple approximate confidence interval for this overall quantity using either a normal approximation or the percentile method can be obtained using the funmediation package.
4.9. Difficulties with time-specific indirect effects
We focus on an overall test of mediation, rather than time-specific mediation estimates, and do not attempt to interpret at a specific t. This is in contrast to Lindquist (2012) who used a “wild bootstrap” to construct confidence intervals for the point-specific indirect effect at each of a grid of points . However, the wild bootstrap is more difficult to apply to binary outcomes, since it involves permutation of residuals. Also, the practical meaning of the time-specific indirect effect with EMA data could be more difficult to interpret because of temporal dependence (see Dziak et al., 2019; VanderWeele & Tchetgen Tchetgen, 2017) and because time-specific snapshots may not adequately represent time-lagged effects (see Maxwell, Cole, & Mitchell, 2011); we address this further in the Discussion.
5. Simulations
We performed a simulation study to determine whether the proposed method has adequate coverage and power under realistic scenarios. We simulated 5000 datasets for each of three sample size scenarios (, , and ). In each dataset, the treatment X is dichotomous and generated with equal probability of 0 (representing control group) and 1 (representing treated group). We imagine an interval from 0 to 1 representing rescaled time in a smoking cessation program, X as a randomized intervention to reduce cravings, Mi(t) as recent amount of cravings reported at time t, and Y as relapse status by end of program, with indicating relapse. These simulated variables map onto the applied example, but the specific values of the simulated variables represent a much wider array of possible variable combinations.
5.1. Methods
The mediator is generated on a grid of 100 time points on an interval from 0 to 1 (e.g., 0.00, 0.01,..., 0.99). However, 60% of those observations are randomly deleted, to create uneven person-specific measurement times. as a whole is assumed to follow a Gaussian process with mean function . We set the time-varying mean of the mediator for the control group to , and the time-varying effect of on the mediator to . This means that both the control and treatment groups start on average with a mean near 0 on the mediator, but the control group increases nonlinearly over time to near 1, while the treatment group increases nonlinearly to near 0.3. The error process for the mediator is generated to have a standard deviation of 2 and an AR(1) structure with correlation 0.8 between adjacent measurements on the full 100-point grid.
The outcome was generated as binary, with a logistic link. Specifically, success probability was given by
where , and . Therefore, tends to reduce , and is positively related to , such that the overall indirect effect is negative (a negative coefficient times a positive coefficient). Specifically, the overall true value of the indirect effect is taken to be . Because the treatment is simulated to be beneficial and the simulated outcome is imagined as deleterious, the negative effect is reasonable.
The model was fit to each dataset using the proposed combination of TVEM and scalar-on-function regression. We tested the null hypothesis that the indirect effect was zero using 199 bootstrap replications. In a real data analysis, 199 would be inadequate, and at least 999 would be recommended. However, we found that the larger number was computationally infeasible in a simulation setting, because 1000 simulated datasets per scenario with 999 bootstrap replications would mean having to fit and tune the model separately for each of approximately one million datasets per scenario.
The R software environment (R Core Team, 2020) was used, with author-written functions available in the package funmediation available on CRAN. This package employs the tvem package (Dziak et al., 2021) and the pfr function in the refund package (Goldsmith et al., 2020). Each package uses generalized additive model functionality from the gam or bam functions in the mgcv package (Wood, 2017, 2021) for back-end calculations. Presmoothing is handled via interpolation using the presmooth option in the lf function in the refund R package. Bootstrapping is performed using the boot function in the boot package (Canty & Ripley, 2020; Davison & Hinkley, 1997).
5.2. Results
Performance measures for estimates of the relationship of X to M(t) are shown in Table 1. Estimates for α0(t) and αX(t) had very little bias and had increasing precision as sample size increased.
Table 1.
Simulation Results for TVEM Predicting Mediator from Treatment
| Sample size | 250 | 500 | 1000 |
|---|---|---|---|
|
| |||
| Intercept function α0(t) | |||
|
| |||
| Bias | −0.0010 | −0.0002 | −0.0006 |
| Mean squared error | 0.0105 | 0.0054 | 0.0029 |
| Root mean squared error | 0.1022 | 0.0736 | 0.0537 |
| Mean estimated SE | 0.1038 | 0.0739 | 0.0535 |
| Pointwise coverage | 0.9461 | 0.9464 | 0.9460 |
| Familywise coverage | 0.6422 | 0.6270 | 0.6276 |
|
| |||
| Treatment effect function αX (t) | |||
|
| |||
| Bias | 0.0001 | 0.0008 | 0.0001 |
| Mean squared error | 0.0203 | 0.0106 | 0.0057 |
| Root mean squared error | 0.1423 | 0.1031 | 0.0758 |
| Mean estimated SE | 0.1444 | 0.1032 | 0.0747 |
| Pointwise coverage | 0.9485 | 0.9531 | 0.9510 |
| Familywise coverage | 0.7170 | 0.6956 | 0.6412 |
Performance measures for estimates of the relationship of X and M(t) to Y are shown in Table 2. Results indicate a very small bias of the estimated effects towards zero, which does not seem to vanish with increasing sample size. Nonetheless, random error decreases with increasing sample size, and pointwise coverage for the 95% pointwise confidence intervals is essentially nominal for all sample sizes, so performance can generally be considered good. The small but non-vanishing bias present may be a side effect of the shrinkage penalty functions used to prevent overfitting of αX and βM.
Table 2.
Simulation Results for Functional Regression Predicting Outcome from Mediator
| Sample size | 250 | 500 | 1000 |
|---|---|---|---|
|
| |||
| Intercept β0 | |||
|
| |||
| Bias | 0.0277 | 0.0236 | 0.0301 |
| Mean squared error | 0.0592 | 0.0284 | 0.0145 |
| Root mean squared error | 0.2432 | 0.1685 | 0.1203 |
| Mean estimated SE | 0.2379 | 0.1668 | 0.1174 |
| Coverage | 0.9492 | 0.9504 | 0.9488 |
|
| |||
| Treatment βx | |||
|
| |||
| Bias | −0.0161 | −0.0176 | −0.0241 |
| Mean squared error | 0.0835 | 0.0410 | 0.0203 |
| Root mean squared error | 0.2889 | 0.2024 | 0.1424 |
| Mean estimated SE | 0.2833 | 0.1986 | 0.1399 |
| Coverage | 0.9486 | 0.9434 | 0.9504 |
|
| |||
| Mediator conditional effect function βM (t) | |||
|
| |||
| Bias | −0.0186 | −0.0180 | −0.0219 |
| Mean squared error | 0.1329 | 0.0651 | 0.0339 |
| Root mean squared error | 0.3645 | 0.2552 | 0.1841 |
| Pointwise coverage | 0.9603 | 0.9577 | 0.9552 |
| Familywise coverage | 0.8598 | 0.8492 | 0.8364 |
The confidence intervals for are constructed only for pointwise coverage (i.e., a 95% long-term probability of containing the true value at any fixed time point), not nominal familywise coverage (i.e., a 95% long-term probability of covering the true value for all the time points jointly), so they would not perform as well on familywise coverage. Lindquist (2012) recommended false discovery rate correction over values of t. However, in the case of observational studies with potentially diffuse and weak effects over time, this might lead to a very high Type II error rate. That is, researchers might misinterpret points which are indicated as significant at a given level as being fundamentally different from time points indicated as nonsignificant, i.e., as times when the exposure or treatment are active and inactive, respectively, despite both being highly affected by sample size and sampling error. It is not yet known how best to handle this issue. Fortunately, it is not a problem for the overall indirect effect , because it is a scalar and only tested once.
Performance measures for estimates of the indirect relationship of X to Y are shown in Table 3. There was a small conservative bias towards zero, which became even smaller for larger sample sizes. Mean squared error also decreased for larger sample sizes. Power and coverage are shown for the normal-theory bootstrap, basic bootstrap, and percentile bootstrap. Of the three methods, the best coverage and power are obtained using the percentile bootstrap. Coverage is very good, and power increases with larger sample sizes. However, adequate power requires more than 500 participants.
Table 3.
Simulation Results for Indirect Effect
| Sample size | 250 | 500 | 1000 |
|---|---|---|---|
|
| |||
| Performance of point estimate | |||
|
| |||
| Bias | 0.0220 | 0.0165 | 0.0160 |
| Mean squared error | 0.0140 | 0.0070 | 0.0036 |
| Root mean squared error | 0.1182 | 0.0839 | 0.0603 |
| Mean estimated SE | 0.1325 | 0.0869 | 0.0593 |
|
| |||
| Bootstrap coverage by method | |||
|
| |||
| Normal | 0.9648 | 0.9500 | 0.9340 |
| Basic | 0.9682 | 0.9516 | 0.9348 |
| Percentile | 0.9576 | 0.9512 | 0.9452 |
|
| |||
| Bootstrap power by method | |||
|
| |||
| Normal | 0.2366 | 0.6350 | 0.9284 |
| Basic | 0.1570 | 0.5654 | 0.9104 |
| Percentile | 0.3704 | 0.6906 | 0.9420 |
6. Empirical Analysis
In this section, we present the results from analyzing the data described in Section 2. The R code for implementing this analysis is available in the supplementary materials.
6.1. Sample Characteristics and Missing Data
Our analysis sample, taken from the 1086 participants in the WSHS2 (Baker et al., 2016), consisted of 1041 participants who were randomized, provided data to at least one EMA prompt post-TQD, and whose abstinence or non-abstinence status, Y, could be ascertained. There was very little missingness for Y, which was not subject to noticeable differential missingness across treatment group (11 missing Y values from among those randomized to patch group, 13 from the varenicline group, 11 from the cNRT group). Thus, missingness is not a large concern for the outcome, Y.
However, participants varied widely in the proportion of response to the total 66 EMA prompts possible, so the mediator M(t) at any given time t was subject to noticeable missingness. This may be a concern for assessing the relationship between X and M(t) or between M(t) and Y.
Among the 1086 participants, all of whom have X (randomization status), 45 did not provide any EMA data, and they were excluded from the analysis. The 1041 participants who were included provided between 1 and 66 observations per participant (mean=41, median=45). There were three EMA prompts per day: morning, evening, and a random time in between. For participants who responded to most prompts, the middle, random, prompt was more likely to be missing than either the morning or evening prompts. The random prompt may have been missing because the participant merely happened to be temporarily unavailable to answer. This is likely to be less of a problem than long-term dropout.
Because the current analysis is intended mainly as an illustration of a new technique, we do not attempt to solve the possible problem of informative missingness here. However, the serious potential limitations which it poses, and possible future approaches to address them, are discussed in Section 7. We conducted an additional analysis in which participants who responded to two or fewer EMA prompts post-TQD were excluded as a sensitivity analysis to partially assess the impact of missingness of functional data on estimation using this technique. The results are similar to those presented here and are included in Appendix 3.
6.2. Total Effect
For comparison, we fit a logistic regression model of the outcome, CO-confirmed 7-day point-prevalence abstinence (1=abstinent, 0=relapsed), at four-weeks post-TQD on treatment group (1 = varenicline, 0 = nicotine replacement therapy). The total effect estimate from this model was not statistically significant (estimate = 0.023, std. error = 0.135, z = 0.167, p = 0.868). Because this study does not have a no-treatment control group, and instead focuses on comparative efficacy between active treatments, this null finding may be due to the true difference between treatment efficacy being small (i.e., small effect size for comparing treatment levels). However, the example is still a useful illustration of the proposed procedures.
6.3. Direct and Indirect Effects
Next, we examine the direct and indirect effects of craving, defined as the desire to smoke in the last 15 minutes, throughout the first two weeks post-TQD using the proposed method. The results of these analyses are unique, providing insights that are not discernible from any other analytic approach, including other mediation approaches. The indirect effect estimate was statistically significant (estimate = 0.044, percentile method 95% bootstrap confidence interval = (0.006, 0.111)). The estimate of the direct effect was not statistically significant (estimate = −0.067, std. error = 0.139). The indirect and direct effects do not add up exactly to the total; this is likely due to the effects of smoothing of the mediator and of the estimated effects (see Appendix 1). It is likely that oversmoothing or undersmoothing of the mediator trajectories may have an effect like that of measurement error, which is known to cause bias (see de Stavola et al., 2022; Fritz, Kenny, & MacKinnon, 2016).
6.4. Effect of Treatment on Mediator
Examination of the individual effects that comprise the indirect effect revealed a more nuanced interpretation. Figure 3 illustrates the time-varying effect of treatment on the mediator. The effect is such that varenicline reduces craving and this effect becomes slightly stronger (i.e., more negative) during the first week post-TQD before leveling off. Other than the first day post-TQD, the effect is statistically significant throughout the two-week post-TQD period, at least in the heuristic sense that the pointwise confidence intervals generally do not include zero.
Figure 3.

Time-varying effect of varenicline (vs. nicotine patch only) on the mediator, craving to smoke in the last 15 min. Left and right panes represent time-varying intercept function and time-varying effect of treatment, respectively. Upper and lower dotted lines represent pointwise approximate 95% confidence intervals.
6.5. Effect of Mediator on Outcome
The effect of the mediator on the outcome, CO-confirmed 7-day point prevalence abstinence at 4 weeks post-TQD, is shown in Figure 4. Results from functional regression are more difficult to interpret precisely than those from a time-varying effect model (Dziak et al., 2019). Nevertheless, it is evident from the confidence intervals in Figure 4 that for the most part, the confidence intervals include 0, with the exception of the end of the first week post-TQD. All else being equal, craving in the first week (especially around day 4) has a negative weight in predicting abstinence, while craving in the second week (especially around day 10) has a weak and perhaps non-significant positive weight. A negative weight followed by a positive weight may be an indication that abstinence is more likely in individuals for whom craving increases over time. However, this explanation is intuitively unlikely because abstainers are expected to experience a decrease in craving over time, so it might be more likely that the result simply means that very high early craving can result in relapse. The wide confidence intervals also make interpretation more difficult.
Figure 4.

Functional effect of the mediator process on CO-confirmed 7-day point-prevalence abstinence 4-weeks post-TQD. Dotted lines represent confidence intervals.
7. Discussion
In this paper, we proposed and illustrated a method for estimating and testing the indirect effect of a randomized treatment on a distal binary outcome variable, as mediated by the nonparametric trajectory of an intensively measured longitudinal process. This continued the work of Lindquist (2012), in combining causal analysis in the counterfactual framework, with regularized overparameterized semiparametric estimation. These two sets of ideas are among the most important in modern statistics (Gelman & Vehtari, 2021). In extending Lindquist’s ideas to a binary setting, we used simulations and a real-data example to illustrate the potential use of functional mediation analysis with binary outcome data. We provide a new R package, funmediation, for fitting this and similar models.
7.1. Limitations
A remaining methodological challenge in functional regression modeling approaches is the issue of missing data and possible informative dropout. If some observations per subject are missing sporadically and completely at random, this would not be a major problem. Many EMA designs give prompts at random times, or at a random number of times, so methods for analyzing them are constructed to allow non-shared measurement times and unequal coordinates. This leads to the simple approach used in this paper, which is to treat occasions of nonresponse to a prompt as though the prompt had never occurred at all on those occasions (essentially listwise deletion, although on the scale of the observation, not the entire participant). This approach assumes that values of M(t) are missing completely at random, which is not ideal.
The situation is more serious if participants drop out for long periods of time, and especially if this might occur for reasons that relate to the variables of interest (e.g., because of being embarrassed or discouraged by a relapse). If the composition of the sample differs at different points in the time interval of interest, then it may be difficult to interpret the overall trajectory. About 14% of the participants in our analysis sample provided less than 20 observations, so even in the absence of informative missingness, their interpolated M(t) trajectories may not closely match what they would have been if more data had been provided.
Multiple imputation can be beneficial for handling missing values in longitudinal data (see Lee, Roberts, Doyle, Anderson, & Carlin, 2016; Schafer & Graham, 2002). More research is required regarding how to use multiple imputation for functional regression (Ciarleglio, Petkova, & Harel, 2020), which is likely to be more challenging than in the more classic case of a few waves of data at fixed times. If informative dropout is suspected, another possibility might be to jointly model the longitudinal processes together with a survival process for dropout, possibly treated as a competing risk for the main outcome of interest (see X. Liu, 2014). However, this also is likely to be challenging to implement in a functional mediation context.
In addition to an overall indirect effect integrated over time, Lindquist (2012) also estimated the product, αX(t)βM(t), for a grid of times t, leading to a time-specific indirect effect. In principle, bootstrap tests could be done to test whether individual time-specific indirect effects are statistically significant, although Lindquist recommends a false discovery rate adjustment in this case, but this may lead to severe power limitations. We did not consider time-specific indirect effects here. Functional regression coefficients can be somewhat difficult to interpret on a time-specific basis with longitudinal data, at least without additional model assumptions. The mediator values at different time points are not independent, so that the most statistically predictive time period need not be the most causally important time period (see de Stavola et al., 2022; Dziak et al., 2019; Gao & Kowal, 2022; Green & Popham, 2016). Furthermore, even without intensive longitudinal data, researchers face the challenge of time-varying confounding (de Stavola et al., 2022; VanderWeele & Tchetgen Tchetgen, 2017). That is, if Y had also been time-varying, then earlier values of Y could affect later values of both M and Y, becoming a time-varying confounder which would violate Assumption 4. We focus on testing the overall effect of the mediator process on a single later time point Y in order to avoid these issues for now, although they will be important to address if functional mediation is to become more widely used for causal inference.
Similar to Lindquist (2012) and Zeng et al. (2021), we assumed no treatment-mediator interaction in order to identify direct and indirect effects. Lindquist (2012) does explore an alternative instrumental variables approach, which requires alternative assumptions. However, this alternative might be more complicated to extend to models that do not use the identity link. As an alternative to natural direct and indirect effects, the use of interventional (see VanderWeele & Tchetgen Tchetgen, 2017) or organic (see Lok & Bosch, 2020) effects might make causal inference in the presence of time-varying confounders more manageable.
We followed Lindquist (2012) in taking a frequentist approach, but a Bayesian approach to mediation analysis may also be useful (K. Liu et al., 2020; Miočević, Gonzalez, Valente, & MacKinnon, 2018). In particular, Huang and Yuan (2017) described a Bayesian analogue to the time-varying mediation method of Lindquist (2012) in the case where the outcome was time-varying and normally distributed, and the ideas could presumably be adjusted to the case of a point and/or binary distal outcome.
Finally, we have not considered the possibility of periodic functions, such as diurnal or seasonal rhythms, as indexes for the varying coefficients in place of linear time. There are some settings in which such features may be theoretically and practically important (Adam et al., 2017).
7.2. Future Directions
Our simulation and example have considered a single time-varying variable as the mediator. Multiple time-varying mediators may be of interest, and options for such models are briefly reviewed in Appendix 2.
We have only considered scalar treatment variables. However, another option would be to have a time-varying exposure X(t) and/or time-varying response Y(t) in addition to the time-varying mediator M(t). This was explored by Zhao et al. (2018) who provided software to fit either concurrent or historical versions of the model. The concurrent approach could be done by fitting a TVEM model to predict the mediator, and another TVEM model to predict the response, and then multiplying the appropriate coefficients pointwise (without integration). The historical approach is able to consider lagged effects either within a sliding window (see also Kim, Şentürk, & Li, 2011) or for the entire past. The concurrent approach is simpler but could miss important information, by only looking at essentially cross-sectional relationships and ignoring lagged ones (see Maxwell et al., 2011). An alternative, highly flexible but still somewhat parametric, approach to time-varying mediation could use differential or integral equations to represent dynamic models in continuous time (Albert, Li, Sun, Woyczynski, & Nelson, 2019).
For point treatment and time-varying mediator and response, Cai, Coffman, Piper, and Li (2022) use a two-step method beginning with a TVEM-like (function-on-scalar) regression to predict M from X, but follow with another function-on-function regression instead of a scalar-on-function regression when predicting Y from M and X. Cai et al. (2022) use local polynomial estimation (Fan & Zhang, 2000) instead of splines to handle the estimation of the semiparametric time-varying effect coefficients, but either approach seems viable.
Functional mediation analysis is a novel method, relevant for both methodologists and applied researchers interested in understanding how an intensively measured longitudinal variable can mediate the relationship between treatment and study outcomes. In the presented approach, we developed functional mediation, a method for estimating a smooth, nonparametric trajectory from treatment to an intensively measured longitudinal mediator using TVEM (Tan et al., 2012), as well as estimating a smooth, nonparametric trajectory from an intensively measured longitudinal mediator to a binary end-of-study outcome using functional regression (Ramsay & Silverman, 2005). More importantly, we provided a mathematical definition of the causal direct and indirect effect that combined TVEM and functional regression in terms of potential outcomes and provided guidance on how to estimate effects using the R package funmediation as well as how to interpret effects.
Although our approach builds on prior work examining TVEM relationships in regression (Tan et al., 2012) and functional mediation (Lindquist, 2012), the present work is innovative in that prior work has not considered a binary, end-of-study outcome measured at only one time point. Binary end-of-study outcomes are often a primary interest in intervention studies, such as smoking cessation, weight maintenance, or abstinence from substance use at follow-up. Despite binary outcomes being a common in intervention studies, methods to evaluate the combination of intensively measured longitudinal data as well as an end of study outcome following treatment are only beginning to be developed. Functional mediation analysis, as presented here is only one of hopefully many future methods that will be developed to model nonparametric longitudinal processes as mediators to better understand how treatment impacts behavior in a causal mediation framework.
Supplementary Material
Acknowledgements
Research was supported by National Institutes of Health grants P50 DA039838 from the National Institute of Drug Abuse and 1R01 CA229542–01 from the National Cancer Institute and the NIH Office of Behavioral and Social Science Research. Content is solely the responsibility of the authors and does not necessarily represent the official views of the funding institutions.
Appendix 1: Effect Decomposition with Log Link
Proof for Log Link
Suppose that a log link function is being used, with the effect definitions given in expression (1) and the assumptions given in section 3.3. The mediator is continuous as given by model (2). The response is binary or count using model (5), with the log function for g. The proof follows VanderWeele and Vansteelandt (2010), Lindquist (2012), and VanderWeele (2015).
By definition,
By the consistency and composition assumptions and assumption 4, we can drop the conditioning of on so that
By the first three assumptions, we can equate the potential outcomes with conditional expectations so that
Then using model (5) in which there is no interaction between the treatment and the mediator, the above becomes
| (7) |
Using model (3),
Therefore,
Now we can compute the total effect, natural direct effect, and natural indirect effect. First,
Next,
Last,
Comparing the above results, it is clear that the direct and indirect effects add (on the log scale) to the total effects, as the definitions of these effects would imply. The proof above would not work exactly for a logit link, because the equivalent of (7) would not hold; it is generally not the case that .
A further limitation is that, following Lindquist (2012), this proof treats as fully observed, so that it can be replaced with its expectation without any bias. In practice, the sample estimates do not exactly decompose, presumably because of smoothing.
Appendix 2: Extending the Model to Multiple Treatments or Multiple Mediators
So far, we did not consider the possibility of more than one mediator process. One way to handle multiple mediators is to study the joint mediated effect through all of the mediators (see VanderWeele, 2015; Wang, Nelson, & Albert, 2013), which could be estimated by subtracting the natural direct effect from the total effect. In this case, the natural direct effect represents the effect that does not go through any of the mediators. If the no-interaction assumption is made, then the controlled direct effect is assumed to equal the natural direct effect, and thus the joint mediated effect may be estimated by subtracting the controlled direct effect from the total effect. Of course, this approach does not reveal which of the mediators, individually, is most important.
Separately estimating the effects of multiple treatment variables and multiple mediator variables is also possible, although the number of parameters required increases quickly. Suppose there are p treatment variables, each either dichotomous or numerical. For example, a set of p binary treatment variables might represent dummy codes for a categorical treatment variable with p+1 levels, such as p treatment groups being compared to a single control group.
Suppose there are mediator variables. Then the model for the mediator could be specified as
for the vector of time-varying mediators, where is a matrix of functions of , and the model for the outcome could be specified as
| (8) |
If mediator, , is not time-varying and does not have time-varying effects, the integral is not needed and could simply be replaced by a product, , for some scalar, . Likewise, in this case, the th column in would equal a constant across all observation times.
In total, if there are p treatment variables and q mediator variables, then there are pq distinct indirect effect pathways. As a caveat, obtaining identifiable estimates and useful confidence intervals from this model might be difficult unless p and q are very small or the sample size is very large. This is because the underlying model for Y is essentially a regression with many covariates (considerably larger than pq, depending on the effective number of time points after smoothing) but only one observation per subject for the outcome. One option for making this problem easier would be to impose parametric assumptions, such as linear or quadratic trajectories, for the mediator or for the α and β coefficients. A decaying exponential trajectory for the effects may be more interpretable than a quadratic trajectory (Fritz, 2014). Alternatively, the effects of a mediator might be constrained to be exactly cumulative, which amounts to its β being constant over time (see Chen, Mukherjee, Ferguson, Meeker, & VanderWeele, 2016).
The model shown in Equation (8) treats each mediator as a parallel pathway from treatment to outcome, so that mediators never interact or affect each other. If the number of mediators and number of measurement times were both very small, then it might be feasible to go beyond this restriction. One could then estimate the path-specific effects (Daniel, de Stavola, Cousens, & Vansteelandt, 2015). However, this will generally not be feasible or interpretable for functional data, because the problems described earlier would be increased by the large number of pathways. Models with large numbers of mediators, such as in genomics studies, might be more challenging to combine with EMA data because of the resulting multiplication of the number of parameters. However, it should be noted that functional mediation models share some similarities with high-dimensional mediation models, in that both involve some form of regularization or data reduction to make the mediator tractable (Derkach, Pfeiffer, Chen, & Sampson, 2019; Zhao, Lindquist, & Caffo, 2020). Therefore, future work in both areas might lead to further adaptations of ideas from one to the other.
As an alternative to using multiple mediators, it might be beneficial to use interventional direct and indirect effects (Chen et al., 2016; Vansteelandt & Daniel, 2017), which do not require assuming that no confounders of the mediator and outcome have been affected by the treatment. A disadvantage is that interventional direct and indirect effects do not necessarily sum to the total effects. The controlled direct effect is a special case of an interventional direct effect and thus, it is also identified in the presence of a mediator-outcome confounder that has been affected by the treatment.
Appendix 3: Analysis excluding participants with two or fewer EMA prompts post-TQD
We reanalyzed our empirical example by excluding the 21 participants who had two or fewer EMA prompts post-TQD. The overall conclusions remain unchanged. The total effect estimate was not statistically significant (estimate = −0.016, std. error =0.136, z = −0.119, p = 0.906). The indirect effect estimate was statistically significant (estimate = 0.043, percentile method 95% bootstrap confidence interval = (0.005, 0.114)). The estimate of the direct effect was not statistically significant (estimate = −0.067, std. error = 0.139). The impact of excluding participants with greater than 97% missing EMA responses is reflected in the total effect estimate but not in the direct and indirect effect estimates. This could be interpreted as the proposed technique’s strength in estimating functional mediation processes in spite of missingness. However, the impact of missingness needs to be thoroughly investigated before claiming this interpretation as scientific evidence of the technique’s functionality.
Footnotes
Declaration of interest statement
The authors report there are no competing interests to declare.
Contributor Information
Donna L. Coffman, Department of Epidemiology and Biostatistics, Temple University, Philadelphia, PA, 19122, USA.
John J. Dziak, Edna Bennett Pierce Prevention Research Center, The Pennsylvania State University, University Park, PA, 16802, USA.
Kaylee Litson, Instructional Technology & Learning Sciences Department, Utah State University, Logan, UT, USA.
Yajnaseni Chakraborti, Department of Epidemiology and Biostatistics, Temple University, Philadelphia, PA, 19122, USA.
Megan E. Piper, Center for Tobacco Research Intervention, University of Wisconsin, Madison, WI, USA.
Runze Li, Department of Statistics, The Pennsylvania State University, University Park, PA, 16802, USA.
References
- Adam EK, Quinn ME, Tavernier R, McQuilland MT, Dahlkee KA, & Gilbert KE (2017). Diurnal cortisol slopes and mental and physical health outcomes: A systematic review and meta-analysis. Psychoneuroendocrinology, 25–41. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Albert JM, Li Y, Sun J, Woyczynski WA, & Nelson S (2019). Continuous-time causal mediation analysis. Statistics in Medicine, 38, 4334–4347. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Baker TB, Piper ME, Stein JH, Smith SS, Bolt DM, Fraser DL, & Fiore MC (2016). Effects of nicotine patch vs. varenicline vs. combination nicotine replacement therapy on smoking cessation at 26 weeks: A randomized clinical trial. JAMA, 315(4), 371–379. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Bind MA, Vanderweele TJ, Coull BA, & Schwartz JD (2016). Causal mediation analysis for longitudinal data with exogenous exposure. Biostatistics, 17(1), 122–134. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Cai X, Coffman DL, Piper ME, & Li R (2022). Estimation and inference for the mediation effect in a time-varying mediation model. BMC Medical Research Methodology, 22, 113. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Canty A, & Ripley BD (2020). boot: Bootstrap R (S-Plus) functions [Computer software manual]. (R package version 1.3–25) [Google Scholar]
- Chen Y-H, Mukherjee B, Ferguson KK, Meeker JD, & VanderWeele TJ (2016). Mediation formula for a binary outcome and a time-varying exposure and mediator, accounting for possible exposure-mediator interaction. American Journal of Epidemiology, 184, 157–159. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Ciarleglio A, Petkova E, & Harel O (2020). Multiple imputation in functional regression with applications to eeg data in a depression study. (arXiv:2001.08175) [DOI] [PMC free article] [PubMed] [Google Scholar]
- Daniel RM, de Stavola BL, Cousens SN, & Vansteelandt S (2015). Causal mediation analysis with multiple mediators. Biometrics, 1–14. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Davison AC, & Hinkley DV (1997). Bootstrap methods and their applications. Cambridge: Cambridge University Press. [Google Scholar]
- de Stavola B, Herle M, & Pickles A (2022). Framing causal questions in life course epidemiology. Annual Review of Statistics and Its Application, 9(1), 223–248. [Google Scholar]
- Derkach A, Pfeiffer RM, Chen T, & Sampson JN (2019). High dimensional mediation analysis with latent variables. Biometrics, 75, 745–756. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Doretti M, Raggi M, & Stanghellini E (2021). Exact parametric causal mediation analysis for a binary outcome with a binary mediator. Statistical Methods and Applications. Retrieved from 10.1007/s10260-021-00562-w [DOI] [Google Scholar]
- Dziak JJ, Coffman DL, Li R, Litson K, & Chakraborti Y (2021). tvem R package (time-varying effect models) [Computer software manual]. Retrieved from https://cran.r-project.org/web/packages/tvem/tvem.pdf
- Dziak JJ, Coffman DL, Reimherr M, Petrovich J, Li R, Shiffman S, & Shiyko MP (2019). Scalar-on-function regression for predicting distal outcomes from intensively gathered longitudinal data: Interpretability for applied scientists. Statistics Surveys, 13, 150–180. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Eilers PHC, & Marx BD (1996). Flexible smoothing with B-splines and penalties. Statistical Science, 11(2), 89–121. [Google Scholar]
- Fan J, & Zhang J-T (2000). Two-step estimation of functional linear models with applications to longitudinal data. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 62(2), 303–322. [Google Scholar]
- Feingold A, MacKinnon DP, & Capaldi DM (2019). Mediation analysis with binary outcomes: Direct and indirect effects of proalcohol influences on alcohol use disorders. Addictive Behaviors, 94, 26–35. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Fritz MS (2014). An exponential decay model for mediation. Prevention Science, 15, 611–622. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Fritz MS, Kenny DA, & MacKinnon DP (2016). The combined effects of measurement error and omitting confounders in the single-mediator model. Multivariate Behavioral Research, 51(5), 681–697. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Gao Y, & Kowal DR (2022). Bayesian adaptive and interpretable functional regression for exposure profiles. Retrieved from https://arxiv.org/abs/2203.00784 (arXiv:1903.04697)
- Geldhof GJ, Anthony KP, Selig JP, & Mendez-Luck CA (2017). Accommodating binary and count variables in mediation. International Journal of Behavioral Development, 42, 300–308. [Google Scholar]
- Gelman A, & Vehtari A (2021). What are the most important statistical ideas of the past 50 years? Journal of the American Statistical Association, 116(536), 2087–2097. [Google Scholar]
- Goldsmith J, Bobb J, Crainiceanu CM, Caffo B, & Reich D (2011). Penalized functional regression. Journal of Computational and Graphical Statistics, 20, 830–851. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Goldsmith J, Scheipl F, Huang L, Wrobel J, Di C, Gellar J, . . . Staicu A-M. (2020). refund R package (regression with functional data) [Computer software manual]. Retrieved from https://cran.r-project.org/web/packages/refund/refund.pdf
- Green MJ, & Popham F (2016, 12). Life course models: improving interpretation by consideration of total effects. International Journal of Epidemiology, 46(3), 1057–1062. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Hastie T, & Tibshirani R (1993). Varying-coefficient models. Journal of the Royal Statistical Society, B, 55, 757–796. [Google Scholar]
- Hernán MA, & Robins JM (2020). Causal inference: What if. Boca Raton: Chapman & Hall/CRC. [Google Scholar]
- Huang J, & Yuan Y (2017). Bayesian dynamic mediation analysis. Psychological Methods, 22, 667–686. [DOI] [PubMed] [Google Scholar]
- Imai K, Keele L, & Yamamoto T (2010). Identification, inference and sensitivity analysis for causal mediation effects. Statistical Science, 25, 51–71. doi: [Google Scholar]
- Kim K, Şentürk D, & Li R (2011). Recent history of functional linear models for sparse longitudinal data. Journal of Statistical Planning and Inference, 141(4), 1554–1566. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Le Foll B, Piper ME, Fowler CD, Tonstad S, Bierut L, Lu L, . . . Hall WD. (2022). Tobacco and nicotine use. Nature Reviews Disease, 8(Primers 19). [DOI] [PubMed] [Google Scholar]
- Lee KJ, Roberts G, Doyle LW, Anderson PJ, & Carlin JB (2016). Multiple imputation for missing data in a longitudinal cohort study: a tutorial based on a detailed case study involving imputation of missing outcome data. International Journal of Social Research Methodology, 19, 575–591. [Google Scholar]
- Liang K-Y, & Zeger SL (1986). Longitudinal data analysis using generalized linear models. Biometrika, 73(1), 13–22. [Google Scholar]
- Lindquist MA (2012). Functional causal mediation analysis with an application to brain connectivity. Journal of the American Statistical Association, 107, 1297–1309. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Lindquist MA, & McKeague IW (2009). Logistic regression with Brownian-like predictors. Journal of the American Statistical Association, 104, 1575–1585. [Google Scholar]
- Liu K, Saarela O, Feldman BM, & Pullenayegum E (2020). Estimation of causal effects with repeatedly measured outcomes in a bayesian framework. Statistical Methods in Medical Research, 0962280219900362. [DOI] [PubMed] [Google Scholar]
- Liu X (2014). Joint modeling of longitudinal and survival data: new models, computing techniques and applications (Doctoral dissertation, Penn State). Retrieved from https://etda.libraries.psu.edu/catalog/23528 [Google Scholar]
- Loh WW, Moerkerke B, Loeys T, Poppe L, Crombez G, & Vansteelandt S (2020). Estimation of controlled direct effects in longitudinal mediation analyses with latent variables in randomized studies. Multivariate Behavioral Research, 55(5), 763–785. [DOI] [PubMed] [Google Scholar]
- Lok JJ, & Bosch RJ (2020). Causal organic indirect and direct effects: closer to Baron and Kenny, with a product method for binary mediators. (arXiv:1903.04697) [DOI] [PMC free article] [PubMed] [Google Scholar]
- MacKinnon DP (2008). Introduction to statistical mediation analysis. Routledge. [Google Scholar]
- Magidson JF, Blashill AJ, Safren SA, & Wagner GJ (2015). Depressive symptoms, lifestyle structure, and ART adherence among HIV-infected individuals: a longitudinal mediation analysis. AIDS and Behavior, 19, 34–40. doi: [DOI] [PMC free article] [PubMed] [Google Scholar]
- Maxwell SE, Cole DA, & Mitchell MA (2011). Bias in cross-sectional analyses of longitudinal mediation: Partial and complete mediation under an autoregressive model. Multivariate Behavioral Research, 46(5), 816–841. [DOI] [PubMed] [Google Scholar]
- Miočević M, Gonzalez O, Valente MJ, & MacKinnon DP (2018). A tutorial in bayesian potential outcomes mediation analysis. Structural Equation Modeling, 25, 121–136. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Moreno-Betancur M, & Carlin JB (2018). Understanding interventional effects: A more natural approach to mediation analysis? Epidemiology, 29(5), 614–617. [DOI] [PubMed] [Google Scholar]
- Nguyen TQ, Schmid I, & Stuart EA (2021). Clarifying causal mediation analysis for the applied researcher: Defining effects based on what we want to learn. Psychological Methods, 26(2), 255–271. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Park S, Steiner PM, & Kaplan D (2018). Identification and sensitivity analysis for average causal mediation effects with time-varying treatments and mediators: Investigating the underlying mechanisms of kindergarten retention policy. Psychometrika, 83(2), 298–320. [DOI] [PubMed] [Google Scholar]
- Pinto Pereira SM, De Stavola BL, Rogers NT, Hardy R, Cooper R, & Power C (2020). Adult obesity and mid-life physical functioning in two british birth cohorts: investigating the mediating role of physical inactivity. International Journal of Epidemiology, 49, 845–856. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Qian T, Yoo H, Klasnja P, Almirall D, & Murphy SA (2019). Estimating time-varying causal excursion effect in mobile health with binary outcomes. (arXiv:1906.00528) [DOI] [PMC free article] [PubMed] [Google Scholar]
- R Core Team. (2020). R: A language and environment for statistical computing [Computer software manual]. Vienna, Austria. Retrieved from https://www.R-project.org/ [Google Scholar]
- Ramsay JO, & Silverman BW (2005). Functional data analysis (2nd ed.). New York: Springer. [Google Scholar]
- Rijnhart JJM, Twisk JW, Chinapaw MJM, de Boer MR, & Heymans MW (2017). Comparison of methods for the analysis of relatively simple mediation models. Contemporary Clinical Trials Communications, 7, 130–135. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Rijnhart JJM, Twisk JWR, Eekhout I, & Heymans MW (2019). Comparison of logistic-regression based methods for simple mediation analysis with a dichotomous outcome variable. BMC Medical Research Methodology, 19. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Rijnhart JJM, Valente MJ, MacKinnon DP, Twisk JWR, & Heymans MW (2021). The use of traditional and causal estimators for mediation models with a binary outcome and exposure-mediator interaction. Structural Equation Modeling: A Multidisciplinary Journal, 345–355. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Robins JM (2003). Semantics of causal DAG models and the identification of direct and indirect effects. Highly Structured Stochastic Systems, 70–81. [Google Scholar]
- Rubin D (1980). Randomization analysis of experimental data: The Fisher randomization test (comment). Journal of the American Statistical Association, 75, 591–593. [Google Scholar]
- Schafer JL, & Graham JW (2002). Missing data: our view of the state of the art. Psychological Methods, 7, 147–77. [PubMed] [Google Scholar]
- Shiffman S, Stone AA, & Hufford MR (2008). Ecological momentary assessment. Annual Review of Clinical Psychology, 4, 1–32. [DOI] [PubMed] [Google Scholar]
- Sullivan AJ, Gunzler DD, Morris N, & VanderWeele TJ (2021). Longitudinal mediation analysis with latent growth curves. (arXiv:2103.05765) [Google Scholar]
- Tan X, Shiyko MP, Li R, Li Y, & Dierker L (2012). A time-varying effect model for intensive longitudinal data. Psychological Methods, 17, 61–77. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Vafaie N, & Kober H (2022, 06.). Association of Drug Cues and Craving With Drug Use and Relapse: A Systematic Review and Meta-analysis. JAMA Psychiatry. Retrieved from 10.1001/jamapsychiatry.2022.1240 doi: [DOI] [PMC free article] [PubMed] [Google Scholar]
- VanderWeele TJ (2015). Explanation in causal inference: Methods for mediation and interaction. New York: Oxford University Press. [Google Scholar]
- VanderWeele TJ, & Tchetgen Tchetgen EJ (2017). Mediation analysis with time varying exposures and mediators. J. R. Statist. Soc. B, 79, 917–938. [DOI] [PMC free article] [PubMed] [Google Scholar]
- VanderWeele TJ, & Vansteelandt S (2009). Conceptual issues concerning mediation, interventions, and composition. Statistics and Its Interface, 2, 457–468. [Google Scholar]
- VanderWeele TJ, & Vansteelandt S (2010). Odds ratios for mediation analysis for a dichotomous outcome. American Journal of Epidemiology, 172(12), 1339–1348. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Vansteelandt S, & Daniel RM (2017). Interventional effects for mediation analysis with multiple mediators. Epidemiology, 28, 258–265. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Vansteelandt S, Linder M, Vandenberghe S, Steen J, & Madsen J (2019). Mediation of time-to-event endpoints accounting for repeatedly measured mediators subject to time-varying confounding. Statistics in Medicine, 38, 4828–4840. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Wang W, Nelson S, & Albert JM (2013). Estimation of causal mediation effects for a dichotomous outcome in multiple-mediator models using the mediation formula. Statistics in Medicine, 32, 4211–4228. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Wood SN (2003). Thin plate regression splines. Journal of the Royal Statistical Society, B, 65, 95–114. [Google Scholar]
- Wood SN (2017). Generalized additive models: An introduction with R (2nd edition). New York: Chapman and Hall/CRC. [Google Scholar]
- Wood SN (2021). mgcv R package (Mixed GAM Computation Vehicle with Automatic Smoothness Estimation) [Computer software manual]. Retrieved from https://cran.r-project.org/web/packages/mgcv/index.html
- Zeng S, Rosenbaum S, Archie E, Alberts S, & Li F (2021). Causal mediation analysis for sparse and irregular longitudinal data. (arXiv:2007.01796) [Google Scholar]
- Zhao Y, Lindquist MA, & Caffo BS (2020). Sparse principal component based high-dimensional mediation analysis. Computational Statistics and Data Analysis, 142, 106835. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Zhao Y, Luo X, Lindquist M, & Caffo B (2018). Functional mediation analysis with an application to functional magnetic resonance imaging data. [Google Scholar]
- Zheng W, & van der Laan M (2017). Longitudinal mediation analysis with time-varying mediators and exposures, with application to survival outcomes. J Causal Inference, 5(2). [DOI] [PMC free article] [PubMed] [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
