[R] nls
Spencer Graves
spencer.graves at pdf.com
Thu Mar 27 01:11:34 CET 2003
Have you tried using "optim"?
An article in the Americal Statistician said that in S-Plus, "nls" often
had convergence problems that could be solved by first using "nlminb"
and then using the output of "nlminb" as starting values for "nls".
R is not S-Plus, but it's possible that "nls" may have some of the same
problems in R as it does in S-Plus. R does not have "nlminb" [Ripley
said in a separate context, "We do not copy defective software"], but it
has "optim", which seems to be better. In particular, "optim" will
estimate the Hessian, and you can compute eigenvalues of the Hessian to
make sure it is positive definite before passing the output of "optim"
to "nls". Or maybe you won't even need "nls".
I'm not sure, but I believe the suggestion to use "nlminb" first came
from the following article:
16. McCullough, B. D. (1999), ``Assessing the reliability of
statistical software: Part II'', The American Statistician, 53 , 149-159
I hope this helps.
Spencer Graves
Komanduru Sai C wrote:
> Hi,
>
> 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));
>
> I was using the following routine which was giving Singular Gradient, Error in
> numericDeriv(form[[3]], names(ind), env) :
> Missing value or an Infinity produced when evaluating the model errors.
>
>
> I also tried the below method given by Dr. Dougla Bates. But still am getting
> the error.
> Error in numericDeriv(form[[3]], names(ind), env) :
> Missing value or an Infinity produced when evaluating the model
>
>
> df <- read.table("data.txt", header=T);
> df1 = na.omit(df[, 1:2])
> library(nls);
> fm = nls(y ~ (x+d)^(-exp(lb)), data = df1, start=c(lb = 0, d = 0),alg =
> 'plinear', trace = TRUE);
>
>
>
>
> I would be glad if someone can help me.
>
> Thanks & Regards,
> Sai Charan Komanduru
>
>
>>To: Komanduru Sai C <sck2348 at cacs.louisiana.edu>
>>Cc: r-help at stat.math.ethz.ch
>>Subject: Re: [R] nls
>>From: Douglas Bates <bates at stat.wisc.edu>
>>Date: 19 Feb 2003 08:33:52 -0600
>>User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp)
>>MIME-Version: 1.0
>>X-Keywords:
>>
>>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/
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list