kosukeimai / mediation

R package mediation
58 stars 29 forks source link

Running a GAM interaction model as input for mediator and outcome model #62

Open basilinb opened 1 year ago

basilinb commented 1 year ago

I am having some trouble using your mediate() function with a Generalized Additive Model(GAM) and see that your documentation specifies it can be done, but does not explain the appropriate syntax. Specifically, I am trying to run a causal mediation analysis with a GAM with an interaction between a continuous variable (time) and two factor categorical variable (illness group). The model aims to asses the relationship of how gene expression (continuous variable) differs over time (also a continuous variable) by a two factor categorical variable (Illness group) and whether this is mediated by viral load (a continuous variable), which differs overtime between the two illness groups. The model syntax for the GAMs is here:

model.mediate <- gam(viral_load~illnessgroup+ s(time) +s(time, by = illnessgroup), data=data, method = "REML")

model.outcome <- gam( gene_exp~illnessgroup + viral_load + s(time) +s(time, by = illnessgroup) ,data=data, method = "REML") mediation_result <- mediate(model.m = model.mediate, model.y = model.outcome, mediator = "viral_load", treat = "illnessgroup", treat.value = "Severe", control.value = "Not_Severe", boot = TRUE, control = "Not_Severe")

This gives me an output with the average ACME, ADE, Prop. mediated and Total Effects but I was expecting to see separate statistics for the treatment (Severe) and control (Not Severe) conditions. This is what we would expect if using a linear model rather than a GAM. Any advice on how to appropriately run the mediate() function with a GAM model using an interaction for 2 comparison groups to get the output for both the treatment and control groups would be much appreciated. Thank you, Basilin Benson