[R] NLS Question

ben@zoo.ufl.edu ben at zoo.ufl.edu
Fri Oct 20 05:29:15 CEST 2000


  Despite my poor track record, I'll take a crack at this.

  Yes, you can do what you want.  For example:

x <- runif(100)
w <- runif(100)
y <- x^2.4*w^3.2+rnorm(100,0,0.01)
plot(x,y)
plot(w,y)
library(nls)
fit <- nls(y~x^a*w^b,start=list(a=2,b=3))

l.est <- lm(log(y) ~ log(x)+log(w)-1)
fit <- nls(y~x^a*w^b,start=list(a=coef(l.est)[1],b=coef(l.est)[2]))

  The error you got (is in my experience) a fairly common result of
starting with parameter values that are far away from the true values, or
have very different scales, so that the numeric-derivative part of nls
fails.  Various solutions are to do an approximate least-squares
regression to start things off (also the "self-starting" models in the nls
package), or to provide an analytic derivative.

On Fri, 20 Oct 2000, Redding, Matthew wrote:

> Hi list members,
> I'm (gradually) coming up to speed on  using R.  SO far I am very much
> enjoying the learning process.
> I mentioned the software to a colleague at another research organisation,
> and he was interested.
> 
> He had the following question:
> 
> Can the following non-linear fit be carried out (I suppose by NLS),
> y~(x^a)*(w^b), where a and b are the parameters and x and w are variables?
> i.e. the formula has two independent variables.
> 
> Does the software do this sort of thing, or will it only handle one
> independent variable?  I gave it a go but did not get an answer out of
> it....the response being
> 2590.046 :  5.0 0.4 
> Error in qr(attr(rhs, "gradient")) : NA/NaN/Inf in foreign function call
> (arg 1)
> 
> Before I persevere any further, does NLS have this capability, or am I on
> the wrong track?
> 
> Thanks, 
> 
> Matt Redding
> 
> ********************************DISCLAIMER****************************
> The information contained in the above e-mail message or messages 
> (which includes any attachments) is confidential and may be legally 
> privileged.  It is intended only for the use of the person or entity 
> to which it is addressed.  If you are not the addressee any form of 
> disclosure, copying, modification, distribution or any action taken 
> or omitted in reliance on the information is unauthorised.  Opinions 
> contained in the message(s) do not necessarily reflect the opinions 
> of the Queensland Government and its authorities.  If you received 
> this communication in error, please notify the sender immediately and 
> delete it from your computer system network.
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 
> 

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list