Cox Model Splines – How to Perform Restricted Cubic Spline (Cox Adjusted) After Multiple Imputation with MICE?

cox-modelcubicmultiple-imputationsplines

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:

a list of variable names, separated by commas, a single data frame, or a fit with Design information. (From help page; emphasis added.)

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 use datadist to fit the model or to display results with Predict(). As the help page for Predict() says, there's an alternative:

For variables not described using datadist, you must specify explicit ranges and adjustment settings for predictors that were in the model.

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 that Predict() 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 the fit.mult.impute() function with fitter=cph, as Demetri Pananos indicates in a comment, to get the proper results based on Rubin's rules.

Related Question