[R] question about non-linear least squares in R
apjaworski at mmm.com
apjaworski at mmm.com
Wed Sep 5 18:24:20 CEST 2007
Here is one way of getting a reasonable fit:
1. Scale your y's by dividing all values by 1e6.
2. Plot x vs. y. The plot looks like a quadratic function.
3. Fit a quadratic const. + B*x^2 - this a linear regression problem so
use lm.
4. Plot the predictions.
5. Eyball the necessary shift - MA is around 0.01. Refit const. +
B*(x-.01)^2. Should get const.=1.147 and B=139.144
6. Use start=list(const.= 1.147, A=0, B=1.147, MA=.01). nls should
converge in 4 iterations.
In general, good starting points may be crucial to nls convergence.
Scaling the y's to reasonable values also helps.
Hope this helps,
Andy
__________________________________
Andy Jaworski
518-1-01
Process Laboratory
3M Corporate Research Laboratory
-----
E-mail: apjaworski at mmm.com
Tel: (651) 733-6092
Fax: (651) 736-3122
"Yu (Warren)
Wang"
<yu.wang at pdf.com> To
Sent by: "r-help at stat.math.ethz.ch"
r-help-bounces at st <r-help at stat.math.ethz.ch>
at.math.ethz.ch cc
Subject
09/05/2007 02:51 [R] question about non-linear least
AM squares in R
Hi, everyone,
My question is: It's not every time that you can get a converged
result from the nls function. Is there any solution for me to get a
reasonable result? For example:
x <- c(-0.06,-0.04,-0.025,-0.015,-0.005,0.005,0.015,0.025,0.04,0.06)
y <-
c(1866760,1457870,1314960,1250560,1184850,1144920,1158850,1199910,1263850,1452520)
fitOup<- nls(y ~ constant + A*(x-MA)^4 + B*(x-MA)^2,
start=list(constant=10000000, A=100000000, B=-1000000, MA=0),
control=nls.control(maxiter=100, minFactor=1/4096), trace=TRUE)
For this one, I cannot get the converged result, how can I reach it? To
use another funtion or to modify some settings for nls?
Thank you very much!
Yours,
Warren
______________________________________________
R-help at stat.math.ethz.ch 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.
More information about the R-help
mailing list