I'm working on a time-to-event mediation analysis in R and have been having difficulty getting the program to run.
I'm trying to examine changes from pre to post treatment on a questionnaire measure as a mediator of group differences in medical events following the intervention. One issue is there were several dropouts so I've attempted to impute the values in the code below. I keep getting the following message for the mediate statement:
Error in formula.default(object, env = baseenv()) : invalid formula
The code is below. Any input is very much appreciated!
med.fit <- with(imp1, lm(posttx~ pretx+ Group))
out.fit<- with(imp1, survreg(Surv(eventtm,event) ~ Group + posttx, dist="lognormal"))
med.out <- mediate(med.fit, out.fit, boot=TRUE, treat = "Group", mediator = "posttx", sims = 100)
summary(med.out)