Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization method not well documented #37

Open
dushoff opened this issue Feb 2, 2024 · 1 comment
Open

Optimization method not well documented #37

dushoff opened this issue Feb 2, 2024 · 1 comment

Comments

@dushoff
Copy link

dushoff commented Feb 2, 2024

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

@bbolker
Copy link
Owner

bbolker commented Mar 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants