Comments (10)
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)
from mediation.
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.
from mediation.
I can't replicate this without the data but #24 is likely to fix this problem
from mediation.
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!
from mediation.
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
from mediation.
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?
from mediation.
@b-staley I have the same issue, did you figure it out? : )
from mediation.
@Sabrinaeder1424 and @Effy-runrun, I have not found a solution yet. Please let me know if you do.
Best,
Brooke
from mediation.
@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.
from mediation.
Thanks for @alessiohappy inspiration.
I also found a similar solution.
To rum mediate
function, we have to keep the specific class of variables.
- Outcome variables and mediators should be continuous variables with values "0" and "1", despite
glm
can fit the model with character outcomes, but it seems thatmediate
can not. - Exposure variables should be binary or continuous.
I don't know why we have to set the class of the variables, but it indeed works.
from mediation.
Related Issues (20)
- Can this packages be used to perform mediation analysis with cox PH model? HOT 1
- Error in offset(years.in.study) : object 'years.in.study' not found
- Could Package "mediate" support multi-categorical treatment? HOT 2
- Fitting an outcome model that is within subject (model.y, using lmer) and a simple model for the mediator (`model.m`, using lm)? HOT 1
- Conda Wheel
- Does mediation package support multi-categorical outcome?
- multiply imputed (MICE) data: pooled p-value calculation
- Error in mediate function when fitting multilevel mediation analysis with crossed random factors
- Model combination error using medsens on a mediate object derived from amelidiate (multiply-imputed data) HOT 1
- Error in if(!INT & isGam.y) { : the condition has length > 1 HOT 3
- Multiple-trial binomial mediator: an inconsistency?
- Does medsens function support the sensitivity analysis of causal mediation analysis with multilevel data? HOT 2
- How could I perform mediation analaysis with multiple mediators (UNCORRELATED WITH EACH OTHER) with the package "mediation" HOT 2
- Running a GAM interaction model as input for mediator and outcome model
- test.TMint for mixed effects models
- More class in mediate function
- Extracting estimates from mediate() output objects for pooling by Rubin's rules
- How much variation should we expect in the CIs based on nonparametric bootstrapping? HOT 1
- Date the updated 'mediation' vignette was created? HOT 1
- Mediation analysis with multiple treatment variables
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mediation.