# Causal Mediation Analysis with treatment smoothed in the outcome stage and linear in the mediator stage

I am considering a mediation analysis that looks like the following in r:

m_1 <- gam(mediator1 ~ age_cat + s(treat, k = 50, bs = "cr") +
cov1 + cov2 + cov3 + cov4 + year, data = mediation_df,
method = "REML")

y_1 <- gam(dem_important ~  age_cat + mediator1 +
s(treat,k = 50, bs = "cr") + cov1 + cov2 + cov3 + cov4 +
year, data = mediation_df, method = "REML")

results1 <- mediate(m_1, y_1, sims = 1000, boot = TRUE,
treat = "treat", mediator = "mediator1")



Where m_1 is the mediation model, y_1 is the outcome model, and mediator1 is a continuous variable, age_cat is a categorical variable, treat is a factor variable modelled with a smooth, cov1, cov2, cov3, cov4 are all dummy variables, and year is a factor variable.

I am now considering a model specification where the mediation model is different:

m_2 <- lm(mediator1 ~ age_cat + treat +
cov1 + cov2 + cov3 + cov4 + year, data = mediation_df,
method = "REML")

y_2 <- gam(dem_important ~  age_cat + mediator1 +
s(treat,k = 50, bs = "cr") + cov1 + cov2 + cov3 + cov4 +
year, data = mediation_df, method = "REML")

results2 <- mediate(m_2, y_2, sims = 1000, boot = TRUE,
treat = "treat", mediator = "mediator1")



In this model setting, for mediation purposes, I do not have a smooth on the treatment variable, as I do not assume a smoothed effect for the factor variable treat on the mediator.

I am wondering if this model specification makes sense. I have seen cases of mediation where one the mediation model is linear and the outcome model is a GAM (Imai et al.). However I have not seen setups where the treatment variable itself is the variable that takes a different form between the two model setups.

Is there a research that has done this? Is this method legitimate at all? What kinds of assumptions must be made to set up a causal mediation analysis like this?

That shouldn't matter as long as predictions can be made from the model since that is how mediation works (i.e., predictions from the mediator model are supplied to the value of the mediator in the outcome model, and the treatment variable is set to specific values for those predictions). What does matter are the values supplied to the control.value and treat.value Since those determine the specific contrast being assessed. By default, these are 0 and 1, which may not be relevant at all to your treatment variable. Because treatment is no included linearly in both models, the values these arguments take will affect the value and interpretation of the medication quantities. If you want a single mediation effect that doesn't rely on the specific values these arguments take, you need to use different models or a different mediation method. There is no such thing as a single "direct effect" or "indirect effect"; these quantities depend on the value the treatment takes under treatment and control. Only when both models are linear or the treatment is binary does this not matter, and in most cases that is unreasonable.

• Thank you so much for your reply and clear explanation. If I may follow up, I am thinking through the control.value and treat.value in this design. For a basic 2-group treatment and control experiment, it is clear how it would work as 0 and 1. But, here I have a factor variable treat with all different values of treatment. My GAM smoothes over the effect of treat on all these different values. I want to find mediation on treat broadly speaking, even though I'm interested in the general mediation on all levels. Do I set a reference level for treat as a control group? Commented Apr 8 at 19:39
• For another example with context, if I am modeling a time trend, and say treat is a variable for observation's birth year, the point of the GAM is to see the birth year effect smoothly modelled over time. When using this as the treatment, I'm not interested in one particular group against another, I want to see the mediation effect on birth year's effect on the outcome across all its values. Is there a particular way to incorporate this in the control.value and treat.value syntax that comes to mind? Commented Apr 8 at 19:42
• The definition of mediation used the mediation package is not compatible with how you have defined your treatment. mediation is not a general purpose mediation package; it implements the specific methods describe in the accompanying papers, which require specifying a contrast between two levels of the treatment. I would encourage you to define your estimand in terms of potential outcomes, not in terms of "is there mediation present", and find a mediation method that allows you to target that estimand. As you have described it, this method is not compatible with your research question.
– Noah
Commented Apr 8 at 19:49
• Thank you for your detailed response. I will definitely look into different mediation options, as I was only familiar with mediation. I am wondering if you might be able to recommend literature for these other mediation methods? Specifically, I am interested in a style of mediation similar to that which is used in this paper: Platt et al. 2020 (doi.org/10.1016/j.socscimed.2020.113088), where the estimand of interest is the mediation effect on a smoothed trend over time. If not mediation, would you interpret this mediation approach as something else in particular? Commented Apr 9 at 4:57
• That paper uses linear models with no smoothing. With linear models, it doesn't matter what values control.value and treat.value take. They use a very simple mediation analysis. All mainstream causal mediation analysis that I know of assumes the estimand is a contrast between expected potential outcomes defined for two values of the treatment. If you can write your estimand, I might be able to point you in a specific direction.
– Noah
Commented Apr 9 at 5:44