Teach you how to use R language to make a competitive risk model and draw a nomogram

The competitive risk model refers to the outcome event that competes with it in a clinical event. This is the event that will cause the original outcome to change, so it is called the competitive risk model. For example, we want to observe the recurrence of a patient’s tumor, but the patient died suddenly in a car accident during the observation period, or died from other diseases, so we cannot observe the recurrence. In this case, the missing data cannot be treated as right-censored only. In this case, the estimation of the data will be wrong. This is that we should give priority to the competitive risk model for data analysis, rather than COX regression. Competitive risk models are often used in data mining. We will introduce how to use competitive risk models for data mining in the SEER database mining tutorial in the future.
Insert picture description here
We use the data set of bladder cancer bladder1 that comes with the R language survival. In order to make it meet the requirements of the competitive risk model, we have done a little sorting. What we want to observe is tumor recurrence, so death is its risk competition factor. .
First we import the required R, and then import the data

library(foreign)
library(survival)
library("cmprsk")
library(rms)
be<-read.csv("E:/r/test/jzfx.csv",sep=',',header=TRUE)

Insert picture description here
Let’s take a look at what the data looks like.
Insert picture description here
The name of the data is interpreted as:
id: patient number; treatment: 1. placebo 2. vitamin B 6. 3. thiotepa;
number: initial number of tumors size: largest Initial tumor size (cm) recur: number of recurrences
start, stop: start, stop: start and end time of each time interval status (outcome): 1. Survival 2. Recurrence 3. Death rtumor: The number of tumors found at recurrence rsize: the largest tumor size at recurrence

## 不同治疗方案的复发率和竞争事件发生率
cum<-cuminc(be$etime,be$status,be$treatment)
plot(cum)

Insert picture description here

Can also beautify
Insert picture description here

## 多因素竞争风险模型-复发的发生率(或竞争事件的发生率,failcode = 2)
time<-be$etime
status<-be$status
x <- be[, c('treatment', 'number', 'size','recur')]
fit2 <- crr(time,status,x,failcode = 1)#这里failcode = 1代表肿瘤复发
summary(fit2)

Insert picture description here
Okay, we have got the model, now we will bring in 1 patient to test it

fit3<-predict(fit2,c(1,2,1,0)) #对应数据X的4个指标
plot(fit3,lty=1,color="darkcyan",ylab="Cumulative probability of recurrence")

Insert picture description here
##Next, let’s do a nomogram.
First, we need to weight the data. Why do we need weighting? The principle is very complicated. I don’t know the principle of the competitive risk model, but the big cows say that we need to weight it. .

library(mstate)
bc<-be
bc<-bc[-1,]
bc<-bc[-129,]
be.w<-crprep("etime",status = "status",data =bc,trans = c(1,2),cens = 0,id="id",
             keep = c('treatment', 'number', 'size','recur'))#进行加权

Insert picture description here

be.w$Time<-be.w$Tstop-be.w$Tstart#添加个时间,好进行COX回归
dd<-datadist(be.w)
options(datadist="dd")
f <- cph(Surv(Tstart,Tstop,status==1) ~ treatment+number+size+recur, x=T, y=T, 
         surv=T, data=be.w, time.inc=36)#建立COX回归
surv<- Survival(f)#生成预测函数
nom <- nomogram(f, fun=list(function(x) surv(36, x),
                            function(x) surv(60, x)),
                funlabel=c("3-year survival Probability", 
                           "5-year survival Probability"))#制作列线图
plot(nom)

Insert picture description here
This nomogram is a bit ugly, mainly because the probability is too small. If you are interested, you can adjust it by yourself
###Median nomogram

med <- Quantile(f) # 计算中位生存时间
nom2 <- nomogram(f, fun=function(x) med(lp=x),funlabel="Median Survival Time")
plot(nom2)

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/dege857/article/details/112257071