Ravi Varadhan
2015-Jan-15 14:26 UTC
[R] R 3.1.2 mle2() function on Windows 7 Error and multiple solutions
Hi, I tried your problem with optimx package. I found a better solution than that found by mle2. ?library(optimx) # the objective function needs to be re-written LL2 <- function(par,y) { lambda <- par[1] alpha <- par[2] beta <- par[3] R = Nweibull(y,lambda,alpha,beta) -sum(log(R)) } optimx(fn=LL2, par=c(.01,325,.8),y=y, lower=c(.00001,.00001,.00001),upper = c(Inf, Inf,Inf),control=list(all.methods=TRUE)) # Look at the solution found by `nlminb' and `nmkb'. This is the optimal one. This log-likelihood is larger than that of mle2 and other optimizers in optimx. If this solution is not what you are looking for, your problem may be poorly scaled. First, make sure that the likelihood is coded correctly. If it is correct, then you may need to improve the scaling of the problem. Hope this is helpful, Ravi [[alternative HTML version deleted]]
Ben Bolker
2015-Jan-15 14:29 UTC
[R] R 3.1.2 mle2() function on Windows 7 Error and multiple solutions
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 For what it's worth, you can use either nlminb (directly) or optimx within the mle2 wrapper by specifying the 'optimizer' parameter ... this gives you flexibility in optimization along with the convenience of mle2 (likelihood ratio tests via anova(), likelihood profiling, etc.) On 15-01-15 09:26 AM, Ravi Varadhan wrote:> Hi, > > > > I tried your problem with optimx package. I found a better > solution than that found by mle2. > > > > ?library(optimx) > > > > # the objective function needs to be re-written > > LL2 <- function(par,y) { > > lambda <- par[1] alpha <- par[2] beta <- par[3] R = > Nweibull(y,lambda,alpha,beta) > > -sum(log(R)) } > > > > optimx(fn=LL2, par=c(.01,325,.8),y=y, > lower=c(.00001,.00001,.00001),upper = c(Inf, > Inf,Inf),control=list(all.methods=TRUE)) > > > > # Look at the solution found by `nlminb' and `nmkb'. This is the > optimal one. This log-likelihood is larger than that of mle2 and > other optimizers in optimx. > > > > If this solution is not what you are looking for, your problem may > be poorly scaled. First, make sure that the likelihood is coded > correctly. If it is correct, then you may need to improve the > scaling of the problem. > > > > > > Hope this is helpful, > > Ravi > > >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAEBAgAGBQJUt87VAAoJEOCV5YRblxUH9E4H/ismNjBi/diA7db1f4EtIYUz fk0V1GIjAkhNr+gxs8bu6CBAMB2f/ufw+9ey2X6yHlzvgfwzIwNafgg9c5qVlArF xD8A4w/4G9cRsQFX8yySEQMP7dH5tyCTeRHU0sEcTbY+vV/NtWAYpF7k36He0QnQ Jz/Gfmjt/TTVlcsL4crr8IdOjP34mq7H1SGXKNoBymhaggkBXXjG+IlhPK3/HE4s 2LFKusdSVDiJCCR+kafwyKxk76Lf2WADw9/RaysWfW0/v5O5dWU4IuvK2//nzvts 7rKMkF9/zlT+LgLNo7LON+RTOeDtTMqyA10Vu+txQTKH4AcMP4LqYoiGMerl6O0=cHEo -----END PGP SIGNATURE-----
Ravi Varadhan
2015-Jan-15 14:36 UTC
[R] R 3.1.2 mle2() function on Windows 7 Error and multiple solutions
A more important point that want to make is that I find few people taking advantage of the "comparative evaluation" or benchmarking ability of optimx. There is no "uniformly best" optimizer for all problems. Different ones turn out to perform better for different problems and it is quite difficult to know a priori which one would be the best for "my" problem. Thus, the benchmarking capability provided by optimx is a powerful feature. Ravi ________________________________________ From: Ben Bolker <bbolker at gmail.com> Sent: Thursday, January 15, 2015 9:29 AM To: Ravi Varadhan; R-Help Cc: malqurashi at KSU.EDU.SA Subject: Re: R 3.1.2 mle2() function on Windows 7 Error and multiple solutions -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 For what it's worth, you can use either nlminb (directly) or optimx within the mle2 wrapper by specifying the 'optimizer' parameter ... this gives you flexibility in optimization along with the convenience of mle2 (likelihood ratio tests via anova(), likelihood profiling, etc.) On 15-01-15 09:26 AM, Ravi Varadhan wrote:> Hi, > > > > I tried your problem with optimx package. I found a better > solution than that found by mle2. > > > > ?library(optimx) > > > > # the objective function needs to be re-written > > LL2 <- function(par,y) { > > lambda <- par[1] alpha <- par[2] beta <- par[3] R > Nweibull(y,lambda,alpha,beta) > > -sum(log(R)) } > > > > optimx(fn=LL2, par=c(.01,325,.8),y=y, > lower=c(.00001,.00001,.00001),upper = c(Inf, > Inf,Inf),control=list(all.methods=TRUE)) > > > > # Look at the solution found by `nlminb' and `nmkb'. This is the > optimal one. This log-likelihood is larger than that of mle2 and > other optimizers in optimx. > > > > If this solution is not what you are looking for, your problem may > be poorly scaled. First, make sure that the likelihood is coded > correctly. If it is correct, then you may need to improve the > scaling of the problem. > > > > > > Hope this is helpful, > > Ravi > > >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAEBAgAGBQJUt87VAAoJEOCV5YRblxUH9E4H/ismNjBi/diA7db1f4EtIYUz fk0V1GIjAkhNr+gxs8bu6CBAMB2f/ufw+9ey2X6yHlzvgfwzIwNafgg9c5qVlArF xD8A4w/4G9cRsQFX8yySEQMP7dH5tyCTeRHU0sEcTbY+vV/NtWAYpF7k36He0QnQ Jz/Gfmjt/TTVlcsL4crr8IdOjP34mq7H1SGXKNoBymhaggkBXXjG+IlhPK3/HE4s 2LFKusdSVDiJCCR+kafwyKxk76Lf2WADw9/RaysWfW0/v5O5dWU4IuvK2//nzvts 7rKMkF9/zlT+LgLNo7LON+RTOeDtTMqyA10Vu+txQTKH4AcMP4LqYoiGMerl6O0=cHEo -----END PGP SIGNATURE-----