kosukeimai / mediation

R package mediation
58 stars 29 forks source link

Bug fix for Issue #23 subscript out of bounds #24

Closed mdtrinh closed 4 years ago

mdtrinh commented 4 years ago

Fixes #23 by adding a procedure to convert character treatment and mediator variables to factor in medsens() (this was already part of mediate() but not incorporated into medsens().

Also fixes a new bug that causes mediate to break when the mediator is a factor variable.

elitefan04 commented 2 years ago

Hello! Could you please explain how to solve this problem more in detail? I have difficulty in reading the code and solve my problem. My model is like this: med.1 <- lmer(new_JOL~new_ME+(1+new_ME|sub),LS2_diffdata) out.1 <- glmer(formula = LS ~ new_MEGroup + new_JOLGroup+ (1+new_ME+new_JOL|sub), family = binomial(link = "logit"), data = LS2_diffdata, control = glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun=2e5))) med.result <- mediate(med.1,out.1, treat="new_ME",mediator="new_JOL",sims = 5000, treat.value = 10 , control.value = 0)

My mediator is for sure a continuous varible from 0 to 10. I used the class(LS2_diffdata$new_JOL) to check, and it showed [numeric]. I am really confused why I encoutered the error message: error in if (xhat == 0) out <- 1 else { : missing value where true/false needed.

If anyone can help me, I will be very much appreciated!