0

I have a question about generating survival time using 'survreg' in R. First, using current data and 'survreg' function with weibull distribution, I did estimate weibull parameters(shape and scale) and beta for X. Then, I generated new survival time using those parameters. But, new generated survival time and existing survival time are different a lot. I show some of my r code for this.


##initial parameter
  wei.par <- survreg(Surv(t,cens) ~ x1+x2+x3, data=data, dist="weibull")
  a <- 1/wei.par$scale                 #shape parm
  b <- exp(wei.par$coefficients[1])    #scale parm
  par.vec <- coef(wei.par)[2:4]        #beta parameters for x1-x3


##Generate random uniform number needed to generate time to events  
  u <- runif(nrow(data))

##Generate time to events using Cox's PH model with Weibull baseline hazards
  data$t1 <- b*(-log(1-u)*exp(as.matrix(data[,c(2:4)]) %*% as.matrix(par.vec)))^(1/a)

I saw some code for new generated time (t1) below. t2 <- b * ( -ln( 1-runif(1000) ) ) ^(1/a) or

t2 <- (-log(1-u)/exp(as.matrix(x) %*% as.matrix(surv.coef)))^(1/b)*a^-1
B--rian
  • 5,578
  • 10
  • 38
  • 89
Matt Lee
  • 1
  • 1
  • I saw some code for new generated time (t1) below. `t2 <- b * ( -ln( 1-runif(1000) ) ) ^(1/a)` or `t2 <- (-log(1-u)/exp(as.matrix(x) %*% as.matrix(surv.coef)))^(1/b)*a^-1` – Matt Lee Nov 27 '17 at 20:16
  • 1
    Use [edit] facilities to add information to questions. Look at documentation for survfit to see how Therneau handle Weibull parameters. – IRTFM Nov 27 '17 at 20:22

0 Answers0