From bolker at ufl.edu  Fri Dec  7 04:17:44 2007
From: bolker at ufl.edu (Ben Bolker)
Date: Thu, 6 Dec 2007 19:17:44 -0800 (PST)
Subject: [Rd] suggested modification to the 'mle' documentation?
In-Reply-To: <971536df0712061512k47f89415v5146c61b346239b8@mail.gmail.com>
References: <4758338E.3080802@pdf.com> <47587F30.6020701@biostat.ku.dk>
	<971536df0712061512k47f89415v5146c61b346239b8@mail.gmail.com>
Message-ID: <14206100.post@talk.nabble.com>




Gabor Grothendieck wrote:
> 
> 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 <p.dalgaard at biostat.ku.dk> 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 at 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
>> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45)
>> 35327907
>>
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 

  At this point I'd just like to advertise the "bbmle" package
(on CRAN) for those who respectfully disagree, as I do, with Peter over
this issue.  I have added a data= argument to my version
of the function that allows other variables to be passed
to the objective function.  It seems to me that this is perfectly
in line with the way that other modeling functions in R
behave.

  (My version also has a cool formula interface and other
bells and whistles, and I would love to get feedback from other
useRs about it.)

   cheers
    Ben Bolker

-- 
View this message in context: http://www.nabble.com/suggested-modification-to-the-%27mle%27-documentation--tf4957508.html#a14206100
Sent from the R devel mailing list archive at Nabble.com.



[Rd] suggested modification to the 'mle' documentation?
Ben Bolker