kosukeimai / mediation

R package mediation
57 stars 28 forks source link

Error in Surv(time, event) : cannot find object "time" #33

Open ShangziWang opened 2 years ago

ShangziWang commented 2 years ago

[Error in Surv(time, event) : cannot find object "time"] in survreg()

Here I am doing mediation analysis among X, Y, and m. Here model.m is linear model and model.y is survival model. The code is as follow:

model.m <- lm(m ~ X, data = data) model.y <- survreg(Surv(time, event) ~ X+m, data = data) mediation <- mediate(model.m, model.y, treat = "X", mediator = "m" , boot = T, outcome = "event")

However, error occurred as Error in Surv(time, event) : cannot find object "time.

lijiaqi-github commented 1 year ago

I have the same problems. The error I met is Error in Surv(time, status) : Time variable is not numeric.

> model.m <- lm(sex ~ ph.ecog, data = lung)
> model.y <- survreg(Surv(time, status) ~ ph.ecog + sex, data =  lung)
> mediation <- mediate(model.m, model.y, treat = "ph.ecog", mediator = "sex" , boot = T, outcome = "status")
Running nonparametric bootstrap

Error in Surv(time, status) : Time variable is not numeric

Could you tell me how you solved them? Thank you.