kosukeimai / mediation

R package mediation
61 stars 29 forks source link

Error in if(!INT & isGam.y) { : the condition has length > 1 #57

Open sebsilas opened 1 year ago

sebsilas commented 1 year ago

I recently updated R and my packages and the below code, which was previously working, is no longer working:

fit.dv <- lme4::lmer(opti3 ~ no_recalled_notes + N + condition + log(attempt) + log(attempt):N + (1|unique_melody_name), data = na.omit(main2))

fit.mediator <- lme4::lmer(no_recalled_notes ~ N + condition + log(attempt) + log(attempt):N + (1|unique_melody_name), data = na.omit(main2))

results <- mediation::mediate(fit.mediator, fit.dv, treat = c('N', 'condition'), mediator = 'no_recalled_notes')

The error is:

Error in if(!INT & isGam.y) { : the condition has length > 1

evagrosfeld commented 1 year ago

Good afternoon, I have a similar problem. Have you already resolved the issue?

sebsilas commented 1 year ago

Hi @evagrosfeld. Yes, I think it's because you can only have one treat variable (I just noticed this in the documentation). I moved one of my treat variables (condition in my example above) to the covariates argument, and it works now.

Were you trying to use two or more variables for treat?

evagrosfeld commented 1 year ago

Indeed, I was. Thank you, inserting one of the treat variables as covariates variable solves the issue!