Benchmarking the mle and mle2 function


December 29, 2018

NOTE : Below post is valid for Package version 1.4.0 and Before.


mle and mle2 are my favorite functions, because they provide extensive amount of outputs for the optimization process. Even though there is no difference in analytical methods used in both of these functions. Further, these analytical methods are the same ones used by optim function. To be honest mle and mle2 functions are wrapper functions of optim. It means both mle and mle2 are using the optim function inside but with some additional inputs, which would generate extended outputs.

Even if I do Benchmark the analytical methods for the mle function it would be very similar to optim function tables but with additional time taken, because of the extra outputs. This would similarly occur when we benchmark analytical methods from the mle2 function as well.

Therefore, I figure why do we need to benchmark them at all. So this blog post is to simply reiterate the initial things which I said in my earlier post on the blog post Benchmarking optimization functions in R.


mle function is from the stats4 package. If we intend to use this function for the estimation of shape parameters a and b of the Beta-Binomial distribution wtih Binomial Outcome Data, then we need to use the EstMLEBetaBin function from the fitODBOD package. This is not enough because for limitations in the mle we need to make changes in our EstMLEBetaBin function as mentioned below.


#new function to facilitate mle criteria 
  EstMLEBetaBin(x=Alcohol_data$Days,freq = Alcohol_data$week1,a,b)

# optimizing values for a,b using default analytial method
mle_answer<-mle(minuslogl = formle,start = list(a=0.1,b=0.2))

We are going to use the Alcohol Consumption data of week 1. In the above code chunk we are using the mle function for our task of finding the optimum shape parameter values for a and b while using the given Binomial Outcome data. Also If you wish you study about the mle function by referring this link from my previous post.


bbmle package holds the mle2 function. It is simply an updated version for the mle function. Although there need to be no changes in the EstMLEBetaBin function to satisfy the mle2 function’s criteria. Now it will be possible to use it.


# optimizing values for a,b using default analytical method
mle2_answer<-mle2(minuslogl= EstMLEBetaBin,start = list(a=0.1,b=0.2),
                  data = list(x=Alcohol_data$Days,freq=Alcohol_data$week1))

Still if someone needs a brief introduction to mle2 function they can refer my previous brief through this link.


My personal opinion is to use the mle2 function, but moving towards what should be the analytical method. It would be wise to choose it based on your needs as these methods completely depend on the data, function that needs to be estimated, complexity of the function and finally the number estimators that needs to be estimated.

This is the link to the article which is for Benchmarking optim function. It might be useful while understanding the analytical methods.