其他
建模-验证-cox-timeROC-校准曲线-DCA曲线(小全套)
The following article is from 灵活胖子的科研进步之路 Author 灵活胖子1988
说明
比较容易,就不具体写了,代码都是默认参数,可以调整后美化图片
# 0. 载入包----------------------------------------------------------------------
library(survival)
library(riskRegression)
library(dcurves)
library(tidyverse)
library(regplot)
# 1.构建数据集并构建模型 ----------------------------------------------------------------------
# 载入数据集
dslearn=sampleData(56,outcome="survival")
dstest=sampleData(100,outcome="survival")
# 建立 COX 回归模型
cox_model <- coxph(Surv(time,event)~X1+X5+X7,data=dslearn,x=1)
# 查看回归系数
summary(cox_model)
# 2.在建模集中绘制列线图,time-AUC,决策曲线及DCA曲线 ----------------------------------------------------------------------
#列线图
regplot(reg = cox_model,failtime = c(1,3,5))
#time-auc
xx=Score(list("cox_model"=cox_model), formula=Surv(time,event)~1,
data=dslearn, metrics="auc", null.model=FALSE, times=seq(1:5))
plotAUC(xx,conf.int=TRUE)
#校准曲线
xs=Score(list(cox_model),Surv(time,event)~1,data=dslearn,
plots="cal",metrics=NULL,q=2)
plotCalibration(xs,method="quantile")
#DCA曲线
dslearn$pred <- predict(object = cox_model,newdata = dslearn,type = "survival")
dslearn$event <- ifelse(dslearn$event==1,T,F)
dca(Surv(time,event) ~ pred, data = dslearn, time = 2)
# 3 验证集time-AUC,决策曲线及DCA曲线 ----------------------------------------------------------------------
#time-auc
xx=Score(list("cox_model"=cox_model), formula=Surv(time,event)~1,
data=dstest, metrics="auc", null.model=FALSE, times=seq(1:5))
plotAUC(xx,conf.int=TRUE)
#校准曲线
xs=Score(list(cox_model),Surv(time,event)~1,data=dstest,
plots="cal",metrics=NULL,q=2)
plotCalibration(xs,method="quantile")
#DCA曲线
dstest$pred <- predict(object = cox_model,newdata = dstest,type = "survival")
dstest$event <- ifelse(dstest$event==1,T,F)
dca(Surv(time,event) ~ pred, data = dstest, time = 2)
关注下方公众号,分享更多更好玩的R语言知识。
点个在看,SCI马上发表。