This is my data about insurance claim
claim | frequency |
---|---|
0 | 370412 |
1 | 46545 |
2 | 3935 |
3 | 317 |
4 | 28 |
5 | 3 |
I want to get the estimate value and also the parameters value using MLE
This is the loglikelihood function that I used
ll=((-t)(log(log(1-alpha))))+(sum(log(log((1-(alpha(theta^x)))/(1-(alpha*(theta^(x+1))))))))
I have run the code like this
x=c(rep(0,370412),rep(1,46545),rep(2,3935),rep(3,317),rep(4,28),rep(5,3))
t=length(x)
loglik=function(par) {
alpha=par[1]
theta=par[2]
ll=((-t)*(log(log(1-alpha))))+(sum(log(log((1-(alpha*(theta^x)))/(1-(alpha*(theta^(x+1))))))))
return(-ll)
}
optim(theta=c(1,0),loglik, x=x,hessian=TRUE,control=list(maxit=100000))
however there's an error message
Error in optim(theta = c(1, 0), loglik, x = x, hessian = TRUE, control = list(maxit = 1e+05)) :
cannot coerce type 'closure' to vector of type 'double'
In addition: Warning message:
In optim(theta = c(1, 0), loglik, x = x, hessian = TRUE, control = list(maxit = 1e+05)) :
one-dimensional optimization by Nelder-Mead is unreliable:
use "Brent" or optimize() directly