Re: [R] Parameter names in nls

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

 <rhelp.20.trevva <at> spamgourmet.com> 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)
plot(data.x,data.y)
nls(y~fitting.fn(a,b,x),data=data.frame(x=data.x,y=data.y),

      start=list(a=0,b=0))

  Ben Bolker



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

list of date sections of archive