Spencer Graves
2007-Dec-06 17:38 UTC
[Rd] suggested modification to the 'mle' documentation?
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. 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)))
Peter Dalgaard
2007-Dec-06 23:01 UTC
[Rd] suggested modification to the 'mle' documentation?
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