[Rd] suggested modification to the 'mle' documentation?
Luke Tierney
luke at stat.uiowa.edu
Sun Dec 9 00:15:09 CET 2007
On Fri, 7 Dec 2007, Ben Bolker wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Luke Tierney wrote:
>> On Fri, 7 Dec 2007, Duncan Murdoch wrote:
>>
>>
>>
>> For working at the general likelihood I think is is better to
>> encourage the approach of definign likelihood constructor functions.
>> The problem with using f, data is that you need to mathc the names
>> used in f and in data, so either you have to explicitly write out f
>> with the names you have in data or you have to modify data to use the
>> names f likes -- in the running example think
>>
>> f <- function(lambda) -sum(dpois(x, lambda, log=T))
>> d <- data.frame(y=rpois(10000, 12.34))
>>
>> somebody has to connext up the x in f with the y in d. With a negative
>> log likelihood constructor defines, for example, as
>>
>> makePoisonNegLogLikelihood <- function(x)
>> function(lambda) -sum(dpois(x, lambda, log=T))
>>
>> this happens naturally with
>>
>> makePoisonNegLogLikelihood(d$y)
>>
>>
>
> I hate to sound like a jerk, but I do hope that in the end we come
> up with a solution that will still be accessible to people who don't
> quite have the concept of writing functions to produce functions.
Any programming language has some idioms and conventions that are
worth lerning if you are going to make most effective use of the
language. R is no exception. One can use R as interactive C but the
results aren't likely to be too satisfactory. Three ideas worth
learning in R (not an exclusive list) are how to use vectorized
arithmetic, how to use the apply family of functions, and how to take
advantage of lexical scope. None of hese is hard to learn, and basic
lexical scope may be the easiest of the three, and the small
investment will pay off.
Best,
luke
> I
> feel it is "natural" for people who have multiple data sets to have the
> variables named similarly in different data sets. All of the
> constructor stuff is still accessible to anyone who wants to use the
> function that way ... is there any way to do a cheesy default
> constructor that is just equivalent to taking the likelihood function
> and arranging for it to be evaluated in an environment containing
> the data? That way if "nllmaker" below were just a formula
> or a log-likelihood function it could still work ...
>
> [snip]
>> Both (simple) bootstrapping and (simple leave-one-out) crossvalidation
>> require a data structure with a notion of cases, which is much more
>> restrictive than the conext in which mle can be used. A more ngeneric
>> aproach to bootstrapping that might fit closer to the level of
>> generality of mle might be parameterized in terms of a negative log
>> likelihood constructor, a starting value constructor, and a resampling
>> function, with a single iteration implemented soemthing like
>>
>> mleboot1 <- function(nllmaker, start, esample) {
>> newdata <- resample()
>> newstart <- do.call(start, newdata)
>> nllfun <- do.call(nllmaker, newdata)
>> mle(fnllfun, start = newstart)
>> }
>>
>> This would leave decisions on the resampling method and data structure
>> up to the user. Somehing similar could be done with K-fold CV.
>>
>> luke
>>
>>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFHWcS1c5UpGjwzenMRAig2AJ9iTzhI1p8tBb7Q15jgT4nA+Zds+gCgggc2
> sI2que28Hl1M5cVGa+anEL0=
> =hCiS
> -----END PGP SIGNATURE-----
>
--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa Phone: 319-335-3386
Department of Statistics and Fax: 319-335-3017
Actuarial Science
241 Schaeffer Hall email: luke at stat.uiowa.edu
Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
More information about the R-devel
mailing list