R语言:cox分析列线图

> library(survival)
> library(regplot)
> library(rms)

> expFile="expTime.txt"       
> cliFile="clinical.txt"      


> exp=read.table(expFile, header=T, sep="\t", check.names=F, row.names=1)

> cli=read.table(cliFile, header=T, sep="\t", check.names=F, row.names=1)
> cli=cli[apply(cli,1,function(x)any(is.na(match('unknow',x)))),,drop=F]
> cli$Age=as.numeric(cli$Age)


> samSample=intersect(row.names(exp), row.names(cli))
> exp1=exp[samSample,,drop=F]
> cli=cli[samSample,,drop=F]
> rt=cbind(exp1, cli)


> res.cox=coxph(Surv(futime, fustat) ~ . , data = rt)
> nom1<-regplot(res.cox,
              plots = c("density", "boxes"),
              clickable=F,
              title="",
              points=TRUE,
              droplines=TRUE,
              observation=rt[2,],
              rank="sd",
              failtime = c(1,3,5),
              prfail = F)

> nomoRisk=predict(res.cox, data=rt, type="risk")
> rt=cbind(exp1, Nomogram=nomoRisk)
> outTab=rbind(ID=colnames(rt), rt)
> write.table(outTab, file="nomoRisk.txt", sep="\t", col.names=F, quote=F)

> pdf(file="calibration.pdf", width=5, height=5)

> f <- cph(Surv(futime, fustat) ~ Nomogram, x=T, y=T, surv=T, data=rt, time.inc=1)
> cal <- calibrate(f, cmethod="KM", method="boot", u=1, m=(nrow(rt)/3), B=1000)
> plot(cal, xlim=c(0,1), ylim=c(0,1),
     xlab="Nomogram-predicted OS (%)", ylab="Observed OS (%)", lwd=1.5, col="green", sub=F)

> f <- cph(Surv(futime, fustat) ~ Nomogram, x=T, y=T, surv=T, data=rt, time.inc=3)
> cal <- calibrate(f, cmethod="KM", method="boot", u=3, m=(nrow(rt)/3), B=1000)
> plot(cal, xlim=c(0,1), ylim=c(0,1), xlab="", ylab="", lwd=1.5, col="blue", sub=F, add=T)


> f <- cph(Surv(futime, fustat) ~ Nomogram, x=T, y=T, surv=T, data=rt, time.inc=5)
> cal <- calibrate(f, cmethod="KM", method="boot", u=5, m=(nrow(rt)/3), B=1000)
> plot(cal, xlim=c(0,1), ylim=c(0,1), xlab="", ylab="",  lwd=1.5, col="red", sub=F, add=T)
legend('bottomright', c('1-year', '3-year', '5-year'),
       col=c("green","blue","red"), lwd=1.5, bty = 'n')
> dev.off()

学习交流一下

  • 13
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值