# Direct and indirect effect of a categorical variable with more than 2 levels in a structural equation model

I am new in SEM, and trying to figure out how to possibly get proportion of direct/indirect effect of a categorical variable with more than 2 levels over its total effect.

We have a categorical variable Intervention with 3 levels, coded as A1 and A2 dummy variables. We measure Outcome, and have another Mediator variable that mediates between the dummy variables and Outcome. Both continuous.

A1-> Outcome[label='a1']
A2-> Outcome[label='a2']
A1-> Mediator[label='b1']
A2-> Mediator[label='b2']
Mediator-> Outcome[label='c']


We are interested in the effect of Intervention to Outcome, and whether it is mediated through Mediator. We are using lavaan in R to calculate a path model, using the following formula

Outcome ~ a1*A1 + a2*A2 + c*Mediator
Mediator ~ b1*A1 + b2*A2

# computing parameters
direct := a1 + a2
indirect := b1*c + b2*c
total := direct + indirect
proportion := indirect/total



I am not sure if the computed parameters above, summing paths starting from each of the two dummy variables, have any meaning. In particular,

1. Would "proportion" above be meaningful in terms of mediation?
2. Is there any way here to consider the direct combined effect of the two dummy variables together as "Intervention"? Is the "direct" parameter above meaningful as the direct effect of intervention on outcome? If not in any absolute/magnitude terms, at least in terms of statistical significance?

I suspect (2) to be partially true, as the z and p-value associated to "direct" does not seem to change depending on how the dummy variables are coded (but the estimates do change), so it seems to refer to the intervention itself. Similarly for (1), "proportion" is constant across codings. But I am still unsure whether/how any this is meaningful.

I don't think it makes sense, because your choice of reference category is arbitrary.

Imagine you were just interested in the effect from A to Mediator. The means might be:

• group 0: 0
• group 1: 1
• group 2: 2

If you pick 0 as the reference category, b1 = 1, b2 = 2. If you pick 1 as the reference category, b1 = -1, b2 = 1. Clearly these lead to different sums, when the models are equivalent, and should not lead to different solutions.

If people combine multiple category effects in this way, they so it with $$R^2$$ or $$\eta^2$$, but I don't think that makes sense with a mediation effect.

If you have balanced categories for A1, A2, A3 (same nr. of cases each) you can use effect coded dummies. For the first regression of the mediator on A, the intercept is then the sample mean of the mediator values, say the "grand mean" of the mediator. The regression effects b1 of A1 and b2 of A2 show the respective deviations from that grand mean for these two groups. For A3, there also is an effect, namely minus the sum of the two effects of A1 and A2! So you can add an arrow in your diagram for A3 as well! In a similar way you can calculate and draw the direct effect of A3 on your outcome. If I'm right (it has been a long time ago) you should center the mediator around its mean value, so that the mediator mean is zero. This is relevant for the regression of the outcome on A and the mediator. You can then calculate the direct and indirect effects in the usual way. The total effect of A is the sum of all direct and indirect effects.

But probably you will not have a balanced design for A. No need to worry, because then you can use weighted effect coding for the three dummies of A! This is described here. I'm not sure if this R package still works, but you can pretty simple construct these wec dummies yourself, as explained there.

See Israëls paper path analysis categorical variables for a detailed description of using categorical variables in a path analysis.