简体   繁体   中英

How to Adjust restricted cubic spline cox model using rms package?

I am trying to plot a restricted cubic spline model using the rms package. However I don't find any way to adjust my cox proportional hazard model, I can only get the unadjusted fit. Here is my code:

library(survival)
library(rms)

dd <- datadist(Cox9)
options(datadist="dd")

fit <- cph(Surv(follcox,evento) ~  rcs(G_VINO,3))
plot(Predict(fit_vino), lty=1, lwd=3, ylim=c(-0.5,1.0),xlim = c(0,50), col="white") 

With this coding I get the unadjusted spline model. I wondered how can I add the confounding variables to adjust the model. I tried:

fit_vino_adj <- cph(Surv(follcox,evento) ~rcs(G_VINO+edad0+actfis+energia))
plot(Predict(fit_vino_adj), lty=2, lwd=2)

But that gives me the splines model of each variable separately, anyone has an idea how can I adjust my model?

Since you failed to include the data in Cox9 or show how one might construct a similar dataframe or show any output, we can only guess at what happened and respond in generalities. It appears that you are bundling the variables within the rcs function. That is unlikely to succeed, or if it does succeed seems likely that the results will be incorrect. Instead you should construct this fit and then plot only the adjusted fit of the curve you are interested in by naming the variable of focus in the Predict -call.

fit_vino_adj <- cph(Surv(follcox,evento) ~ rcs(G_VINO, 3)+edad0+actfis+energia)
plot(Predict(fit_vino_adj, name="G_VINO"), lty=2, lwd=2)

Or perhaps (assuming these are all continuous measurements) make the very slightly modified plotting call after:

fit_vino_adj2 <- cph(Surv(follcox,evento) ~ rcs(G_VINO, 3)+rcs(edad0, 3) + 
                                           rcs(actfis, 3) + rcs(energia, 3) )
plot(Predict(fit_vino_adj), lty=2, lwd=2)  # to see form of all variable fits.

If you want to have two or more rcs splines in the models, then you need to wrap rcs around the other variables separately. I did not think that rcs function was not like the ^ function, which has a formula expansion method. (Although your claim that you got separate output from that second model makes me wonder if I have completely kept up with that package.) If you wanted a complex surface for what I call "crossed-splines", then you would use the * operator between two rcs calls. Crossing with a factor variable will construct individual rcs-spline fits for each level of the factor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM