生存包中的survexp函数以错误结尾

时间:2019-08-01 10:59:05

标签: r survival-analysis

我将survexp与两个数据集一起使用。研究组(来自生存软件包的mgus数据集)和比率表(也来自生存软件包的survexp.us)。

不幸的是,函数调用以错误结束:

> library("survival")

> mgus2=mgus

> mgus2$dxyr =  as.character(mgus2$dxyr+1900)

> head(mgus2)
  id age    sex dxyr pcdx pctime futime death alb creat  hgb mspike
1  1  78 female 1968 <NA>     NA    748     1 2.8   1.2 11.5    2.0
2  2  73 female 1966   LP   1310   6751     1  NA    NA   NA    1.3
3  3  87   male 1968 <NA>     NA    277     1 2.2   1.1 11.2    1.3
4  4  86   male 1969 <NA>     NA   1815     1 2.8   1.3 15.3    1.8
5  5  74 female 1968 <NA>     NA   2587     1 3.0   0.8  9.8    1.4
6  6  81   male 1968 <NA>     NA    563     1 2.9   0.9 11.5    1.8
> 

        > fite <- survexp(Surv(futime, death) ~ 1, data=mgus2, ratetable=survexp.us, 
        +                 rmap=list(age=age*365.25, sex=c("female", "male"), year=dxyr))


    Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
          arguments imply differing number of rows: 241, 2

是否有必要例如以某种方式准备数据集mgus以便与上面的survexp函数一起使用?

2 个答案:

答案 0 :(得分:0)

由于将性别变量包含在“ rmap”列表中而重新定义了性别变量,因此出现了错误:sex=c("female", "male"),

一旦删除了看似不必要的重新定义,您将得到一个非常有用的进一步错误:

 fite <- survexp(Surv(futime, death) ~ 1, data=mgus2, ratetable=survexp.us, rmap=list( year=dxyr))
Error in match.ratetable(rdata, ratetable) : 
  for this ratetable, year must be a continuous variable

您可以保留年龄变量的重定义(上面未列出),但是只有数字为year(或更确切地说,dxyr)才能成功:

mgus2$dxyr =  mgus2$dxyr+1900
fite <- survexp(Surv(futime, death) ~ 1, data=mgus2, 
                 ratetable=survexp.us, rmap=list(age=age*365.25, year=dxyr))

> str(fite)
List of 6
 $ call  : language survexp(formula = Surv(futime, death) ~ 1, data = mgus2, rmap = list(age = age * 365.25, year = dxyr),      ratet| __truncated__
 $ surv  : num [1:237] 0.999 0.999 0.997 0.997 0.996 ...
 $ n.risk: int [1:237] 241 240 239 238 237 236 235 233 232 231 ...
 $ time  : num [1:237] 6 7 31 32 39 60 61 152 153 174 ...
 $ summ  : chr "  age ranges from 34 to 90 years\n  male: 137  female: 104 \n  date of entry from 1975-05-11 to 1975-05-28 \n"
 $ method: chr "cohort"
 - attr(*, "class")= chr [1:2] "survexp" "survfit"

summary(fite, times=(0:30)*365.24)
Call: survexp(formula = Surv(futime, death) ~ 1, data = mgus2, rmap = list(age = age * 
    365.25, year = dxyr), ratetable = survexp.us)

  time n.risk survival
     0    241    1.000
   365    227    0.967
   730    218    0.941
  1096    210    0.904
  1461    205    0.873
  1826    193    0.841
  2191    187    0.815
  2557    176    0.787
  2922    168    0.754
  3287    155    0.730
  3652    149    0.706
  4018    143    0.677
  4383    134    0.649
  4748    129    0.624
  5113    117    0.601
  5479    105    0.583
  5844    100    0.558
  6209     87    0.536
  6574     82    0.518
  6940     73    0.497
  7305     69    0.481
  7670     67    0.464
  8035     63    0.443
  8401     58    0.427
  8766     53    0.410
  9131     44    0.391
  9496     40    0.378
  9861     35    0.360
 10227     32    0.345
 10592     30    0.331
 10957     28    0.316

答案 1 :(得分:0)

非常感谢您的帮助。 ?survexp的一个例子错误地建议了我,并给出了性别而不是一个例子。

Examples

# 
# Stanford heart transplant data
#  We don't have sex in the data set, but know it to be nearly all males.
# Estimate of conditional survival  
fit1 <- survexp(futime ~ 1, rmap=list(sex="male", year=accept.dt,   
          age=(accept.dt-birth.dt)), method='conditional', data=jasa)
...