Hi!
This is a repost of an earlier message (with a clearer example
demonstrating the problem I ran into). If you run the mle example in
stats4
library(stats4)
x <- 0:10
y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
ll <- function(ymax=15, xhalf=6)
-sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE))
(fit <- mle(ll))
plot(profile(fit), absVal=FALSE)
everything works fine. Now run
(fit <- mle(ll, method="BFGS", control=list(ndeps=c(1e-3, 1e-3))))
plot(profile(fit), absVal=FALSE)
and you will get
Error in interpSpline.default(obj[[i]]$par.vals[, i], obj[[i]]$z,
na.action = na.omit) :
only 0's may mix with negative subscripts
This happens because optim gets the old ndeps but just one variable to
optimize. The optim error is not reported, so the problem is rather hard
to trace. Would you agree that this would be worth fixing?
Best regards,
Daniel
(original posting with quick workaround
http://tolstoy.newcastle.edu.au/R/help/04/07/1778.html)
--
Daniel Hoppe
Department of Marketing
University of Vienna
Bruenner Strasse 72
1210 Vienna
Austria
Problem with mle in stats4 (R 1.9.1)
4 messages · Daniel Hoppe, Brian Ripley, Peter Dalgaard
We are currently on R 2.0.0 alpha. If you submit a bug fix, preferably this week and at the latest next week, it will be considered for 2.0.0. Please take seriously that R is an open project and does not have `staff' to fix bugs. If you think it is worth fixing, please fix it for us by providing a complete analysis and fixes for all the possible options that might be affected. The best place for a patch to be sent is R-bugs.
On Mon, 13 Sep 2004, Daniel Hoppe wrote:
Hi!
This is a repost of an earlier message (with a clearer example
demonstrating the problem I ran into). If you run the mle example in
stats4
library(stats4)
x <- 0:10
y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
ll <- function(ymax=15, xhalf=6)
-sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE))
(fit <- mle(ll))
plot(profile(fit), absVal=FALSE)
everything works fine. Now run
(fit <- mle(ll, method="BFGS", control=list(ndeps=c(1e-3, 1e-3))))
plot(profile(fit), absVal=FALSE)
and you will get
Error in interpSpline.default(obj[[i]]$par.vals[, i], obj[[i]]$z,
na.action = na.omit) :
only 0's may mix with negative subscripts
This happens because optim gets the old ndeps but just one variable to
optimize. The optim error is not reported, so the problem is rather hard
to trace. Would you agree that this would be worth fixing?
Best regards,
Daniel
(original posting with quick workaround
http://tolstoy.newcastle.edu.au/R/help/04/07/1778.html)
--
Daniel Hoppe
Department of Marketing
University of Vienna
Bruenner Strasse 72
1210 Vienna
Austria
______________________________________________ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
"Daniel Hoppe" <daniel.hoppe@univie.ac.at> writes:
Hi! This is a repost of an earlier message (with a clearer example demonstrating the problem I ran into). If you run the mle example in stats4
....
This happens because optim gets the old ndeps but just one variable to optimize. The optim error is not reported, so the problem is rather hard to trace. Would you agree that this would be worth fixing?
Definitely (and the problem is still in 2.0.0 alpha). Thanks for the reminder.
(original posting with quick workaround http://tolstoy.newcastle.edu.au/R/help/04/07/1778.html)
Could well be fix, not just workaround.... Given that optim wasn't designed to be able to hold arguments constant, any fix is going to be somewhat kludgy.
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
Peter Dalgaard <p.dalgaard@biostat.ku.dk> writes:
(original posting with quick workaround http://tolstoy.newcastle.edu.au/R/help/04/07/1778.html)
Could well be fix, not just workaround.... Given that optim wasn't designed to be able to hold arguments constant, any fix is going to be somewhat kludgy.
Had another look and your workaround turned out to be a bit too
kludgy. This seems to work (the eval() is important):
if (!is.null(call$control$ndeps))
call$control$ndeps <- eval(call$control$ndeps)[-i]
if (!is.null(call$control$parscale))
call$control$parscale <- eval(call$control$parscale)[-i]
and a bit further down, I think you need to move the assignment to
"call" inside the "for (i in which)" loop, so that the changes don't
accumulate.
Leaves one issue, namely *where* to eval, and the above code is not
quite right (you might capture a local variable of profile.mle, and if
you called mle from a function, references to local variables inside
that function can not be passed). Then again it actually never was
right since the try(eval(call),....) call has the same issue. We
really ought to save the environment of the original call to mle to be
safe. How best to do that is a bit unclear to me. Could add a slot of
just set the environment of the call (but that seems not to be
documented to work...).
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907