0

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)
AndySavage
  • 1,729
  • 1
  • 20
  • 34
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) which would include sample input data. Otherwise we have no idea how your formula relates to the data in your data.frame. – MrFlick Nov 07 '14 at 17:44
  • Try using: lm(posttx~ pretx+ Group, data=imp1) rather than with(imp1, lm(..)) – rnso Nov 07 '14 at 17:45
  • Based on your description you have a longitudinal (repeated) design and use the mediate package. I'm trying to run a mediation analysis on repeated measures but hesitate whether the mediate function is suitable. Just wondering what your rationale is. I'm new to mediation analysis. – Simone Apr 21 '18 at 15:09

0 Answers0