Bad scaling will waste a lot of everyone's time.
I put the data in a data frame mdat, then
library(nlmrt)
mdat<-read.csv("muzzamil.csv", header=T)
fmn <- nlxb(y~a * (x^b), data=mdat, start=c(a=1,b=1), trace=T)
fm <- nls(y~a * (x^b), data=mdat, start=c(a=1,b=1), trace=T)
fmn2 <- nlxb(y~a2 * ((x-1979)^b2), data=mdat, start=c(a2=1,b2=1), trace=T)
fm2 <- nls(y~a2 * ((x-1979)^b2), data=mdat, start=c(a2=1,b2=1), trace=T)
found a possible solution quickly with the last 2 forms. Without
adjusting the x data, you get a very ill-conditioned problem.
JN
Message: 21
Date: Wed, 14 Nov 2012 03:04:56 -0800 (PST)
From: muzammil786 <m.shah...@sheffield.ac.uk>
To: r-help@r-project.org
Subject: Re: [R] problem in fitting model in NLS function
Message-ID: <1352891096449-4649473.p...@n4.nabble.com>
Content-Type: text/plain; charset=us-ascii
Dear David,
I am having a similar problem on this data (given below). I have tried
several starting values for a and b, but it is consistently giving me:
*fm <- nls(y~f(x,a,b), data.frame(x,y), start=c(a=1,b=1))
Error in numericDeriv(form[[3L]], names(ind), env) :
Missing value or an infinity produced when evaluating the model*
The function f(x,a,b) is defined here:
*f <- function(x,a,b) {a * I(x^b)} *
The data is given here:
* x y
1 1980 1
2 1981 1
3 1982 1
4 1983 3
5 1984 3
6 1985 5
7 1986 8
8 1987 8
9 1988 9
10 1989 12
11 1990 15
12 1991 24
13 1992 33
14 1993 44
15 1994 62
16 1995 68
17 1996 81
18 1997 87
19 1998 102
20 1999 114
21 2000 123
22 2001 135
23 2002 144
24 2003 158
25 2004 172
26 2005 188
27 2006 197
28 2007 224
29 2008 234
30 2009 254
31 2010 278
32 2011 312
33 2012 317*
I shall be grateful if you could guide me what's wrong here.
Cheers.
Muzammil
--
View this message in context:
http://r.789695.n4.nabble.com/problem-in-fitting-model-in-NLS-function-tp4345082p4649473.html
Sent from the R help mailing list archive at Nabble.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.