[R] nlm and "missing argument

Charilaos Skiadas cskiadas at gmail.com
Fri May 30 06:11:47 CEST 2008


On May 29, 2008, at 11:54 PM, Redding, Matthew wrote:

> Dear R Gurus,
>
> I am having a little difficulty with nlm. I've searched the  
> archives and
> found nothing that tells me why this is occuring -- though there are
> some slightly similar issues.
>
> A simple example:
>
> lev2<-function(aaa,bbb,ccc,ddd,eee){
> 	res<-aaa+bbb+ccc+ddd+eee
> 	res
>
> }
>
> nlm(lev2,p=c(32,4,5),ddd=45,eee=23)
>
> Error in f(x, ...) : argument "bbb" is missing, with no default
>
> Why is this occurring?  I am running 2.6.1.
>
> Is there something simple here that I am overlooking?  I am trying to
> take advantage of the "..." method of inputing
> parameters that I do not want optimised.
>
> Kind regards,

Read the documentation for nlm more closely. The Arguments part says  
about f:

	This should be a function of a vector of the length of p followed by  
any other arguments specified by the ... argument.

All the examples in fact do exactly that, using only the first  
variable, x, of f for all the unknowns. So perhaps you want to do a  
simple wrapping like this:

lev3 <- function(x,ddd,eee) {
	lev2(x[1],x[2],x[3],ddd,eee)
}
nlm(lev3,p=c(32,4,5),ddd=45,eee=23)

> Matt Redding

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



More information about the R-help mailing list