第十九章 生存分析

作者: x2yline | 来源:发表于2017-11-29 22:12 被阅读108次

    生存分析与cox回归

    # setwd('E:/医学统计学(第4版)/各章例题SPSS数据文件') data_19_2 <-
    # haven::read_sav('例19-02.sav') data_19_1 <- haven::read_sav('例19-01.sav') data_19_3 <-
    # haven::read_sav('例19-03.sav') data_19_5 <- haven::read_sav('例19-05.sav') save(data_19_2,
    # file='19_2.Rdata') save(data_19_5, file='19_5.Rdata')
    load(url("https://github.com/x2yline/Rdata/raw/master/mediacl_statistics/19_2.Rdata"))
    load(url("https://github.com/x2yline/Rdata/raw/master/mediacl_statistics/19_5.Rdata"))
    
    par(family = "simhei")
    library(survival)
    
    CPCOLS <- c("#FF0A58", "#AB9E9E")
    CPCOLS <- c("#F01641", "#A19999")
    
    ## 生存分析
    fit2 <- survfit(Surv(time, status) ~ group, data = data_19_2)
    plot(fit2, lty = c(1, 1), ylab = "生存率", xlab = "生存时间(月)", bty = "n", main = "生存曲线", 
        col = c(CPCOLS[1], CPCOLS[2]), lwd = 2, mark.time = T, mark = 19, cex = 1.1)
    
    legend(40, 1, c("甲种手术方式", "乙种手术方式", "删失"), lty = c(1, 1, NA), pch = c(NA, NA, 
        16), col = c(CPCOLS[1], CPCOLS[2], CPCOLS[1]), lwd = 2, bty = "n", cex = 0.8)
    
    
    生存分析曲线
    diff_sur <- survdiff(Surv(time, status) ~ group, data = data_19_2)
    pchisq(q = diff_sur$chisq, df = 1, lower.tail = FALSE)
    ## [1] 0.003089351
    
    ## http://sites.stat.psu.edu/~drh20/R/html/survival/html/plot.survfit.html
    
    
    ## cox回归分析
    fit5 = coxph(Surv(t, y) ~ X4 + X5, data = data_19_5)
    # plot(survfit( fit5))
    fit5.sum <- summary(fit5)
    fit5.sum[["coefficients"]]
    ##          coef exp(coef)  se(coef)         z    Pr(>|z|)
    ## X4 -1.7830043 0.1681323 0.5478848 -3.254342 0.001136555
    ## X5  0.9395114 2.5587308 0.4446201  2.113066 0.034595151
    

    相关文章

      网友评论

      • Thinkando:好快啊,都生存分析啦
        Thinkando:@x2yline 确实,我最近学的有些囫囵吞枣,需要会看仔细打磨一下,优秀如你~
        x2yline:@thinkando 哈哈,其实我们已经学到聚类了,但是贪多嚼不烂,高级统计学老师讲的也不多,以后还会到实战的时候会继续补充学习的,现在大致实现一下:joy:

      本文标题:第十九章 生存分析

      本文链接:https://www.haomeiwen.com/subject/jgxmbxtx.html