Hi,
I am using nls library
df <- read.table("data.txt", header=T);
library(nls);
fm <- nls(y ~ a*(x+d)^(-b), df,
start=list(a=max(df->y,na.rm=T)/2,b=1,d=0));
coef(fm);
q();
When i am using the above routine i am getting the following error
Error in nlsModel(formula, mf, start) : singular gradient matrix at initial
parameter estimates
Can some one help me in this.
The data.txt file looks like this
x y z
1.0 NA 478
2.0 NA 473
3.0 NA 449
4.0 NA 446
5.0 NA 438
6.5 NA 437
6.5 NA 437
8.0 NA 427
9.0 NA 426
10.0 NA 425
11.0 NA 424
14.0 NA 423
14.0 NA 423
14.0 NA 423
14.0 NA 423
14.0 NA 423
.........
The y field has some values at the bottom.
Thanks,
SAi
Komanduru Sai C <sck2348 at cacs.louisiana.edu> writes:> Hi, > > I am using nls library > > df <- read.table("data.txt", header=T); > library(nls); > fm <- nls(y ~ a*(x+d)^(-b), df, start=list(a=max(df->y,na.rm=T)/2,b=1,d=0)); > coef(fm); > q();1) Are you sure you meant max(df->y, na.rm=TRUE) and not max(df$y, na.rm=TRUE)? 2) To begin you may want to use a data frame without the missing data df1 = na.omit(df[, 1:2]) 3) Use the plinear algorithm and change from b to exp(lb) fm = nls(y ~ (x+d)^(-exp(lb)), data = df1, start=c(lb = 0, d = 0), alg = 'plinear', trace = TRUE) -- Douglas Bates bates at stat.wisc.edu Statistics Department 608/262-2598 University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/