生存分析和可视化

・9 分钟阅读

  • 源代码名称: survminer
  • 源代码网址: https://www.github.com/kassambara/survminer
  • survminer的文档
  • survminer的源代码下载
  • Git URL:
    git://www.github.com/kassambara/survminer.git
  • Git Clone代码到本地:
    git clone https://www.github.com/kassambara/survminer
  • Subversion代码到本地:
    $ svn co --depth empty https://www.github.com/kassambara/survminer
                              Checked out revision 1.
                              $ cd repo
                              $ svn up trunk
              
  • Build StatusCRAN_Status_BadgeDownloadsTotal Downloads


    survminer :生存分析和可视化

    survminer R软件包提供了便利的生存分析和可视化功能。

    包中的主要功能按以下的方式组织在不同的类别中。

    生存曲线


    • ggsurvplot ():利用'number at risk'表,事件表的累计数量和被过滤的主体表的累计数绘制生存曲线。

    • arrange_ggsurvplots ():在同一页面上排列多个ggsurvplots 。

    • ggsurvevents ():绘制事件的时间分布。

    • surv_summary ():生存曲线总结,默认的summary ()函数相比,surv_summary ()创建一个数据帧,其中包含来自survfit结果的漂亮摘要。

    • surv_cutpoint ():一次确定一个或多个连续变量的最佳切点,提供与生存最显著关系对应的一个切点的值。

    • pairwise_survdiff ():生存曲线的多重比较,计算分组级别之间的配对比较,以及多个测试的更正。


    Cox模型诊断


    • ggcoxzph ():比例危害的图形测试,显示缩放的Schoenfeld残差图,以及使用ggplot2的平滑曲线,plot.cox.zph()的包装器。

    • ggcoxdiagnostics ():显示诊断图表显示cr比例危险模型的良好。

    • ggcoxfunctional ():显示关于零cox比例危险模型鞅残差的连续解释变量的图,cox模型中连续变量的函数形式的正确选取。


    Cox模型综述


    • ggforest ():绘制CoxPH模型的forest plot 。

    • ggcoxadjustedcurves ():绘制coxph模型的调整生存曲线。


    竞争风险


    • ggcompetingrisks ():绘制竞争风险的累积关联曲线,

    有关更多信息,请访问,并查看survminer包中每个函数的文档和使用例子。

    安装和加载

    按以下的方式从CRAN安装:

    install.packages("survminer")

    或者,从gitHub 位置安装最新版本:

    if(!require(devtools)) install.packages("devtools")devtools::install_github("kassambara/survminer", build_vignettes=FALSE)

    加载survminer :

    library("survminer")

    ggsurvplot :绘制生存曲线

    拟合生存曲线

    require("survival")fit<- survfit(Surv(time, status) ~sex, data=lung)

    基本图

    ggsurvplot(fit, data=lung)

    审查形状可按以下的方式更改:

    ggsurvplot(fit, data=lung, censor.shape="|", censor.size=4)

    自定义生存曲线

    ggsurvplot(
     fit, 
     data=lung, 
     size=1, # change line sizepalette= 
     c("#E7B800", "#2E9FDF"),# custom color palettesconf.int=TRUE, # Add confidence intervalpval=TRUE, # Add p-valuerisk.table=TRUE, # Add risk tablerisk.table.col="strata",# Risk table color by groupslegend.labs= 
     c("Male", "Female"), # Change legend labelsrisk.table.height=0.25, # Useful to change when you have multiple groupsggtheme= theme_bw() # Change ggplot2 theme)

    注意,还有其他参数可以自定义主标题,轴标签,字形,轴限制,图例和危险表的编号。

    更定制的生存曲线

    关注xlimbreak.time.by参数,这些参数不改变生存surves估计的计算,同时,在风险表图例的文本注释中,提供提供栏而不是名称的risk.table.y.text.col =TRUErisk.table.y.text =FALSE

    ggsurvplot(
     fit, # survfit object with calculated statistics.data=lung, # data used to fit survival curves.risk.table=TRUE, # show risk table.pval=TRUE, # show p-value of log-rank test.conf.int=TRUE, # show confidence intervals for # point estimates of survival curves.xlim= c(0,500), # present narrower X axis, but not affect# survival estimates.xlab="Time in days", # customize X axis label.break.time.by=100, # break X axis in time intervals by 500.ggtheme= theme_light(), # customize plot and risk table with a theme.risk.table.y.text.col=T, # colour risk table text annotations.risk.table.y.text=FALSE# show bars instead of names in text annotations# in legend of risk table)

    定制生存曲线

    ggsurv<- ggsurvplot(
     fit, # survfit object with calculated statistics.data=lung, # data used to fit survival curves.risk.table=TRUE, # show risk table.pval=TRUE, # show p-value of log-rank test.conf.int=TRUE, # show confidence intervals for # point estimates of survival curves.palette= c("#E7B800", "#2E9FDF"),
     xlim= c(0,500), # present narrower X axis, but not affect# survival estimates.xlab="Time in days", # customize X axis label.break.time.by=100, # break X axis in time intervals by 500.ggtheme= theme_light(), # customize plot and risk table with a theme.risk.table.y.text.col=T,# colour risk table text annotations.risk.table.height=0.25, # the height of the risk tablerisk.table.y.text=FALSE,# show bars instead of names in text annotations# in legend of risk table.ncensor.plot=TRUE, # plot the number of censored subjects at time tncensor.plot.height=0.25,
     conf.int.style="step", # customize style of confidence intervalssurv.median.line="hv", # add the median survival pointer.legend.labs= 
     c("Male", "Female") # change legend labels. )ggsurv

    Uber platinum定制生存曲线

    # Changing Labels# %%%%%%%%%%%%%%%%%%%%%%%%%%# Labels for Survival Curves (plot)ggsurv$plot<-ggsurv$plot+ labs(
     title="Survival curves", 
     subtitle="Based on Kaplan-Meier estimates", 
     caption="created with survminer" 
     )# Labels for Risk Table ggsurv$table<-ggsurv$table+ labs(
     title="Note the risk set sizes", 
     subtitle="and remember about censoring.", 
     caption="source code: website.com" 
     )# Labels for ncensor plot ggsurv$ncensor.plot<-ggsurv$ncensor.plot+ labs( 
     title="Number of censorings", 
     subtitle="over the time.",
     caption="source code: website.com" )# Changing the font size, style and color# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# Applying the same font style to all the components of ggsurv:# survival curves, risk table and censor partggsurv<- ggpar(
     ggsurv,
     font.title= c(16, "bold", "darkblue"), 
     font.subtitle= c(15, "bold.italic", "purple"), 
     font.caption= c(14, "plain", "orange"), 
     font.x= c(14, "bold.italic", "red"), 
     font.y= c(14, "bold.italic", "darkred"), 
     font.xtickslab= c(12, "plain", "darkgreen"),
     legend="top")ggsurv

    Uber platinum premium保费定制生存曲线

    # Using specific fonts for risk table and ncensor plots#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# Font for Risk Tableggsurv$table<- ggpar(
     ggsurv$table,
     font.title= c(13, "bold.italic", "green"),
     font.subtitle= c(15, "bold", "pink"),
     font.caption= c(11, "plain", "darkgreen"),
     font.x= c(8, "bold.italic", "orange"),
     font.y= c(11, "bold.italic", "darkgreen"),
     font.xtickslab= c(9, "bold", "red")
    )# Font for ncensor plotggsurv$ncensor.plot<- ggpar(
     ggsurv$ncensor.plot,
     font.title= c(13, "bold.italic", "green"),
     font.subtitle= c(15, "bold", "pink"),
     font.caption= c(11, "plain", "darkgreen"),
     font.x= c(8, "bold.italic", "orange"),
     font.y= c(11, "bold.italic", "darkgreen"),
     font.xtickslab= c(9, "bold", "red")
    )
    print(ggsurv)

    讨论
    Fansisi profile image