The closure only works if you are defining the inner function yourself.
If you are not then its yet more work to redefine the environment of
the inner function or other workaround.

On Dec 6, 2007 6:01 PM, Peter Dalgaard <[EMAIL PROTECTED]> wrote:
> Spencer Graves wrote:
> > Hello:
> >
> >       I wish to again express my appreciation to all who have
> > contributed to making R what it is today.
> >
> >       At this moment, I'm particularly grateful for whoever modified the
> > 'mle' code so data no longer need be passed via global variables.  I
> > remember struggling with this a couple of years ago, and I only today
> > discovered that it is no longer the case.
> >
> >       I'd like to suggest that the 'mle' help file be modified to
> > advertise this fact, e.g., by adding one of the two examples appearing
> > below.
> >
>
> In a word: No!!! That is not the design. A likelihood function is a
> function of its parameters, and the "fixed" argument is for holding some
> parameters fixed (e.g. during profiling).
>
> To include data, just make a closure, e.g.
>
> poissonLike <- function(x., y.){
>    function(ymax=15, xhalf=6)
>      -sum(stats::dpois(y., lambda=ymax/(1+x./xhalf), log=TRUE))}
> mll <-  poissonLike(x, y)
> mle(ll, ....
>
>
> >       Best Wishes,
> >       Spencer Graves
> > ################################
> > x <- 0:10
> > y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
> > #  Pass data via function arguments rather than global variables
> > ll.5 <- function(ymax=15, xhalf=6, x., y.)
> >          -sum(stats::dpois(y., lambda=ymax/(1+x./xhalf), log=TRUE))
> > (fit.5 <- mle(ll.5, start=list(ymax=15, xhalf=6),
> >               fixed=list(x.=x, y.=y)))
> >
> > ll3 <- function(lymax=log(15), lxhalf=log(6), x., y.)
> >   -sum(stats::dpois(y.,
> >          lambda=exp(lymax)/(1+x./exp(lxhalf)), log=TRUE))
> > (fit3 <- mle(ll3, start=list(lymax=0, lxhalf=0),
> >              fixed=list(x.=x, y.=y)))
> >
> > ______________________________________________
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>
> --
>   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
>  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
> ~~~~~~~~~~ - ([EMAIL PROTECTED])                  FAX: (+45) 35327907
>
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to