[R] wrapping mle()

Sebastian P. Luque spluque at gmail.com
Sat Dec 30 06:17:15 CET 2006


Hi,

How can we set the environment for the minuslog function in mle()?  The
call in this code fails because the "ll" function cannot find the object
'y'.  Modifying from the example in ?mle:


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


How should "fit.mle" be constructed so that "ll" works on the appropriate
environment?  Thanks in advance for any advice on this.


-- 
Seb



More information about the R-help mailing list