[R] wrapping mle()

Sebastian P. Luque spluque at gmail.com
Sat Dec 30 16:47:26 CET 2006


On Sat, 30 Dec 2006 07:41:48 +0000 (GMT),
Prof Brian Ripley <ripley at stats.ox.ac.uk> 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

Thanks to both of you.  I really need to get to grips with environments.


Happy new year,

-- 
Seb



More information about the R-help mailing list