Problems implementing MLE estimation in the bbmle package (for R)


will

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?

Thomas Lumley

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 mle2are 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

Related


Maximum Likelihood Estimation - MLE - in R using the plm package

Lucca coding I have unbalanced panel data and I want to fit this type of regression: Pr(y=1|xB) = G(xB+a) where "y" is a binary variable, "x" is a vector of explanatory variables, and "B" is my coefficient. I want to implement a random effects model with maxi

Simple numerical estimation problem for MLE of polynomials in R

John N I am trying to build a simple numerical MLE estimate for a multinomial distribution. The polynomial has a constraint - all cell probabilities need to add up to one. In general, the way to have this constraint is to reformulate one probability as (1 - su

Simple numerical estimation problem for MLE of polynomials in R

John N I am trying to build a simple numerical MLE estimate for a multinomial distribution. The polynomial has a constraint - all cell probabilities need to add up to one. In general, the way to have this constraint is to reformulate one probability as (1 - su

Simple numerical estimation problem for MLE of polynomials in R

John N I am trying to build a simple numerical MLE estimate for a multinomial distribution. The polynomial has a constraint - all cell probabilities need to add up to one. In general, the way to have this constraint is to reformulate one probability as (1 - su

Implementing Gaussian Mixture MLE using optim() in R

User 2007598 I am trying to implement MLE for mixture of Gaussians in R using optim() using R's native dataset (Geyser from MASS). My code is as follows. The problem is that optim works fine, but returns the original parameters I passed to it, and also says it

Implementing Gaussian Mixture MLE using optim() in R

User 2007598 I am trying to implement MLE for mixture of Gaussians in R using optim() using R's native dataset (Geyser from MASS). My code is as follows. The problem is that optim works fine, but returns the original parameters I passed to it, and also says it

Implementing Gaussian Mixture MLE using optim() in R

User 2007598 I am trying to implement MLE for mixture of Gaussians in R using optim() using R's native dataset (Geyser from MASS). My code is as follows. The problem is that optim works fine, but returns the original parameters I passed to it, and also says it

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

Error running MLE2 function (BBMLE)

tension mle2()I get the following error when running a function from a package bbmlein R : Some parameters are on the boundary: Hessian-based variance-covariance calculations may be unreliable I'm trying to understand if this is due to a problem with my data o

R: Error in estimating mle using MaxLik() package

Jasmine Helen My purpose is to find the maximum likelihood estimator using Newton Raphson's algorithm and compare this solution with glm(). So I try to use maxLik() in R. The result is an error, I have not used this package before, please fix this error, thank

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Use bbmle with vector arguments: mle2 (already run with optim)

Brix bbmle:mle2I'm having some trouble using the function when trying to do a regression . To illustrate my problem, I came up with a toy example. We define negative log-likelihood for a Poisson distribution (or any custom distribution): LL <- function(beta, z

Problems implementing Heapsort algorithm in R

Hendra I want to create my own Heapsort algorithm in R. this is my code heapify <- function(array, n, i) { parent <- i leftChild <- 2 * i + 1 rightChild <- 2 * i + 2 if ((leftChild < n) & (array[parent] < array[leftChild])) { parent = leftChild

Problems implementing Heapsort algorithm in R

Hendra I want to create my own Heapsort algorithm in R. this is my code heapify <- function(array, n, i) { parent <- i leftChild <- 2 * i + 1 rightChild <- 2 * i + 2 if ((leftChild < n) & (array[parent] < array[leftChild])) { parent = leftChild

Understanding Manual MLE logit estimation and optimization

John Stud I'm looking for insight as to why a slight change in the gradient function is necessary to achieve the same result of a manual logit MLE calculation. They get the same result, but it's not clear to me why the changes specified below are necessary. Co

Understanding Manual MLE logit estimation and optimization

John Stud I'm looking for insight as to why a slight change in the gradient function is necessary to achieve the same result of a manual logit MLE calculation. They get the same result, but it's not clear to me why the changes specified below are necessary. Co

Understanding Manual MLE logit estimation and optimization

John Stud I'm looking for insight as to why a slight change in the gradient function is necessary to achieve the same result of a manual logit MLE calculation. They get the same result, but it's not clear to me why the changes specified below are necessary. Co