Open almogsi opened 4 years ago
I can't replicate this without the data but #24 is likely to fix this problem
this may help you to fix this problem. in mediate.R, you can find "For binary response models, the 'mediator' must be a numeric variable with values 0 or 1 as opposed to a factor." (Line 53-54)
I'm having trouble with
mediation::mediate()
nb.terror.y.anx <- glm(data = terror_removed2, certain~cond + event + WC + anx, control = glm.control(maxit = 50000), family = "poisson") nb.terror.m.anx <- glm(data = terror_removed2, anx~cond + event + WC + certain, control = glm.control(maxit = 50000), family = "poisson") med.anx <- mediation::mediate(nb.terror.m.anx,nb.terror.y.anx, treat = "cond", mediator = "anx", sim = 2)
Works fine, but whenever sim>2, I get:
Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed
I saw there's still an open topic in a realted issue
Hope it's ok to flag it up again.
Thanks!
@almogsi Hello! I met the same problem. Can I ask how did you solve this problem eventually? Many thanks!
I am also running into the issue and getting this error. The response in #24 has not helped. I have a continuous mediator, binary (0/1) exposure and survival outcome. Could someone please advise?
Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed
I am also running into the issue and getting this error. The response in #24 has not helped. I have a continuous mediator, binary (0/1) exposure and survival outcome. Could someone please advise?
Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed
Hi, I'm wondering if you have found a solution to this issue?
@b-staley I have the same issue, did you figure it out? : )
@Sabrinaeder1424 and @Effy-runrun, I have not found a solution yet. Please let me know if you do.
Best,
Brooke
@Sabrinaeder1424 and @Effy-runrun, I have not found a solution yet. Please let me know if you do.
Best,
Brooke
Hi, I have given up trying with this package, and found another package call "regmedint" while searching. It was developed based on SAS and SPSS macro "mediation" by Valeri & VanderWeele, which also allows for mediation analysis concerning survival data. I succeeded in analyzing my data with this package, and the authors have written a detailed paper on how to use this package. https://www.researchgate.net/publication/359526597_A_Brief_Primer_on_Conducting_Regression-Based_Causal_Mediation_Analysis
Hope this will work for you too.
I was facing the same problem using a continuous exposure and a binary mediator. Here's what I did:
df$mediator <- as.factor(df$mediator)
df$mediator <- as.numeric(df$mediator)
The binary mediator records were so "converted" from 0 and 1 to 1 and 2, respectively.
df$mediator <- ifelse(df$mediator == 1, 0, ifelse(df$mediator == 2, 1, df$mediator))
df$mediator <- ifelse(df$mediator == 1, 0, ifelse(df$mediator == 2, 1, df$mediator))
Finally, i run the mediate
function once more and that worked with no more issues.
Thanks for @alessiohappy inspiration.
I also found a similar solution.
To rum mediate
function, we have to keep the specific class of variables.
glm
can fit the model with character outcomes, but it seems that mediate
can not.I don't know why we have to set the class of the variables, but it indeed works.
I'm having trouble with
mediation::mediate()
Works fine, but whenever sim>2, I get:
I saw there's still an open topic in a realted issue
Hope it's ok to flag it up again.
Thanks!