Elodie Gillain
2013-Apr-11 15:11 UTC
[R] plotting the cumulative hazard function of a process whose intensity function is specified
I would like to simulate a stochastic process by specifying an intensity function, say lambda(t)=0.05 + 3 exp(鈭抰) I have the following code, but it has a number of problems. One issue I have is I do not know where the time variable is. I would appreciate your help with this code. library("survival") n <- 5000 lamc<-0.08 k1<-0.05 k2<-3 ld<-function(t){k1+k2} l<-function(t){k1+k2*exp(-t)} gendata<-function(n,lamc,k1,k2) { re<-rexp(5*n)/(k1+k2) ru<-runif(5*n) y<-rep(0,n) k<-1 for (i in 1:n){ u<-re[k] } while (ru[k] <l(u)/ld(u)){ k<-k+1 u<-u+re[k] y[i]<-u k<-k+1 } cen<-rexp(n,rate=lamc) } obj<-Surv(floor(pmin(y,cen)),ifelse(y<-cen,1,0)) u<-gendata(n,lamc,k1,k2) lsurv2<-survfit(Surv(floor(pmin(y,cen)) ~ x, data = u) plot(lsurv2,fun='cumhaz',xlab='temps',ylab='has',noconf) [[alternative HTML version deleted]]