0

Rで生存関数の導関数を取り、それを新しい関数に保存しようとしています。

これまでの私のコードは次のとおりです。

install.packages("survival")
library(survival)
survival <- matrix(c(1, 555, 0, 82, 2, 473, 8, 30, 3, 435, 8, 27, 4, 400, 7, 22, 5,  
                   371, 7, 26, 6, 338, 28, 25, 7, 285, 31, 20,8, 234, 32, 11, 9, 191, 
                   24, 14, 10, 153, 27, 13, 11, 113, 22, 5, 12, 86, 23, 5, 13, 58, 18,
                   5, 14, 35, 9, 2, 15, 24, 7, 3, 16, 14, 11, 3), 
                   ncol=4, byrow=TRUE)
year <- c()
for (i in 1:nrow(survival) ) year <- c(year, rep(i, survival[i, 4]))
for (i in 1:nrow(survival) ) year <- c(year, rep(i, survival[i, 3]))
state <- c(rep(1, sum(survival[, 4])), rep(0, sum(survival[, 3])))
my.surv <- Surv(year, state)
fit <- survfit(my.surv ~ 1)
my.fit <- survfit(my.surv ~ 1)
### K-M plot
plot(my.fit, main="Kaplan-Meier estimate with 95% confidence bounds",
     xlab="time", ylab="survival function") 
### K-M cumulative hazard function
H.hat <- -log(my.fit$surv)
4

0 に答える 0