Hello I would like to perform restricted cubic spline (Cox adjusted) after multiple imputation with mice.I use rms package. but after imputation when I use the function datadist
I get this message (Error in sort.int(x, na.last = na.last, decreasing = decreasing, …) : 'x' must be atomic.)
I'm using the following code.
Multiple imputation
`Mydata<- mice::mice(cohort,seed = 123, print = FALSE,m=5)
# Converting data and performing restricted cubic spline
d<-datadist(Mydata)
options(datadist="d")
k<-with(Mydata,quantile(tg,c(.05,0.25,0.75,0.95)))
fit<- cph(Surv(time, cvd) ~ rcs(tg, k)+covariates, data=Mydata)
myplot <- Predict(fit,tg, ref.zero = TRUE, fun=exp)
ggplot(dataplot,aes(tg, yhat)) + geom_line(colour="blue", linetype="solid", size=1)+geom_hline(yintercept =1, linetype="dashed")`
Any guidance.
Thank you in advance.
Best Answer
The problem is that
datadist()
expects as its argument:You provided it with what's effectively a list of 5 data frames, one per imputation. So it didn't know what to do.*
A
datadist
object provides useful choices for later display of model results. You don't need to usedatadist
to fit the model or to display results withPredict()
. As the help page forPredict()
says, there's an alternative:What might be simpler would be to use
datadist()
on one of the imputed data sets. That should allow you to use the convenient summaries of model results like those thatPredict()
provides.*I suspect that you have a similar problem with the way that you are calling
cph()
on the imputed data sets. I understand that you need to call thefit.mult.impute()
function withfitter=cph
, as Demetri Pananos indicates in a comment, to get the proper results based on Rubin's rules.