On Thu, Mar 14, 2013 at 5:07 AM, meng <laomen...@163.com> wrote: > Hi,all: > I met a problem of nls. > > My data: > x y > 60 0.8 > 80 6.5 > 100 20.5 > 120 45.9 > > I want to fit exp curve of data. > > My code: >> nls(y ~ exp(a + b*x)+d,start=list(a=0,b=0,d=1)) > Error in nlsModel(formula, mf, start, wts) : > singular gradient matrix at initial parameter estimates > > I can't find out the reason for the error. > Any suggesions are welcome. >
The gradient is singular at your starting value so you will have to use a better starting value. If d = 0 then its linear in log(y) so you can compute a starting value using lm like this: lm1 <- lm(log(y) ~ x, DF) st <- setNames(c(coef(lm1), 0), c("a", "b", "d")) Also note that you are trying to fit a model with 3 parameters to only 4 data points. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@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.