Skip to content
Prev 106743 / 398506 Next

wrapping mle()

Add the line marked ### so that the environment of loglik.fun is reset to
the environment within fit.mle so that it can find y there:

library(stats4)
ll <- function(ymax=15, xhalf=6) {
   -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE))
}
fit.mle <- function(FUN, x, y) {
   loglik.fun <- match.fun(FUN)
   environment(loglik.fun) <- environment() ###
   mle(loglik.fun, method="L-BFGS-B", lower=c(0, 0))
}
fit.mle("ll", x=0:10, y=c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8))
On 12/30/06, Sebastian P. Luque <spluque at gmail.com> wrote: