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

Spencer Graves spencer.graves at pdf.com
Mon Oct 10 00:15:30 CEST 2005


	  I will attempt a brief comment on this post, as I've seen no replies. 
  It's difficult to comment on this, as you do not really provide enough 
information to permit someone like me to understand your problem.  Only 
one portion of this problem is the fact that I can't find your function 
"mle" in one of the standard libraries, and I don't know if it is part 
of a contributed library or something you wrote.

	  However, I've encountered problems roughly like what you describe, 
and I've solved them in three different ways:

	  (a) Making a local copy inside the wrapper function and then pass to 
the standard function like "mle" only arguments locally defined.

	  (b) Using "assign"  with (I think) something like "pos=0".  I don't 
remember exactly for that, and the help file for "assign" and several 
searches with RSiteSearch didn't help me.  If you want to try this, I 
suggest you look for information on "lexical scoping" with "assign", etc.

	  (c) Passing additional references via "..." if "mle" has such in its 
function definition.

	  If you still would like more help from this group, PLEASE do read the 
posting guide (www.R-project.org/posting-guide.html).  I believe people 
who follow that guide on average get more useful answers quicker.

	  Viel Glück!
	  spencer graves

Coryn Bailer-Jones wrote:

> 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.
> 
> ---------------------------------------------------------------------------
> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list