1

I encountered some issues when calculating restricted mean survival time (RMST) in R and I made some attempts.

Here is the idea that I tried to calculate the RMST by myself.

i) I fitted a cox regression model to get estimated function of h(t), and I deploy individual covariables to calculate individual h(t);

ii) I derived individual survival curve S(t) by the above individual h(t);

iii) I then calculated individual RMST by the above individual S(t) with the following formula: RMST = integrate(S(t)) by 0 to tau. (I don't know how to put a formal formula here and I am sure you can understand what I am saying).

I have tried the above method to calculate individual RMST with the following R code:

# load R package
library(survRM2)
library(survival)

# generate example
D <- rmst2.sample.data()
time <- D$time
status <- D$status
x <- D[,c(4,6,7)]

# fit cox regression model with weibull baseline
fit<-survreg(Surv(time,status)~ x[[1]] + x[[2]]+ x[[3]],data = D,dist = "weibull")

# get cox regression coefficients of covariables
beta=fit$coefficients

# get paramaters within baseline hazard
gamma.weibull=fit$scale

# cutomize a function to calculate individual hazard
hazard <- function(u,x1,x2,x3) {

  gamma.weibull*u^(gamma.weibull-1)*exp(beta[1]+beta[2]*x1+beta[3]*x2+beta[4]*x3)

}

# cutomize a function to calculate individual survival
surv <-function(t,x1,x2,x3) {

  sapply(t,function(z){
    exp(-integrate(hazard,lower=0,upper=z,x1=x1,x2=x2,x3=x3)$value)
    }
  )
}


rmst <- c() # genrate a empty vector
for(i in 1:312) { # 312 is the sample size

  rmst[i]=integrate(surv,0,5,x1=x[[1]][i],x2=x[[2]][i],x3=x[[3]][i])$value

}

# Error in integrate(surv, 0, 5, x1 = x[[1]][i], x2 = x[[2]][i], x3 = x[[3]][i]) : 
#   the integral is probably divergent

I have three questions:

1) Is there anything wrong about my idea or computational process?

2) In the step iii), there are some cases that integrals are non-integrable (that is, integrals do not converge). Is there any solution, or should I use approximate evaluation?

3) One last shoot, is there any better method to calculate this individual RMST?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sugus
  • 23
  • 4
  • Yeah thanks for this kind reminding. I have attached several lines of code to generate a example which derived from a R package, and I really hope that some one could give me a help! – Sugus Sep 04 '19 at 07:24

0 Answers0