问题
I try to estimate mle parameters of a generalised gamma distribution.
I use optim function with a lower bound equal to one (since parameters must be positive) and BFGS method.
Initially, I estimate the log likelihood function as below:
negloglikgengamma<-function(thet,dat) {
alpha<-thet[1]
kappa<-thet[2]
lamda<-thet[3]
-sum(dggamma(y,scale=alpha,shape1=kappa,shape2=lamda,log=T))
}
I use minus log likelihood function in order to use "optim" and find the minimum.
Then I use optim function.
fitggamma<-optim(c(0.4,0.5,2),negloglikgengamma,hessian=TRUE,method="L-BFGS- B",dat=y,lower=1)
The results are:
$par
[1] 1.000000 1.000000 2.165561
$value
[1] -0.1214229
$counts
function gradient
6 6
$convergence
[1] 0
$message
[1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"
$hessian
[,1] [,2] [,3]
[1,] -9.998753e-01 1.0000003 -2.924863e-05
[2,] 1.000000e+00 1.2063171 -9.530030e-02
[3,] -2.924863e-05 -0.0953003 4.402082e-02
I am trying to estimate s.e. and I notice that Var(alpha)=-9.998753e-01 <0. Why is this happening? What I should change?
来源:https://stackoverflow.com/questions/59951587/why-do-i-get-negative-variance-from-hessian-matrix-in-optim-function