{'fraction_non_alphanumeric': 0.04119483666526865, 'fraction_numerical': 0.014096649424483899, 'mean_word_length': 4.1916051772105964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Path Analysis for Binary Random Variables

The decomposition of the overall effect of a treatment into direct and indirect effects is here investigated with reference to a recursive system of binary random variables. We show how, for the single mediator context, the marginal effect measured on the log odds scale can be written as the sum of the indirect and direct effects plus a residual term that vanishes under some specific conditions. We then extend our definitions to situations involving multiple mediators and address research questions concerning the decomposition of the total effect when some mediators on the pathway from the treatment to the outcome are marginalized over. Connections to the counterfactual definitions of the effects are also made. Data coming from an encouragement design on students' attitude to visit museums in Florence, Italy, are reanalyzed. The estimates of the defined quantities are reported together with their standard errors to compute p-values and form confidence intervals.


Introduction
The decomposition of the total effect of a treatment X on an outcome variable Y into direct and indirect effects is a central topic in empirical research. In linear models, the relationship between total, direct and indirect effects is well understood (Cochran 1938;Alwin and Hauser 1975; Baron and Kenny 1986;Bollen 1987) and a simple decomposition is available. Such a decomposition is based on the linearity of the marginal model for Y against X, where the coefficient of X is equal to the sum of the direct effect and the indirect effects. Outside the linear case, this simplicity is lost, as in the marginal model of Y against X only, either the effect of X on Y is a complex function of the original parameters or the error term does not possess nice properties, or both.
We here consider situations where the outcome Y is a binary random variable. Contributions have addressed the case of one continuous mediator, see for example MacKinnon et al. (2007); Karlson, Holm, and Breen (2012) ;Holm (2013, 2018). Recent results concern the exact parametric form of the marginal effect of X on Y on the log odds ratio scale when the mediator is also binary (Stanghellini and Doretti 2019). In this setting, when X is continuous the marginal model of Y against X is non-linear unless some conditional independence assumptions hold, and a rather complex formula links the marginal and conditional effect of X on Y. Similarly, for a discrete X the parameters of the conditional model combine in a non-linear fashion to form the marginal effect. For analogous results on the log relative risk scale see Lupparelli (2019).
Starting from the results in Stanghellini and Doretti (2019), we here elaborate a novel proposal for the direct and indirect effect definitions on the log odds scale for a treatment variable X either continuous or discrete. The postulated system can be represented by a Directed Acyclic Graph (DAG), see Lauritzen (1996, Ch. 2), to which we refer for definitions; see also Elwert (2013) for an account in the sociological context. Our proposal is based on zeroing the path-specific regression coefficients. Graphically, this corresponds to deleting one arrow in the associated DAG and thereby represents the analogue of the path analysis method.
We initially focus on a single mediator context and show that the marginal effect can be written as the sum of the indirect and direct effects plus a residual term that vanishes under some specific conditions. The proposed parametric relationship allows, for the specific setting under investigation, to solve the debate on which method should be used to disentangle the total effect, i.e., the product method or the difference method (Breen et al. 2018). It also avoids fitting two nested models, thereby sidestepping the issue of unequal variance (Winship and Mare 1983). We then extend our derivations to the case of multiple binary mediators, also modeled as a recursive system of univariate logistic regressions. In this context, additional path-specific effects can be defined and different research questions addressed. Although the paper draws from the derivation in Stanghellini and Doretti (2019), some novel results are also presented. With reference to a single mediator, a general formulation of functional form linking the log odds ratio of the mediator and of the outcome to the covariates is considered. This is then extended to the multiple mediator context, for which a strategy for deriving the direct and indirect effects when marginalizing over an intermediate or outer mediator is also illustrated.
Our approach is developed in a purely associational context that, in general, holds no interpretation for causal inference. However, if the recursive system of equation is structural (Pearl 2009, Ch. 7) and no unmeasured confounders exist, the total effect and some of its components can be endowed with a causal interpretation. Notice that a decomposition of the total effect based on counterfactual entities has been given by Pearl (2001Pearl ( , 2012 and extended to the odds ratio scale by VanderWeele and Vansteelandt (2010). This parallelism is also addressed in this paper.
In Section 2, we offer the general theory for the case of a single mediator. A case study concerning a randomized encouragement experiment on cultural consumption performed in Florence (Italy) is also presented as a guiding example. Results of a simulation study investigating maximum likelihood (ML) estimation of the effects and other related measures is also reported in Section 3, while the extension to the multiple mediator setting is contained in Section 4. In Section 5, we address other complex issues concerning path-specific effects, whereas links with counterfactual definitions are explored in Section 6. Finally, in Section 7 we draw some conclusions.

Effect decomposition with a single mediator
We first focus on a very simple model for a binary outcome Y, a binary mediator W and a treatment X, that can be either discrete or continuous; see Fig 1(a) for the corresponding DAG. Our aim is to decompose the total effect of X on Y on the log odds scale. Our postulated models are a logistic regression for Y given X and W and for W given X, that is, and Notice that we allow for the interaction between X and W in the outcome equation. In order to make the paper self-contained, the derivations in Stanghellini and Doretti (2019) to evaluate the total effect as a function of the parameters of models (1) and (2) are here reproduced, prior the introduction of its decomposition into direct, indirect and residual effects.
As a guiding example through this section, we consider an experiment aiming at identifying the best incentives to offer high school students in Florence to enhance cultural interest and increase art museum attendance. Three treatment levels are considered: a flyer given to the students with the main information about the Palazzo Vecchio museum constitutes the first level; a flyer and a presentation of the museum from an expert constitutes the second level; a flyer, the presentation and a reward in the form of extra-credit points for their final school grade constitutes the third level. All students receive a free entry ticket to Palazzo Vecchio. The aim of the experiment is not only to assess the total effect of the treatment (X) on students museum's attendance (Y), but also to understand to what extent this effect could be stimulated by student's visit to Palazzo Vecchio (W); see Lattarulo, Mariani, and Razzolini (2017) and Forastiere et al. (2019).
The interest is in the marginal model of Y against X, as a function of the parameters in (1) and (2). From first principles of probabilities, it follows that: The second term of the right hand side (rhs) of the above equality is given from model (1), while the parametric expression of the first term is not immediately derived from models (1) and (2), as it involves the probability of W after conditioning on X and Y (not after conditioning on X only).
However, by repeated use of the previous relationship, we have: Using (1) and (2), after some simplifications, we find: In what follows we denote with g y (x) the log P(W=1|Y=y,X=x) P(W=0|Y=y,X=x) , i.e.
Since (1 + exp g y (x)) −1 corresponds to P(W = 0 | Y = y, X = x), substituting in (3) for w = 0, we find: Denoting with Analogously, lettingW = 1 − W, then It then follows that (6) can be rewritten as or, alternatively, as Notice that conditioning on a set of covariates C = (C 1 , . . . C p ) does not strongly alter the structure of (6) and (8). We here offer an example for p = 1, with both additive and interaction effects up to the second order in both models for Y and W. After the marginalization over W, we obtain the marginal model for Y given X and C as: with See Appendix A for a general formulation that includes more covariates and possibly nonlinear link functions. 1  48 17  2  14 21  2  14 28  3  3  3  3 23 21  Ignoring for now the sampling errors, we see that the g y (x, c) function can be formed by plugging in (10) the ML estimates of the parameters. The function expresses the log odds ratio of W after conditioning on X, Y and the covariate C.
We now present a definition for the total, direct and indirect effects in the situation with no covariates. When covariates C are present, the parametric formula of TE(x) and its decomposition, for both continuous and discrete X, vary with the level of C. Notice that the direct and indirect effects so defined do not sum to the total effect, but a residual term remains. This term is zero only under some specific conditions, that we are going to discuss.
Total Effect Let TE(x) be the effect of X on Y, on the log odds scale, in the distribution of (Y | X) obtained after marginalization on W. For X continuous and differentiable, the total effect is defined  as the derivative of (6) with respect to x. For X discrete, the total effect is defined as the difference between (6) evaluated at two different levels of X.
Indirect Effect Let IE(x) be the indirect effect of X on Y on the log odds scale. The indirect effect is defined as the part of the total effect of X on Y through W only. It is evaluated after imposing, in the total effect, the coefficients of X in the model for Y equal to zero, i.e. β x = β xw = 0, i.e.
Direct Effect Let DE(x) be the direct effect of X on Y on the log odds scale. The direct effect is defined as the part of the total effect due to X only. It is obtained after imposing, in the total effect, the coefficients of W in the model for Y equal to zero, i.e. β w = β xw = 0 so that W ⊥ ⊥ Y | X (see Fig. 1(c)). In other words, we have DE(x) = TE(x) | β w =β xw =0 . This definition is aligned with the collapsibility of odds ratio, as explained by Xie, Ma, and Geng (2008), Corollary 3. It is important to notice that the direct effect can also be seen as the effect of X on Y keeping W = 0.
Residual Effect Let RES(x) be the residual effect of X on Y on the log odds scale defined as Notice that this residual term is always null in linear models. In this context, the total effect can be decomposed into the sum of the direct and indirect effect. Provided that these two are positive, it is therefore meaningful to look at the ratio between the indirect effect and the total effect, as it gives an indication of the proportion of total effect due to the mediator W (i.e., the proportion mediated). When a residual effect is present, the ratio between the indirect and total effect can still provide information on the weight of the indirect effect on the total effect, though with a less clear interpretation (see Sections 2.1 and 2.2).
In what follows, we study in detail the decomposition of the total effect for the simple case without covariates, where X can be either continuous or discrete. Addition of covariates can be done in a straightforward manner.

Continuous case
We first look at the case of X continuous and differentiable. Let It is possible to show that where with g y (x) as in (5). Eq. (12) confirms the well-known fact that the marginal logistic model is non linear in x, also providing the explicit expression of it. Notice that, as shown in Stanghellini and Doretti (2019), all terms in curly bracket are bounded between 0 and 1, while ∆ w (x) is bounded between -1 and 1. Notice further that ∆ w (x) and ∆ y (x) share the same sign, and they are both zero whenever Indirect Effect Following the definition, we evaluate the total effect assuming β on the value of x, and is null if either γ x or β w are zero. It can be shown that, for all x, ∆ * w (x) and β w share the same sign and, therefore, the indirect effect is concordant with the γ x β w product; see Appendix B. However, the magnitude of the effect varies with x.
Direct Effect Following the definition, we evaluate the direct effect after assuming β w = β xw = 0, that is Notice that (14) follows as ∆ y (x) and ∆ w (x) are zero when β w = β xw = 0.
Residual Effect Finally, the residual effect is given by difference as follows It is therefore apparent that the effect above vanishes whenever β x = β xw = 0 or β w = β xw = 0.
As a matter of fact, in the former case we have ∆ w (x) = ∆ * w (x), whereas in the latter case ∆ w (x) = ∆ y (x) = 0. Notice that the latter case coincides with the condition of collapsibility of odds ratio, see Xie et al. (2008), Corollary 3. Since all terms in curly brackets are bounded, expression (15) also highlights that the sign of the residual effect depends on the relative magnitude of the coefficients and is not linked to the logistic regression coefficients in a clear way. As a matter of fact, even if the direct and indirect effects share the same sign, the sign of the residual effect may be either positive or negative. Thus, as mentioned in Section 2, for a fixed level of x, the ratio between the indirect effect and the total effect may provide an indication of the relative strength of the indirect effect, though with a less clear interpretation.
Some cases of interest Reformulating the total effect by definition as in (11), we study in detail the decomposition of the total effect into indirect (13), direct (14) and residual (15) effects for some cases of interest.
Case i) When the recursive logistic models can be depicted as in Fig. 1 follows from the definition above that and both DE(x) and RES(x) are zero.
Case ii) When the recursive logistic models can be depicted as in Fig. 1 follows from the definition above that and both IE(x) and RES(x) are zero.
Case iii) A noticeable situation arises after imposing β xw = 0. In this case, the total effect is Notice that this assumption does not itself reflect into any conditional independence. If we further assume γ x = 0 then some simplifications arise. Thus It is possible to see that under this condition |TE(x)| ≤ |β x |, in line with results obtained by Neuhaus and Jewell (1993) in a more general context.
Case iv) When the recursive logistic models can be depicted as in Fig. 1(d), i.e. W ⊥ ⊥ X, it follows from the definition above that In this case, there is an effect modification due to conditioning of an additional variable, in line with well-known results on non-collapsibility of parameters of logistic regression models, see Xie et al. (2008). In addition, we notice that even in this simple case the linearity of X in the marginal model is lost. Furthermore, if β x and β xw are both positive (negative), the marginal effect is also positive (negative), thereby recovering the finding in Cox and Wermuth (2003) on the condition to avoid the effect reversal (i.e., the marginal and conditional effects having opposite signs).

Discrete case
Without loss of generality, we here assume that X is binary. The total effect of X on Y can be derived by taking the first difference of, equivalently, (7) or (8). We here opt for differentiating (7).
which explicitly becomes with g y (x) as in (5). Notice that, in order to make the extension to X discrete straightforward, we maintain the x notation. Obviously, in the case of a binary X, TE(x) = cpr(Y, X), a constant term corresponding to the cross product ratio of the marginal table for Y and X.
Indirect Effect Following the definition above, we evaluate the total effect assuming β (5). In parallel with the continuous case, the indirect effect is null if either β w or γ x are zero. It can be shown with some algebra that it is concordant with the product of the two coefficients.
Direct Effect Following the definition of the direct effect, we evaluate the direct effect after assuming in the total effect β w = β xw = 0, that is Residual Effect By definition, the remaining effect is evaluated by difference, such as with g * y (x) as above. It can easily be seen that RES(x) is zero as soon as β x = β xw = 0, leading to g * y (1) = g y (1), or β w = β xw = 0, leading to g 1 (x) = g 0 (x) and g * 1 (x) = g * 0 (x), see (5). The latter situation coincides with the condition of collapsibility of odds ratio, see Xie et al. (2008), Corollary 3. However, like in the continuous case, there is no clear relationship between the sign of this effect and the logistic regression coefficients.
Some cases of interest Following the definition, we reformulate the total effect of a binary X on a binary Y as in (11) and we study in detail the decomposition of the total effect into the indirect (17), direct (18) and residual (19) effects for some cases of interest.
Case i) When the recursive logistic models can be depicted as in Fig. 1 follows from the definition above that and both DE(x) and RES(x) are zero.
Case ii) When the recursive logistic models can be depicted as in Fig. 1(c follows from the definition above that as all other terms are zero. Case iii) After imposing β xw = 0 the total effect is .
Notice that g * y (x) is g y (x) evaluated at β x = β xw = 0. If we further assume γ x = 0, after some algebra, it is possible to show that under this condition |TE(x)| ≤ |β x | in line with results obtained  by Neuhaus and Jewell (1993).
Case iv) When the recursive logistic models can be depicted as in Fig. 1(d), i.e. W ⊥ ⊥ X, it follows from the case above After some algebra, it is possible to show that this condition is sufficient to avoid effect reversal, as proved by Cox and Wermuth (2003) in a more general context.
With reference to the cultural consumption data, in Table 3 the decomposition of the total effect of moving from level 1 to the other levels of X is reported. Notice that this decomposition is based on the estimated parameters of Table 2, and does not require to estimate the marginal model of Y against X and C only, thereby avoiding the issue of comparing parameters coming from two logistic models with unequal variance. 95% confidence intervals and p-values are calculated using the approximated standard errors evaluated via the delta method (Oehlert 1992).
In the upper part of Table 3, the decomposition for the {2, 1} contrast is reported. For both levels of C, the total and direct effects are positive and statistically significant, while the indirect effect, also positive, is moderately significant in C = 0 (p-value 0.057) and non significant for C = 1 (pvalue 0.205). As for the {3, 1} contrast, in the lower part of Table 3, we see instead that all the direct, indirect and total effects are positive and statistically significant for both C = 0 and C = 1 (though the indirect effect for C = 1 is only moderately significant). Although, for each contrast, the total, direct and indirect effects are all positive, their interpretation in terms of proportion mediated is not possible given the presence of a negative residual effect; see Section 2. Such an effect is rather large in magnitude, possibly due to a large interaction coefficient; see Table 2.
In summary, the direct and total effects of moving from level 1 to level 2 of X are positive and statistically significant in all groups of students, while the indirect effect, also positive, is significant only for students mainly interested in humanities. When moving from level 1 to level 3 of X all effects are positive and significant. We believe that this is an important message on how to design incentives to increase museums attendance of high school students, that cannot be easily derived by simply looking at the estimated coefficients in Table 2. Our

Effect decomposition on the probability scale
So far, we have considered effect decompositions operating on the logistic scale. However, sociologists and econometricians are quite often concerned with effects on the probability scale (also called partial effects; see Wooldridge 2010, Cap. 15), for which effect decompositions in specific contexts, typically on the additive scale, have also been proposed (Karlson et al., 2012;Breen et al., 2013). We here denote with η(x) the rhs of (6), that is, For the continuous X case, effects are defined as derivatives w.r. to x of the probability function.
The Total Probability Effect (TPE(x)) is therefore so defined: where TE(x) corresponds to the total effect on the logistic scale as defined in (12). The result follows from the derivative of expit η(x) = exp η(x)/{1 + exp η(x)} with respect to its argument η(x).
On the other hand, for X binary or discrete, the total effect on the probability scale can be defined by simply taking the difference across levels of X of the marginal probability. For the binary X this becomes: In analogy with the approach of Section 2, the Direct Probability Effect (DPE(x)) and Indirect Probability Effect (IPE(x)) are defined by zeroing the corresponding coefficients in TPE(x). To obtain an additive decomposition, we also define the Residual Probability Effect (RPE(x)) by difference as With particular reference to the continuous case, this amounts to: where IE(x) is as in Eq. (13)  For the cultural consumption data, the effects on the probability scale are summarized in Table 4, which has the same structure of Table 3. As expected, results are in line with the ones on the log odds scale. Notice that averaging the effects may be not appropriate in applications with a strong variation across levels of x, as in this case, especially with reference to the indirect effects.

Simulation study
In this section, we present results of a simulation study to investigate how well the relative amount of indirect effect is recovered, also in relation with already existing methods. In particular, Karlson et al. (2012) and Breen et al. (2013) derive a decomposition of the total effect that can be applied to the case of a continuous mediator W, when the response model for Y can either be a logistic or a probit one with no interaction terms. In this context, the total effect, as measured by the marginal coeffi-  cient of X on Y, is the sum of the direct and indirect effects, as in linear models. When all effects are positive, it is therefore meaningful to compute the proportion mediated as the ratio between the indirect and total effect; see Eq. (21) in Breen et al. (2013). The authors present a method to sidestep the well-known issue of unequal variances, known as KHB method. They also propose to adapt it to the binary mediator case, by postulating a linear probability model for W.
We here postulate a logistic model for W and analyze, through simulations, the behaviour in finite samples of the KHB method and of the proposed method. For X binary, we compare the KHB method with the ratio between the estimates of the effects IE(x) and TE(x) in Section 2, obtained by plugging-in the ML estimates of the parameters in the corresponding expression. For X continuous, we notice that the KHB measure should be interpreted as the proportion mediated on the probability scale in the same fashion as discussed in Section 2.3. For this reason, we proceed as follows. Given a sample of n units, an estimate of the corresponding effect is formed by averaging across units the corresponding entities. As an instance, the estimated Average Total Probability Effect (ATPE) is so formed: where TPE(x i ) is the estimated total probability effect of unit i, obtained by plugging-in the ML estimates in the corresponding expression. The estimated Average Indirect Probability Effect (AIPE) is formed accordingly and the ratio between the two entities is then taken. We recall from Section 2 that, due to the presence of the residual effect, this measure should not be interpreted as proportion mediated in the usual way. The above measure is then compared with the KHB measure.
We consider a basic setting with no covariates, where the outcome Y and the mediator W are generated according to Equations (1) and (2) respectively. Though our method can accommodate for the treatment-mediator interaction β xw in the outcome equation, for a fair comparison it is here posed to zero. The remaining parameters are set to: β 0 = −2 = γ 0 and β w = 2 = γ x , while β x is varying in {0.4, 0.9, 1.8} in order to explore different relative amounts of indirect effect.
We define three sample sizes, i.e., n ∈ {250, 500, 1000}. In the binary treatment case, the X variate is sampled from a Bernoulli distribution with probability equal to 0.5. In the continuous treatment case, we first generate a large pseudo-population of size N pop = 150000 from a Normal distribution with null mean and variance equal to 2 and then create X by extracting a random sample of size n from it. In this way, the true value of the AIPE/ATPE ratio is computed on the pseudo-population and does not vary with the sample size. Once X is obtained, for each n, N = 2000 replications of (W, Y) are drawn and estimation is performed.

Extension to multiple binary mediators
The proposed definitions of direct, indirect and residual effects, together with their parametric formulations, extend nicely to the situation where multiple binary mediators are present. Suppose there are k mediators and that a full ordering among the variables (Y, W 1 , W k−1 , . . . , W k , X) is available such that each variable is a potential response variable for the subsequent ones. The system can be represented via a DAG, see Figure 2. We assume that each response model is a hierarchical logistic model. In the following, if we impose the regression coefficient of one covariate to be zero, all higher order interaction terms involving this covariate are implicitly imposed to zero. For brevity, we denote with W > j , the set of all W r such that r > j. The coefficients of X and of W j and of their interactions in the logistic regression of Y are denoted with β, in a self-explaining fashion.
In analogy with (7), the logistic model for Y given X, obtained after marginalization upon the k mediators, is .
In Appendix C the relevant expressions are given.
In line with what done for the simple case, we here offer a generalization of the definitions for the total, direct, indirect and residual effects under the situation of k mediators.
Total Effect Let TE(x) be the total effect of X on Y on the log odds scale, after marginalization on k binary mediators. For X continuous and differentiable, the total effect is defined as the derivative of (21) with respect to x. It follows that For X discrete, the total effect is defined as the difference between (21) evaluated at two different levels of X. Without loss of generality, we here assume X binary, and take the difference for x = 1 and x = 0. Then Equation (23) can also be written as follows . Direct Effect Let DE(x) be the direct effect of X on Y on the log odds scale. Letβ W be the set of all β regression coefficients of each mediator in the model for Y, including also the interaction terms both between mediators and between mediators and X. The direct effect is evaluated in TE(x) after Global Indirect Effect The global indirect effect GIE(x) can be defined in analogy with the previous definitions, as the total effect evaluated when the direct effect of X, β x , is zero. Since we only deal with hierarchical models, this implies that all interaction terms between X and the mediators are also zero. Therefore, Residual Effect Let RES(x) be the residual effect evaluated by difference, i.e., From previous derivations, non-zero residual effects are induced by graphs having more than one arrow pointing to Y. Therefore, we can state that the residual effect is zero whenever one of the two following graphical conditions holds: (i) there is no direct path from X to Y or (ii) there is the direct path from X to Y and no other arrow is pointing to Y. As an instance, the model corresponding to the DAG in Fig. 3(a) has a non-zero RES(x) as there is a direct arrow form X to Y and other two arrows are pointing to Y, while models corresponding to DAGs as in Figs. 3(b) and 3(c) are such that TE(x) = GIE(x) and RES(x) = 0.
In a setting with multiple mediators, one is also interested in a path-specific indirect effect, i.e.
the effect that is due to some mediators only, and is null whenever one arrow along the pathway is deleted. Notice that, in this setting, also other research questions are of interest, such as the path-specific indirect effects when some mediators are marginalized over. They are addressed in Section 5.
Path-Specific Indirect Effect Let A be one of the 2 k−1 ordered subsets of (W 1 , W 2 , . . . , W k ) containing at least one element of W. Let i A be the ordered set of indices j such that W j ∈ A. The path-specific indirect effect PSIE A (x) is obtained from the total effect after imposing that: • β x = 0; • β w j = 0 with j = {1, 2, . . . , k}, j min{i A } the smallest index in i A ; • γ r, j = 0 with W r ∈ A, j > r, j ℓ r , where ℓ r is the index following r in i A ; • γ r,x = 0 with W r ∈ A, r max{i A } the largest index in i A .
In this way, each path-specific indirect effect contains only the parameters pertaining to the path Figure 4: DAG with W 1 acting as a collider node in the path (including the intercepts). It then follows that the indirect effect PSIE A (x) is null whenever one of the following conditions holds: Notice that each of the conditions above implies deleting one arrow in the DAG corresponding to the model of interest.
Notice that the definition of path-specific indirect effects allows only for direction preserving paths, i.e. paths with all arrows pointing to the same direction. As a matter of fact, only ordered subsets of W are allowed to form A. This choice is justified by the fact that these are the only subsets with a non-zero path-specific indirect effect. To clarify the issue, see the graph in Fig. 4.
The path X → W 3 → W 1 ← W 2 → Y is not admitted as it gives rise to (W 3 , W 1 , W 2 ), not an ordered subset of W. However, as W 1 is a collider node the path between X and Y is blocked by (W 3 , W 1 , W 2 ) and the corresponding path-specific effect is zero, see Pearl (2009, Chs . 1 and 3).
It is also important to notice that, in parallel to the single-mediator case, DE(x) coincides with the effect of X on Y keeping W 1 = W 2 = . . . = W k = 0. However, PSIE A (x) does not in general coincide with the indirect effect after keeping the mediators not in A equal to zero. To see this, notice that in Fig. 4 the path-specific indirect effect for A = (W 3 , W 2 ) is evaluated after imposing that β x = β w 1 = 0. This effect does not coincide with the one obtained after conditioning on W 1 = 0, see Elwert and Winship (2014).
Notice that the sum of all the path-specific indirect effects in general is not equal to the global indirect effect. This is true even when there is just one path from X to Y. This is due to the different ways to deal with the effects induced in non-collapsible subgraphs. These are subgraphs involving three random variables, (W i , W j , W r ), or (W i , W j , Y), i > j > r, such that there are two arrows pointing to the inner node, i.e. W r or Y. In this case W j acts as a mediator between W i and W r , or Y, and there is a non-zero residual effect; see Section 2. Specifically, the global indirect effect includes all residual effects, whereas path-specific indirect effects do not.
As an example, consider the models with DAG as in Figures 5(a) and 5(b). In both DAGs there is just one indirect path leading from X to Y, i.e. X → W 3 → W 1 → Y, with A = (W 3 , W 1 ).
Both models have GIE(x) PSIE A (x). The model corresponding to Figures 5 (a) has two noncollapsible subgraphs, namely the ones induced by (W 3 , W 2 , W 1 ) and (W 2 , W 1 , Y), while the model corresponding to Figure 5 (b) has one non-collapsible subgraph, namely the one induced by Notice the different meaning of the parameters attached to the arrow W 3 → W 1 in the two effects: in the GIE(x) it is the total effect of W 3 on W 1 , while in the path-specific PSIE A (x) it is the direct effect. We here present an instance of both situations.

Other path-specific indirect effects of interest
Suppose that the research question involves investigation of the path-specific indirect effects in the model obtained after marginalization over W 1 of a model corresponding to the DAG in Figure 6(a). In Figure 6(b), the DAG corresponding to the marginal model of interest is presented, with the red arrows corresponding to parameters that change due to the marginalization over W 1 .
The expressions for these parameters is reported in Appendix D. The only non-zero path-specific indirect effects are for A = {W 2 } and A = {W 3 }. They can be evaluated by making use of the Figure 6: (a) Marginalization over the inner mediator W 1 and (b) quantifying the parameters (in red the parameters that change). Figure 7: (a) Marginalization over the outer mediator W 2 and (b) quantifying the parameters (in red the parameters that change).
parameters of the marginal model. Notice that, as expected, the GIE(x) in the marginal model is equal to the GIE(x) in the original model.

Quantification of effects in models obtained after marginalization over intermediate or outer
nodes involves repeated use of the derivations here presented. We here detail the steps to be followed for the case with k = 2 mediators. Generalizations to more complex models can be derived after repeatedly applying the procedure here proposed.
Suppose that we wish to evaluate the indirect effect in the model with W 1 as unique mediator, i.e. the model obtained after marginalization over W 2 , see Figure 7. This implies deriving the parametric formulation of in which the second term of the right hand side of the equation is to be determined. From repeated use of the derivations in Appendix A, we have with the expression of h y,w 1 in Appendix E. The values of the marginal parameters are straightforward; see e.g. Appendix D.

Causal interpretation of total, direct and indirect effects
In the counterfactual framework, many approaches exist to mediation analysis, and a review is in Huber (2019). In a single mediator context, VanderWeele and Vansteelandt (2010) define the counterfactual notion of direct and indirect effects when the outcome is binary, thereby focusing on the log odds scale. Within a regression analysis context with a continuous mediator, the authors present an approximated parametric formulation of the effects that holds under the rare outcome assumption of Y. Valeri and VanderWeele (2013) address the same problem when also the mediator is binary, again modeled under the rare outcome assumption. It is therefore worth to explore the links existing between the effects introduced here and these causal effects defined in a formal counterfactual framework. Since the latter are contrasts expressed, possibly after a logarithmic transformation, by a difference, this parallel holds for X binary. Notice that, differently from the above cited approaches, we here present a decomposition based on the exact formulation of the effects on the log odds scale.
Under the assumption that the recursive system of equation is structural in the sense of Pearl (2009, Ch. 7), one can give the total effect and some of its components a causal interpretation. To say that the recursive system of equations is structural implies that the DAG is a causal graph that satisfies a set of axioms, namely composition, effectiveness and reversibility, see also Steen and Vansteelandt With a single binary mediator, a parallelism between the structural definition of a DAG and the Sequential Ignorability Assumption of Imai, Keele, and Yamamoto (2010) exists, see Pearl (2012) and Shpitser and VanderWeele (2011). Under the assumption of no unmeasured counfounder of the treatment-outcome relationship, possibly after conditioning on a set of pre-treatment covariates C, the total effect of X on Y here presented corresponds to the total causal effect as de- show that the pure natural indirect effect can be seen as the total effect after assuming β x = β xw = 0 (i.e. the indirect effect; see Section 2.2 case i)) and that the pure natural direct effect corresponds to the total effect after assuming γ x = 0, i.e. X ⊥ ⊥ W (see Section 2.2 case iv)). More details are in Doretti et al. (2021).
When multiple causally ordered mediators are present, several possible effects are of interest, see Daniel et al. (2015); Steen et al. (2017). However, in this case the definition of natural direct and indirect effects is more cumbersome, and sometimes effects of interest are non-parametrically non identifiable, see e.g. the situation described in Avin, Shpitser, and Pearl (2005). Again, if no unobserved confounders exist, some parallelisms continue to hold. As an instance, the direct effect can be seen as the controlled direct effect of X on Y after an external intervention to fix the mediator W 1 = W 2 = . . . = W k = 0 is performed, see also VanderWeele and Vansteelandt (2014).
Our approach allows further to appreciate the total and controlled direct effect of X on Y also when some mediators are marginalized over, while others are kept in the system. We believe that this is an important research question in many applied studies.

Conclusions
Logistic regression is by far the most used model for a binary response. Further than in a mediation context, the models here proposed may arise in longitudinal studies with a binary outcome measured at different occasions.
With reference to a single mediator, we have proposed a novel decomposition of the total effect into direct and indirect effects that is more appropriate for the nonlinear case and that, under certain conditions, reduces to the classical definition in the linear case. Additionally, this decomposition overcomes the issue of unequal variance when fitting two nested models. As illustrative example, we have re-analyzed data based on an encouragement program to stimulate students' attitude to visit museums. We have shown how the decomposition of the total effect could avoid erroneous conclusions on the direct and indirect effects and provides additional information that cannot be found by just looking at the results of the separate regressions analysis. Although the total, direct and indirect effects are all positive, a substantial residual effect, possibly due to a large interaction coefficient, hinders the interpretation in terms of proportion mediated.
Additional important results concern the extension of the definitions to the multiple mediator context. Repeated use of the decomposition of the total effect allows to address complex issues like quantifying the total, direct and indirect effects when a subset of mediators are marginalized over. Links to the causal effects have also been established.

A Appendix: a general formulation
The definitions of total, direct, indirect effects can be extended to include a set of covariates C = (C 1 , C 2 , . . . , C p ). Let c = (c 1 , c 2 , . . . , c p ) denote a possible value of C. Let rhs(Y | W = w, X = x, C = c) denote the right hand side of the logit model for Y against X and C. Notice that rhs(Y | W = 1, X = 0, C = 0) is the part rhs(Y | W = w, X = x, C = c) that contains w terms only. Let rhs(W | X = x, C = c) denote the right hand side of the logit model for W against X and C.
A straightforward extension of the derivations presented in Section 1 leads to the following: with log RR W|Y,X=x,C=c = log exp g 1 (x, c) The total effect can be obtained from Equations (29) -(30), after taking the derivative with respect to X (for X continuous) or taking difference among levels of X (for X discrete).

C Appendix: multiple mediators
We here generalize the previous derivations to a situation with multiple mediators. We denote with g (w < j ) y (x, w > j ) the function (30) evaluated after marginalizing over the W < j mediators and considering (W j+1 , . . . , W k ) as covariates. The expression of g (w < j ) y (x, w > j ) can be derived recursively, after noting that g y (x, w >1 ) is (30) after imposing W = W 1 and C = W >1 . We marginalize iteratively over the inner mediator, that is starting from the marginalization over W 1 , we have and then over W 2 , we have up to marginalization over W k , that is where, at each step, D Appendix: marginalization over W 1 with k = 3 Let us consider the model with k = 3 and X binary. No conditional independences are assumed.
We here report the parametric forms for the parameters changed after the marginalization over W 1 .
Let us consider four logistic regression models, respectively, for the outcome Y, and for the three mediators W 1 , W 2 , W 3 , with interaction terms up to the second order.
We denote with γ j,0 , γ j,x , γ j,i , γ j,xi , γ j,hi , in order, the intercept, the coefficient of X, the coefficient of W i , the interaction term of X and W i and the interaction term of W h and W i in the regression of W j against W r , r > j, and X. We also denote with β (w i ) 0 , β (w i ) x , etc., in order, the intercept, the main effect of X, etc., of the logistic model for Y against the covariates after marginalization on W i and β , etc., in order, the intercept, the main effect of X, etc., of the logistic model for Y against the covariates after marginalization on W i and W > j . Notice that marginalization over the inner mediator induces changes in the parameters of the outcome equation only. From Eq. (29), considering W 2 and W 3 as covariates and marginalizing over W 1 we obtain the first marginal model for Y against X, W 1 , W 2 , W 3 over W 1 such as β (w 1 ) xw j xw j + β (w 1 ) xw 2 w 3 xw 2 w 3 = β 0 + β x x + β w 2 w 2 + β xw 2 xw 2 − log RRW 1 |Y,X=x,W 2 =w 2 ,W 3 =w 3 where log RRW 1 |Y,X=x,W 2 =w 2 ,W 3 =w 3 = log 1 + exp g 0 (x, w 2 , w 3 ) 1 + exp g 1 (x, w 2 , w 3 ) with g y (x, w 2 , w 3 ) obtained from (30) after imposing W = W 1 and C = (W 2 , W 3 ). It then follows that β (w 1 ) 0 = β 0 − log RRW 1 |Y,X=0,W 2 =0,W 3 =0 .
Notice that even if we did not include any type of interaction in the full model, after the first marginalization, the interactions of second and third order appear.