From: Jim Lindsey <jlindsey@luc.ac.be> Message-Id: <9803121734.AA17337@alpha.luc.ac.be> Subject: Re: R-beta: nonlinear fitting To: wsimpson@uwinnipeg.ca (Bill Simpson) Date: Thu, 12 Mar 1998 18:34:15 +0100 (MET) In-Reply-To: <Pine.OSF.3.95.980312092714.1585B-100000@io.uwinnipeg.ca> from "Bill Simpson" at Mar 12, 98 09:36:15 am > > Thanks very much Douglas for the pointer to nlm. > Maybe the "Notes on R" maintainer can add at least a mention of nlm in the > section on nonlinear fitting? > > I never did nonlinear fitting in S-Plus before, so I have nothing to > unlearn, but I was hoping someone could show me how to do a least squares > fit with nlm. > > example: > x<-c(1,2,3,4,5,6) > y<-.3*x^-.6 +.2 > y<-y+rnorm(6,0,.01) > > Please show me how to fit the model > y=a*x^b + c > by least squares. I would like parameter estimates plus the standard > error for each param. try fn <- function(p) (y-p[1]*x^p[2]+p[3])^2 nlm(fn,p=c(0.3,-0.6,0.2)) Of course, you usually will not have such good initial estimates as those I put in the p vector! There are a lot of further options to nlm if you have convergence problems. See the help. Jim > > (This example could replace the current nonlinear fitting section in > "Notes on R") > > Thanks very much for any help! > > Bill Simpson > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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@stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._