Cox生存分析可视化-Forest plot(森林图) |

今天学习用森林图展示COX生存分析

1.数据准备
setwd("E:\\MATH")
load('clin.LIHC.Rdata')
df<-subset(clin.LIHC,select =c(submitter_id,vital_status,days_to_death,days_to_last_follow_up,age_at_diagnosis,weight,height,gender))
df2 <- df
# 将status表示患者结局,1表示删失,2表示死亡
df2[df2$vital_status=='Dead',]$vital_status <- 2
df2[df2$vital_status=='Alive',]$vital_status <- 1
df2$vital_status <- as.numeric(df2$vital_status)

#将 days_to_death 和 days_ to_last_follow_up 合并为一列
df2$time <- df2$days_to_death
df2$time[which(is.na(df2$time))] <- df2$days_to_last_follow_up[which(is.na(df2$time))]
df2$age=df2$age_at_diagnosis/365#把日变成年
#colnames(meta)=c('ID','event','race','age','gender','stage',"days")#改变取出的几组的名字

数据格式如下


df1.png
2.构建COX回归模型

对LIHC队列进行Cox回归分析,时间变量是time,结局变量是status,自变量选择 age和gender,结果如下:

library(survival)
library(survminer)
model <- coxph( Surv(time, vital_status) ~ gender + age , data =  df2 )
model
#Call:
#coxph(formula = Surv(time, vital_status) ~ gender + age, data = df2)

#                coef exp(coef)  se(coef)      z     p
#gendermale -0.131112  0.877120  0.186485 -0.703 0.482
#age         0.009764  1.009812  0.007088  1.377 0.168

#Likelihood ratio test=3.03  on 2 df, p=0.2197
#n= 372, number of events= 130 
#   (5 observations deleted due to missingness)

结果不显著,但是我们仍然可以绘制森林图。

3.绘制森林图
#基础森林图
ggforest(model, data = df2)
#优化森林图
model <- coxph( Surv(time, vital_status) ~ gender + age , data =  df2 )
ggforest(model,  #coxph得到的Cox回归结果
         data = df2,  #数据集
         main = 'Hazard ratio of LIHC',  #标题
         cpositions = c(0.01, 0.15, 0.35),  #前三列距离,从前往后看
         fontsize = 1, #字体大小
         refLabel = 'reference', #相对变量的数值标签,也可改为1
         noDigits = 3 #保留HR值以及95%CI的小数位数
)
基础森林图.png

优化森林图.png

方法很重要,可以依葫芦画瓢。
参考文章:Forest plot(森林图) | Cox生存分析可视化

你可能感兴趣的:(Cox生存分析可视化-Forest plot(森林图) |)