I am trying to get the Maximum Likelihood Estimators of the log-likelihood of a Gumbel distribution for survival analysis(i say that so that you dont get astranged by the log-likelihood function, i think its correct). In order to do that i have to maximize the minus log-likelihood by using the optim function, i tried to do so but the console is giving me an Error in fn(par, ...) : argument "b" is missing, with no default.
I tried also to do it in a similar way as in the answer to this link: Solve for maximum likelihood with two parameters under constraints ,but the console game me the following: Error in optim(c(1, 1), function(x) log_lhood(x[1], x[2], d = lung$status, : objective function in optim evaluates to length 0 not 1.
log_lhood <- function(m,b,d,t){
sum<-0
for (i in 1:length(lung)){
if (d[i] == 1){
sum<- sum - log(1-exp(-exp(-(t[i]-m)/b)))
} else {
sum<- sum - log((1/b)*exp(-(t[i]-m/b+exp(-(t[i]-m/b)))))
}
}
}
#a,b parameter optimization
optim(c(0,0), fn = log_lhood, d = lung$status, t = KM_fit$time) #1st way
optim(c(1, 1), function(x) log_lhood(x[1], x[2],d=lung$status,t=KM_fit_test$time)) #2nd way as in the link
lung
from a package? – Evan Friedland