mediation icon indicating copy to clipboard operation
mediation copied to clipboard

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

Open sebsilas opened this issue 1 year ago • 3 comments

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

sebsilas avatar May 12 '23 09:05 sebsilas

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

evagrosfeld avatar Jul 07 '23 14:07 evagrosfeld

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?

sebsilas avatar Jul 10 '23 15:07 sebsilas

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

evagrosfeld avatar Jul 10 '23 15:07 evagrosfeld