[R] Error using a data frame as the "start" parameter in mle()

Coryn Bailer-Jones calj at mpia-hd.mpg.de
Thu Sep 29 17:24:52 CEST 2005

Dear R-Users,

I am trying to use mle() to optimize two (or more) parameters, but I want
to specify those parmeters in a data frame rather than having to spell
them out separately in the "start" variable of mle().

My call is

> mle(negll, start=list(aps=init), fixed=list(measphot=newphot,
    formod=formod, Nbands=Nbands), method="BFGS")

where negll is a function I have written which uses the function
predict.loess(). negll works fine when called directly. The parameter I am
trying to optimize, "aps", is a data frame containing two parameters, e.g.

> init
  teff logg
1 8000  4.5

When I run mle I get the following error message

Error in predict.loess(formod[[band]], aps) :
        Argument "aps" is missing, with no default

As negll does work fine, I presume I am incorrectly passing "aps" into
mle(). Note that mle() works fine if I rewrite negll to work on a scalar
"aps" and then I use start=list(aps=500), for example. Can anyone help me
with this?

Incidentally, I am only using a data frame for "aps" because I am using
loess(), and this seems to require a formula with named variables in a
data frame (here "logg" and "teff"). I can't get it work with arrays:

> temp <- loess(formula = photd[, band] ~ gridaps[, 1] * gridaps[, 2])
> predict(temp, c(4,8000))
Error in predict.loess(temp, c(4, 8000)) :
        newdata does not contain the variables needed

Thanks in advance for any clues.


Coryn Bailer-Jones                    calj at mpia-hd.mpg.de
Max-Planck-Institut fuer Astronomie   http://www.mpia-hd.mpg.de/homes/calj/
Koenigstuhl 17                        tel: +49 6221 528-224        (direct)
D-69117 Heidelberg                         +49 6221 528-0       (reception)
Germany                               fax: +49 6221 528-246

More information about the R-help mailing list