R生存分析AFT

Posted 智能先行者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R生存分析AFT相关的知识,希望对你有一定的参考价值。

1. Surv

Description

创建一个生存对象,通常用作模型公式中的响应变量。 参数匹配是此功能的特殊功能,请参阅下面的详细信息。

Surv(time, time2, event,
    type=c(‘right‘, ‘left‘, ‘interval‘, ‘counting‘, ‘interval2‘, ‘mstate‘),
    origin=0)
is.Surv(x)

Arguments
time
对于右删失数据,这是一个跟踪时间。对于区间数据,第一个参数是区间的开始时间。 
event 
状态指示,通常,0=活着,1=死亡。其他选择是TRUE/FALSE (TRUE = 死亡) or 1/2 (2=死亡)。对于区间删失数据,状态指示,0=右删失, 1=事件时间, 2=左删失, 3=区间删失.
右删失(Right Censoring):只知道实际寿命大于某数;
左删失(Left Censoring):只知道实际寿命小于某数;
区间删失(Interval Censoring):只知道实际寿命在一个时间区间内。
time2 
区间删失区间的结束时间或仅对过程数据进行计数。
type 
指定删失类型。 "right", "left", "counting", "interval", "interval2" or "mstate".
如果event变量是一个因子,假定type="mstate"。如果没有指定参数time2,type="right";如果指定参数time2,type="counting" 

 

Surv使用示例

> str(lung)
‘data.frame‘:	228 obs. of  10 variables:
 $ inst     : num  3 3 3 5 1 12 7 11 1 7 ...
 $ time     : num  306 455 1010 210 883 ...
 $ status   : num  2 2 1 2 2 1 2 2 2 2 ...
 $ age      : num  74 68 56 57 60 74 68 71 53 61 ...
 $ sex      : num  1 1 1 1 1 1 2 2 1 1 ...
 $ ph.ecog  : num  1 0 0 1 0 1 2 2 1 2 ...
 $ ph.karno : num  90 90 90 90 100 50 70 60 70 70 ...
 $ pat.karno: num  100 90 90 60 90 80 60 80 80 70 ...
 $ meal.cal : num  1175 1225 NA 1150 NA ...
 $ wt.loss  : num  NA 15 15 11 0 0 10 1 16 34 ...
> with(lung, Surv(time, status))
  [1]  306   455  1010+  210   883  1022+  310   361   218 
 [10]  166   170   654   728    71   567   144   613   707 
 [19]   61    88   301    81   624   371   394   520   574 
 [28]  118   390    12   473    26   533   107    53   122 
 [37]  814   965+   93   731   460   153   433   145   583 
 [46]   95   303   519   643   765   735   189    53   246 
 [55]  689    65     5   132   687   345   444   223   175 
 [64]   60   163    65   208   821+  428   230   840+  305 
 [73]   11   132   226   426   705   363    11   176   791 
 [82]   95   196+  167   806+  284   641   147   740+  163 
 [91]  655   239    88   245   588+   30   179   310   477 
[100]  166   559+  450   364   107   177   156   529+   11 
[109]  429   351    15   181   283   201   524    13   212 
[118]  524   288   363   442   199   550    54   558   207 
[127]   92    60   551+  543+  293   202   353   511+  267 
[136]  511+  371   387   457   337   201   404+  222    62 
[145]  458+  356+  353   163    31   340   229   444+  315+
[154]  182   156   329   364+  291   179   376+  384+  268 
[163]  292+  142   413+  266+  194   320   181   285   301+
[172]  348   197   382+  303+  296+  180   186   145   269+
[181]  300+  284+  350   272+  292+  332+  285   259+  110 
[190]  286   270    81   131   225+  269   225+  243+  279+
[199]  276+  135    79    59   240+  202+  235+  105   224+
[208]  239   237+  173+  252+  221+  185+   92+   13   222+
[217]  192+  183   211+  175+  197+  203+  116   188+  191+
[226]  105+  174+  177+


> str(heart)
‘data.frame‘:	172 obs. of  8 variables:
 $ start     : num  0 0 0 1 0 36 0 0 0 51 ...
 $ stop      : num  50 6 1 16 36 39 18 3 51 675 ...
 $ event     : num  1 1 0 1 0 1 1 1 0 1 ...
 $ age       : num  -17.16 3.84 6.3 6.3 -7.74 ...
 $ year      : num  0.123 0.255 0.266 0.266 0.49 ...
 $ surgery   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ transplant: Factor w/ 2 levels "0","1": 1 1 1 2 1 2 1 1 1 2 ...
 $ id        : num  1 2 3 3 4 4 5 6 7 7 ...
> Surv(heart$start, heart$stop, heart$event)
  [1] (  0.0,  50.0]  (  0.0,   6.0]  (  0.0,   1.0+]
  [4] (  1.0,  16.0]  (  0.0,  36.0+] ( 36.0,  39.0] 
  [7] (  0.0,  18.0]  (  0.0,   3.0]  (  0.0,  51.0+]
 [10] ( 51.0, 675.0]  (  0.0,  40.0]  (  0.0,  85.0] 
 [13] (  0.0,  12.0+] ( 12.0,  58.0]  (  0.0,  26.0+]
 [16] ( 26.0, 153.0]  (  0.0,   8.0]  (  0.0,  17.0+]
 [19] ( 17.0,  81.0]  (  0.0,  37.0+] ( 37.0,1387.0] 
 [22] (  0.0,   1.0]  (  0.0,  28.0+] ( 28.0, 308.0] 
 [25] (  0.0,  36.0]  (  0.0,  20.0+] ( 20.0,  43.0] 
 [28] (  0.0,  37.0]  (  0.0,  18.0+] ( 18.0,  28.0] 
 [31] (  0.0,   8.0+] (  8.0,1032.0]  (  0.0,  12.0+]
 [34] ( 12.0,  51.0]  (  0.0,   3.0+] (  3.0, 733.0] 
 [37] (  0.0,  83.0+] ( 83.0, 219.0]  (  0.0,  25.0+]
 [40] ( 25.0,1800.0+] (  0.0,1401.0+] (  0.0, 263.0] 
 [43] (  0.0,  71.0+] ( 71.0,  72.0]  (  0.0,  35.0] 
 [46] (  0.0,  16.0+] ( 16.0, 852.0]  (  0.0,  16.0] 
 [49] (  0.0,  17.0+] ( 17.0,  77.0]  (  0.0,  51.0+]
 [52] ( 51.0,1587.0+] (  0.0,  23.0+] ( 23.0,1572.0+]
 [55] (  0.0,  12.0]  (  0.0,  46.0+] ( 46.0, 100.0] 
 [58] (  0.0,  19.0+] ( 19.0,  66.0]  (  0.0,   4.5+]
 [61] (  4.5,   5.0]  (  0.0,   2.0+] (  2.0,  53.0] 
 [64] (  0.0,  41.0+] ( 41.0,1408.0+] (  0.0,  58.0+]
 [67] ( 58.0,1322.0+] (  0.0,   3.0]  (  0.0,   2.0] 
 [70] (  0.0,  40.0]  (  0.0,   1.0+] (  1.0,  45.0] 
 [73] (  0.0,   2.0+] (  2.0, 996.0]  (  0.0,  21.0+]
 [76] ( 21.0,  72.0]  (  0.0,   9.0]  (  0.0,  36.0+]
 [79] ( 36.0,1142.0+] (  0.0,  83.0+] ( 83.0, 980.0] 
 [82] (  0.0,  32.0+] ( 32.0, 285.0]  (  0.0, 102.0] 
 [85] (  0.0,  41.0+] ( 41.0, 188.0]  (  0.0,   3.0] 
 [88] (  0.0,  10.0+] ( 10.0,  61.0]  (  0.0,  67.0+]
 [91] ( 67.0, 942.0+] (  0.0, 149.0]  (  0.0,  21.0+]
 [94] ( 21.0, 343.0]  (  0.0,  78.0+] ( 78.0, 916.0+]
 [97] (  0.0,   3.0+] (  3.0,  68.0]  (  0.0,   2.0] 
[100] (  0.0,  69.0]  (  0.0,  27.0+] ( 27.0, 842.0+]
[103] (  0.0,  33.0+] ( 33.0, 584.0]  (  0.0,  12.0+]
[106] ( 12.0,  78.0]  (  0.0,  32.0]  (  0.0,  57.0+]
[109] ( 57.0, 285.0]  (  0.0,   3.0+] (  3.0,  68.0] 
[112] (  0.0,  10.0+] ( 10.0, 670.0+] (  0.0,   5.0+]
[115] (  5.0,  30.0]  (  0.0,  31.0+] ( 31.0, 620.0+]
[118] (  0.0,   4.0+] (  4.0, 596.0+] (  0.0,  27.0+]
[121] ( 27.0,  90.0]  (  0.0,   5.0+] (  5.0,  17.0] 
[124] (  0.0,   2.0]  (  0.0,  46.0+] ( 46.0, 545.0+]
[127] (  0.0,  21.0]  (  0.0, 210.0+] (210.0, 515.0+]
[130] (  0.0,  67.0+] ( 67.0,  96.0]  (  0.0,  26.0+]
[133] ( 26.0, 482.0+] (  0.0,   6.0+] (  6.0, 445.0+]
[136] (  0.0, 428.0+] (  0.0,  32.0+] ( 32.0,  80.0] 
[139] (  0.0,  37.0+] ( 37.0, 334.0]  (  0.0,   5.0] 
[142] (  0.0,   8.0+] (  8.0, 397.0+] (  0.0,  60.0+]
[145] ( 60.0, 110.0]  (  0.0,  31.0+] ( 31.0, 370.0+]
[148] (  0.0, 139.0+] (139.0, 207.0]  (  0.0, 160.0+]
[151] (160.0, 186.0]  (  0.0, 340.0]  (  0.0, 310.0+]
[154] (310.0, 340.0+] (  0.0,  28.0+] ( 28.0, 265.0+]
[157] (  0.0,   4.0+] (  4.0, 165.0]  (  0.0,   2.0+]
[160] (  2.0,  16.0]  (  0.0,  13.0+] ( 13.0, 180.0+]
[163] (  0.0,  21.0+] ( 21.0, 131.0+] (  0.0,  96.0+]
[166] ( 96.0, 109.0+] (  0.0,  21.0]  (  0.0,  38.0+]
[169] ( 38.0,  39.0+] (  0.0,  31.0+] (  0.0,  11.0+]
[172] (  0.0,   6.0] 

 

2.survreg

拟合参数生存回归模型。 这些是用于时间变量的任意变换的位置尺度模型; 最常见的情况使用对数变换,建立加速失效时间模型。

survreg(formula, data, weights, subset,
        na.action, dist="weibull", init=NULL, scale=0,
        control,parms=NULL,model=FALSE, x=FALSE,
        y=TRUE, robust=FALSE, score=FALSE, ...)
  
dist
y变量的假设分布。"weibull", "exponential", "gaussian", "logistic","lognormal" and "loglogistic"。

scale 
可选的固定值。如果设置<=0,scale将被估计

control 
控制值列表,参考survreg.control()

以上是关于R生存分析AFT的主要内容,如果未能解决你的问题,请参考以下文章

视频R语言生存分析原理与晚期肺癌患者分析案例|数据分享|附代码数据

R语言生存分析之 Kaplan-Meier估计log-rank检验cox回归寿命表代码示例

拓端tecdat|R语言辅导解释生存分析中危险率和风险率的变化

R语言生存分析(survival analysis)与生存资料有关的概念详解

R生存分析 - KM曲线 ,值得拥有姓名和颜值

R|生存分析 - KM曲线 ,值得拥有姓名和颜值