bbmle icon indicating copy to clipboard operation
bbmle copied to clipboard

Optimization method not well documented

Open dushoff opened this issue 1 year ago • 1 comments

method is referred to optim; it is hard to figure out that the default method is actually different.

dushoff avatar Feb 02 '24 22:02 dushoff

Also (marginally related), make sure "user" option for optimization is documented; ?example?

library(bbmle)
library(emdbook) ## for dbetabinom
library(DEoptim)
load(system.file("vignetteData","orob1.rda",package="bbmle"))

m1 <- mle2(m ~ dbetabinom(prob = plogis(logit_mu),
                    size = n,
                    theta = exp(log_theta)),
     parameters = list(logit_mu ~ dilution),
     start = list(logit_mu = 0, log_theta = 0),
     data = orob1)


dewrap <- function(par, fn, lower = -Inf, upper = Inf, control = DEoptim.control(), ...) {
    ## what about ... args? eventually we might want to be able to pass
    ##  the DEoptim control settings
    dd <- DEoptim(fn = fn, lower = lower, upper = upper, control = control)
    ## need to preserve/restore original names
    bestpar <- dd$optim$bestmem
    names(bestpar) <- names(par)
    ## pretend we always converged
    return(list(par = bestpar, value = dd$optim$bestval, conv  = 0))
}

npar <- 4
update(m1,
       ## setting lower/upper to ±10 works here because these are log/logit scales
       lower = rep(-10, npar),
       upper = rep( 10, npar),
       optimizer = "user",  ## tell mle2 to use a user-specified optimization function
       optimfun = dewrap,
       control = DEoptim.control(itermax = 100, trace = FALSE)
       )

bbolker avatar Mar 04 '24 17:03 bbolker