Problems implementing MLE estimation in the bbmle package (for R)
I am trying to validate the MLEs for $\alpha$ , $\beta$ and $\lambda$ obtained for the Logistic-Lomax distribution by Zubair et al. in their paper titled A Study of Logistic-Lomax Distribution when using Dataset 1 . The paper uses the following code to do this (see Appendix B):
library(bbmle)
x <- c(66, 117, 132, 111, 107, 85, 89, 79, 91, 97, 138, 103, 111, 86, 78, 96, 93, 101, 102, 110, 95, 96, 88, 122, 115, 92, 137, 91, 84, 96, 97, 100, 105, 104, 137, 80, 104, 104, 106, 84, 92, 86, 104, 132, 94, 99, 102, 101, 104, 107, 99, 85, 95, 89, 102, 100, 98, 97, 104, 114, 111, 98, 99, 102, 91, 95, 111, 104, 97, 98, 102, 109, 88, 91, 103, 94, 105, 103, 96, 100, 101, 98, 97, 97, 101, 102, 98, 94, 100, 98, 99, 92, 102, 87 , 99, 62, 92, 100, 96, 98)
n <- length(x)
ll_LLx <- function(alpha, beta, lambda){
n*log(lambda*alpha/beta)-sum(log(1+x/beta))
-(lambda+1)*sum(log(log((1+x/beta)^alpha)))
-2*sum(log(1+(log((1+x/beta)^alpha))^(-lambda)))
}
mle.res <- mle2(ll_LLx, start=list(alpha=alpha, beta=beta, lambda=lambda),
hessian.opt=TRUE)
summary(mle.res)
The paper uses this code to obtain MLE values for this dataset $\hat{\alpha} = 0.5302, \hat{\beta} = 17.6331, \hat{\lambda} = 35.6364$ . My question is simple: how can I implement this code in R without generating errors? This code seems to list the parameters as "alpha", "beta", and "lambda", but doesn't assign them numerical starting values. So I try to set reasonable starting values for these parameters before the code, like this:
alpha=0.5
beta=17
lambda=35
However, this gives an unexpected error:
Error in optim(par = c(alpha = 0.5, beta = 17, lambda = 35), fn = function (p) :
non-finite finite-difference value [1]
In addition: There were 50 or more warnings (use warnings() to see the first 50)
What's going on here and how can I fix it?
There are two problems.
first
> alpha=0.53
> beta=17.6
> lambda=35.6
> ll_fragment<-function(alpha,beta,gamma) -2*sum(log(1+(log((1+x/beta)^alpha))^(-lambda)))
>
> ll_LLx(alpha,beta,gamma)
[1] -205.132
> ll_fragment(alpha,beta,gamma)
[1] -205.132
That is, the printing of the code introduces newlines, and when you copy the code from the PDF, you end up with a series of three expressions. The value returned by the function is the value of the last expression.
Second, if the code is compared to the log-likelihood defined in equation numbering... as defined in the unnumbered equation preceding equation 6.1, the equation begins with $n\log\frac{\lambda\alpha}{ \beta} $ . The code has n*log(lambda*alpha/beta)
. These look the same, but mle2
are minimal , so they should have opposite signs. The log-likelihood equation matches the pdf in equation 2.2, so I think it's correct and the code given will try to minimize the log-likelihood.
If I fix the newlines and flags I get
> mle.res <- mle2(ll1a, start=list(alpha=alpha, beta=beta, lambda=lambda),hessian=TRUE)
Warning messages:
1: In log(lambda * alpha/beta) : NaNs produced
2: In log(log((1 + x/beta)^alpha)) : NaNs produced
3: In log(lambda * alpha/beta) : NaNs produced
4: In log(log((1 + x/beta)^alpha)) : NaNs produced
5: In log(lambda * alpha/beta) : NaNs produced
6: In log(log((1 + x/beta)^alpha)) : NaNs produced
> summary(mle.res)
Maximum likelihood estimation
Call:
mle2(minuslogl = ll1a, start = list(alpha = alpha, beta = beta,
lambda = lambda), hessian.opts = TRUE)
Coefficients:
Estimate Std. Error z value Pr(z)
alpha 0.530499 0.018522 28.641 < 2.2e-16 ***
beta 17.649226 1.357944 12.997 < 2.2e-16 ***
lambda 35.636033 2.260395 15.765 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
-2 log L: 771.2541
Consistent with the paper.
That's why the code in the repository should be needed and not in the PDF, but even getting the code is a big step forward for this type of paper