这是我一直在尝试执行的代码。
我的示例代码
library(rms)
ddist <- datadist(data)
options(datadist='ddist')
fit <- psm(Surv(days_pfs, pd2) ~ rcs(x1,3)+rcs(x2,3)+x3+x4+x5+x6+ x7+x8+x9,
dist="lognormal", x=T , y=T , data=data)
newdata <- expand.grid(x1=7, x2=3, x3=3, x4=2, x5=1 ,x6=0, x7=1, x8=2,x9=1)
xb<-predict(fit,newdata)
survival12 <- 1-pnorm((log(12)-xb)/fit$scale)
pdf <- (dnorm((log(12)-xb)/fit$scale))/(12* fit$scale)
# 18 elements to codify restricted cubic splines & categorical variable
x <- c(1,7,7, 3,3, 0,1,0, 1,0,0, 1,0, 0, 0, 1,0 ,1)
se <- pdf %*% t(x)%*%vcov(fit) %*% x %*% pdf %>% sqrt
ll <- (1-s12)-1.96*se
ul <- (1-s12)+1.96*se
ic <- c(ul,1-s12,ll)
1-ic