MLE simulation data for survival analysis covariate in R

82 Views Asked by At

I was trying to do simulation on mle for my model which is a parallel exponential model to estimate the covariate which is b0 and b1. t and x I got generate using random numbers.

My pdf is f(t) = 2 * (lambda * exp(-lambda * t)) * (1- exp(-lambda * t))^2 The lambda is the covariate. lambda = b0 + b1*x

 n=20
 u<- runif(n,0,1)
 x<- rnorm(n,0,1)
 
 b0=2 ; b1=4
   t1= -log(1-sqrt(u))/(b0+b1*x) #inverse method
 
 c1<- rexp(n,0.01)
 c<- 1*(t1<c1)
 t= pmin(t1,c1)
 
 data1<-data.frame(x,t,t1,c1,c)
 
 
 #mle
 LLF<- function(para){
   set.seed(1)
   
   b0=para[1]
   b1=para[2]
   
   z1= log(2*(b0+b1*x)) - (b0+b1*x)*t + log(1-exp(-(b0+b1*x)*t))
   
   j=sum(z1)
   return(j)
 }
 mle<-maxLik(LLF,start = c(2,4))
Warning message:
In log(2 * (b0 + b1 * x)) : NaNs produced

How can I estimate MLE when I am using random numbers that include negative and log cannot compute negative numbers.

0

There are 0 best solutions below