r - Kaplan-Meier 包括生存和移植数据

标签 r survival-analysis

我拥有的是使用 R 对机械心脏支持患者进行的 Kaplan-Meier 分析。

我需要的是将以下数据添加到图中(如示例中所示):

  • 因心脏移植 (HTX) 而幸存的患者
  • 死亡患者

  • 换句话说,有两组,其中一组是另一组(所有患者)的子集(移植患者)。这两条曲线必须从 0/0 开始并且会增加。

    我自己的情节是由:
    pump <- read.table(file=datafile, header=FALSE,
                       col.names=c('TIME', 'CENSUS', 'DEVICE'))
    # convert days to months
    pump$TIME <- pump$TIME/(730/24)
    mfit.overall <- survfit(Surv(TIME, CENSUS==0) ~ 1, data=pump)
    plot(mfit.overall, xlab="months on device", ylab="cum. survival", xaxt="n")
    axis(1, at=seq(from=0, to=24, by=6), las=0)
    

    如何添加两条附加曲线?

    亲切的问候
    约翰

    样本 Kaplan Meier 曲线:http://i.stack.imgur.com/158e8.jpg

    演示数据:

    生存数据,进入泵:

    TIME    CENSUS  DEVICE
    426     1       1
    349     1       1
    558     1       1
    402     1       1
    12      0       1
    84      0       1
    308     1       1
    174     1       1
    315     1       1
    734     1       1
    544     1       2
    1433    1       2
    1422    1       2
    262     1       2
    318     1       2
    288     1       2
    1000    1       2
    


    发送数据:

    TIME    CENSUS  DEVICE
    426     1        1
    288     1        2
    308     1        1
    


    死亡人数:

    TIME    CENSUS  DEVICE
    12      0        1
    84      0        1
    

    最佳答案

    par(new=TRUE)您可以在与第一个图形相同的图形中绘制第二个图形。

    通常我会推荐使用 lines()用于向绘图添加曲线,因为 par(new=TRUE)执行覆盖图的不同的任务。当以不打算使用的方式使用函数时,您可能会犯错误,例如我差点忘了重要的 xlim争论。然而,从 survfit 中提取曲线并非易事。对象,所以我认为这是两害相权取其轻的。

    # Fake data for the plots
    pump <- data.frame(TIME=rweibull(40, 2, 20),
                       CENSUS=runif(40) < .3,
                       DEVICE=rep(0:1, c(20,20)))
    # load package
    library("survival")
    
    # Fit models
    mfit.overall <-survfit(Surv(TIME, CENSUS==0) ~ 1, data=pump)
    mfit.htx <- survfit(Surv(TIME, CENSUS==0) ~ 1, data=pump, subset=DEVICE==1)
    
    # Plot
    plot(mfit.overall, col=1, xlim=range(pump$TIME), fun=function(x) 1-x)
    # `xlim` makes sure the x-axis is the same in both plots
    # `fun` flips the curve to start at 0 and increase
    par(new=TRUE)
    plot(mfit.htx, col=2, xlim=range(pump$TIME), fun=function(x) 1-x,
        ann=FALSE, axes=FALSE, bty="n") # This hides the annotations of the 2nd plot
    legend("topright", c("All", "HTX"), col=1:2, lwd=1)
    

    enter image description here

    关于r - Kaplan-Meier 包括生存和移植数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13359241/

    相关文章:

    R错误: could not find function is_empty

    r - 在 R 和 Sparklyr 中,将表写入 .CSV (spark_write_csv) 会生成许多文件,而不是一个文件。为什么?我可以改变这一点吗?

    r - 如何修复 R Shiny 中的 'Error: variable lengths differ (found for ' input$s')'

    r - 使用 randomForestSRC 在特定时间点的生存概率

    R icenReg 包 : Move plot legend for ic_np fit

    r - R-将数据帧列表合并到一个缺少行的值的数据帧中

    r - 包装 R 的绘图函数(或 ggplot2)以防止绘制大数据集

    r - 我可以在 R 中为 Cox 比例风险模型执行所有子集变量选择吗?

    r - 在R中的句点和数字之间插入字符串

    r - 仅访问生存对象的一部分