Giter VIP home page Giter VIP logo

Comments (10)

DrLilei avatar DrLilei commented on August 18, 2024 2

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.

alessiohappy avatar alessiohappy commented on August 18, 2024 1

I was facing the same problem using a continuous exposure and a binary mediator.
Here's what I did:

  1. df$mediator <- as.factor(df$mediator)

  2. df$mediator <- as.numeric(df$mediator)
    The binary mediator records were so "converted" from 0 and 1 to 1 and 2, respectively.

  3. 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.

mdtrinh avatar mdtrinh commented on August 18, 2024

I can't replicate this without the data but #24 is likely to fix this problem

from mediation.

elitefan04 avatar elitefan04 commented on August 18, 2024

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.

b-staley avatar b-staley commented on August 18, 2024

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.

Effy-runrun avatar Effy-runrun commented on August 18, 2024

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.

Sabrinaeder1424 avatar Sabrinaeder1424 commented on August 18, 2024

@b-staley I have the same issue, did you figure it out? : )

from mediation.

b-staley avatar b-staley commented on August 18, 2024

@Sabrinaeder1424 and @Effy-runrun, I have not found a solution yet. Please let me know if you do.

Best,

Brooke

from mediation.

Effy-runrun avatar Effy-runrun commented on August 18, 2024

@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.

liulinsmu avatar liulinsmu commented on August 18, 2024

Thanks for @alessiohappy inspiration.
I also found a similar solution.
To rum mediate function, we have to keep the specific class of variables.

  1. 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 that mediate can not.
  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.