Zhiyuan Sun
2014-Mar-06 03:51 UTC
[R] How to use restricted cubic spline in survfit.cph function in "survival" package?
Hello, I used PBC data set included in the "survival" package to fit a cox model. The model included a restricted cubic spline transformation on age. Then I tried using "survfit" function to predict a survival curve using the first row of the original data. I got an error message. The R code and error message is below.> require(survival) > fit<-coxph(Surv(time,status==2)~rcs(age,4)+sex, data=pbc) > id1<-pbc[1,] > surv.id1<-survfit(fit,newdata=id1)Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc) : fewer than 6 non-missing observations with knots omitted Can anyone provide any suggestions? Thanks, Zhiyuan
Andrews, Chris
2014-Mar-06 13:13 UTC
[R] How to use restricted cubic spline in survfit.cph function in "survival" package?
Try cph in rms (where rcs is defined). library(rms) fit<-cph(Surv(time,status==2)~rcs(age,4)+sex, data=pbc, y=TRUE, x=TRUE) id1<-pbc[1,] surv.id1<-survfit(fit,newdata=id1) plot(surv.id1) summary(surv.id1) -----Original Message----- From: Zhiyuan Sun [mailto:sam.d.sun at gmail.com] Sent: Wednesday, March 05, 2014 10:52 PM To: r-help at r-project.org Cc: therneau.terry at mayo.edu Subject: [R] How to use restricted cubic spline in survfit.cph function in "survival" package? Hello, I used PBC data set included in the "survival" package to fit a cox model. The model included a restricted cubic spline transformation on age. Then I tried using "survfit" function to predict a survival curve using the first row of the original data. I got an error message. The R code and error message is below.> require(survival) > fit<-coxph(Surv(time,status==2)~rcs(age,4)+sex, data=pbc) > id1<-pbc[1,] > surv.id1<-survfit(fit,newdata=id1)Error in rcspline.eval(x, nk = nknots, inclx = TRUE, pc = pc) : fewer than 6 non-missing observations with knots omitted Can anyone provide any suggestions? Thanks, Zhiyuan ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues