Skip to content
Prev 106745 / 398506 Next

wrapping mle()

On Fri, 29 Dec 2006, Sebastian P. Luque wrote:

            
You need to set the environment of ll to that containing your data 
objects.  This would happen automatically if you defined ll in the 
function fit.mle.  A brutal solution would be

fit.mle <- function(FUN, x, y) {
    loglik.fun <- match.fun(FUN)
    environment(loglik.fun) <- sys.frame(sys.nframe())
    mle(loglik.fun, method="L-BFGS-B", lower=c(0, 0))
}

but of course that would remove the previous environment from the scope, 
so you may need something like

    env <- sys.frame(sys.nframe())
    parent.env(env) <- environment(ll)
    environment(loglik.fun) <- env