Re: [R] Parameter names in nls

From: Ben Bolker <>
Date: Tue, 22 Jul 2008 14:14:52 +0000 (UTC)

 <rhelp.20.trevva <at>> writes:

> Kiaora Rolf,
> Thanks for the reply. The syntax that I am using is based on examples
> from ?optim, where a very similar system is setup with the rosenbrook
> banana function. Given that nls() is basically a wrapper for optim(),
> it seems reasonable that the logic should carry across. Furthermore,
> the formula that I have provided ie "data.y~fitting.fn(data.x,params)"
> is recognised and accepted by nls, and gives the intended result. It
> seems to me that the approach I have taken is not that daft (is it?).
> One of my collegues also tells me that there was a similar problem a
> while back with optim() stripping parameter names...
> Cheers,

  I don't know about "daft", but I think you're a little bit mistaken about nls -- it is NOT a wrapper for optim. Because nls accepts formulas with arbitrary variables, it has to do some funky things with names and evaluation ...

  The following seems a little bit more idiomatic to me, and maybe does what you want (or can be adapted)?

fitting.fn <-function(a,b,x) {

    a + x*b

data.x <- 1:50
data.y <- pi*data.x + rnorm(50,sd=20)


  Ben Bolker mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 22 Jul 2008 - 14:53:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jul 2008 - 15:32:04 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive