2016-07-01 3 views
0

R에서 'relsurv'패키지를 사용하여 일대일 생존과 국가 생명표를 비교하려고합니다. 아래의 코드는 내 문제를 relsurv의 예제를 사용하지만 생명표 데이터를 변경하여 보여줍니다. 나는 2 년과 2 세의 수명 표를 아래의 생명 표 데이터에서 사용했다. 실제 데이터는 훨씬 크지 만 같은 오류가 발생한다. 오류는 '잘못된 ratetable 인수'이지만 예제 life-tables 'slopop'및 'survexp.us'에 따라 형식을 지정했습니다.생존 분석에 사용할 생명표 작성

library(survival) 
library(relsurv) 
data(rdata) # example data from relsurv 
raw = read.table(header=T, stringsAsFactors = F, sep=' ', text=' 
Year Age sex qx 
1980 30 1 0.00189 
1980 31 1 0.00188 
1981 30 1 0.00191 
1981 31 1 0.00191 
1980 30 2 0.00077 
1980 31 2 0.00078 
1981 30 2 0.00076 
1981 31 2 0.00074 
') 

ages = c(30,40) # in years 
years = c(1980, 1990) 
rtab = array(data=NA, dim=c(length(ages), 2, length(years))) # set up blank array: ages, sexes, years 
for (y in unique(raw$Year)){ 
    for (s in 1:2){ 
    rtab[ , s, y-min(years)+1] = -1 * log(1-subset(raw, Year==y&sex==s)$qx)/365.24 # probability of death in next year, transformed to hazard (see ratetables help) 
    } 
} 
attributes(rtab)$dimnames[[1]] = as.character(ages) 
attributes(rtab)$dimnames[[2]] = c('male','female') 
attributes(rtab)$dimnames[[3]] = as.character(years) 
attributes(rtab)$dimid <- c("age", "sex", 'year') 
attributes(rtab)$dim <- c(length(ages), 2, length(years)) 
attributes(rtab)$factor = c(0,0,1) 
attributes(rtab)$type = c(2,1,4) 
attributes(rtab)$cutpoints[[1]] = ages*365.24 # must be in days 
attributes(rtab)$cutpoints[[2]] = NULL 
attributes(rtab)$cutpoints[[3]] = as.date(paste("1Jan", years, sep='')) # must be date 
attributes(rtab)$class = "ratetable" 

# example from relsurv 
rsmul(Surv(time,cens) ~ sex+as.factor(agegr)+ 
     ratetable(age=age*365.24, sex=sex, year=year), 
     data=rdata, ratetable=rtab, int=1) 

답변

0

relsurv 패키지의 transrate 기능을 사용하여 데이터를 다시 포맷 해보십시오. 그렇게하면 호환 가능한 데이터 세트를 얻을 수 있습니다.

감사합니다, 조쉬

0

세 가지 추가 : 당신은 attributes(rtab)$factor = c(0,1,0)을 설정해야

  1. , 성 (두 번째 차원) 요소이기 때문에 (즉, 시간이 지남에 따라 변경되지 않습니다).

  2. 무엇인가 유효한 요금 테이블인지 확인하는 좋은 방법은 is.ratetable() 기능을 사용하는 것입니다. is.ratetable(rtab, verbose = TRUE)은 무엇이 잘못되었는지를 나타내는 메시지를 반환합니다.

  3. 확인 verbose를 사용하지 않고 is.ratetable의 결과 때문에 것 유효 속도 테이블에 대한 거짓말.

이 나머지 내용은이 거짓말에 관한 것입니다.

type 속성이 지정되지 않은 경우 is.ratetablefactor 속성을 사용하여 계산합니다. 함수를 출력하면이 것을 볼 수 있습니다. 그러나, 그것은 그렇게 잘못하는 것 같습니다. type <- 1 * (fac == 1) + 2 * (fac == 0) + 4 * (fac > 0)을 사용합니다. 여기서 facattributes(rtab)$factor입니다.

는하지만 제공하는 것 경우 type 속성을 확인하는 다음 섹션, 유일한 유효한 값은 1, 2, 34 말합니다. 위 코드에서 1을 얻는 것은 불가능합니다.

예를 들어 relsurv 패키지와 함께 제공되는 slopop 래터 러블을 살펴 보겠습니다.

library(relsurv) 
data(slopop) 
is.ratetable(slopop) 
# [1] TRUE 

is.ratetable(slopop, verbose = TRUE) 
# [1] "wrong length for cutpoints 3" 

나는 이것이 귀하의 요금 테이블이 끊어진 곳이라고 생각합니다.