代码+视频,超详细的R语言svykm函数绘制复杂抽样设计数据cox回归生存曲线(Kaplan-Meier)

发布时间:2024年01月11日

我们在既往的文章《R语言绘制复杂抽样设计数据cox回归生存曲线(Kaplan-Meier)》中介绍了怎么使用jskm包的svykm函数绘制复杂抽样设计数据cox回归生存曲线(Kaplan-Meier),今天来视频操作一下

在这里插入图片描述

超详细的R语言svykm函数绘制复杂抽样设计数据cox回归生存曲线(Kaplan-Meier)

代码

library(jskm)
library(survey)

#公众号回复:胆管炎数据,可以获得数据
pbc<-read.csv("E:/r/test/pbc.csv",sep=',',header=TRUE) 

# age:年龄,trt:治疗方案:1D-青霉烯,2安慰剂,edema:水肿, 
# status: 结局变量0/1/2表示审查、移植、死亡。

pbc$randomized <- with(pbc, !is.na(trt) & trt>0)
biasmodel <- glm(randomized~age*edema,data=pbc)
pbc$randprob <- fitted(biasmodel)


#生成预测值randprob后我们就可以正式分析了,我们先生成一个调查数据

dpbc <- svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))

s1 <- svykm(Surv(time,status>0)~sex, design=dpbc,se=T)

#绘图
svyjskm(s1)

#更改X轴,Y轴标签和标题
svyjskm(s1,xlabs = "时间",ylabs = "生存率",main = "时间与生存率关系图")

#对图例进行修改
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",ystratalabs=c("男","女"))

#对X轴的范围进行限制,对Y轴也是一样的
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),xlims=c(0,3000))

#把Y轴改成以百分比显示
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),surv.scale="percent")

#更改显示的时间轴点数,默认是6个点
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700)

#在图中生成P值
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T)

#调整文中P值的位置和字体的大小
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,pval.coord=c(1000,0.4),pval.size=8)

#添加Log-rank进P值后面
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T)

#调整图例位置
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,legendposition=c(0.6,0.8))

#不显示图例
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,legendposition=c(0.6,0.8),legend=F)

#更换色彩风格,默认是Set1
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,linecols="Set2")

#dashed设置虚线,好像只能设置一条
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,linecols="Set2",dashed=T)

#显示累积发生率函数
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,linecols="Set2",cumhaz=T)

#调用ggpubr::ggarrange函数来形成表格,给了我不少启发
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,linecols="Set2",table=T)

#修改表格下面的副标题名字
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=,
        linecols="Set2",table=T,label.nrisk="生存人数")

#设置Numbers at risk字体大小,默认是10
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,
        linecols="Set2",table=T,label.nrisk="生存人数",size.label.nrisk=12)

#给曲线加上百分比显示
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,
        linecols="Set2",table=T,label.nrisk="生存人数",size.label.nrisk=12,showpercent = T)

#cut.landmark是设置一个新的地标
svyjskm(s1,xlabs = "时间",ylabs = "生存率",ystrataname = "性别",
        ystratalabs=c("男","女"),timeby=700,pval=T,
        pval.coord=c(1000,0.4),pval.testname=T,
        linecols="Set2",table=T,label.nrisk="生存人数",size.label.nrisk=12,showpercent = T,cut.landmark=2100)



文章来源:https://blog.csdn.net/dege857/article/details/135518722
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。