Re: [R] Error 'singular gradient' in nonlinear model fitting

From: Douglas Bates <bates_at_stat.wisc.edu>
Date: Sat, 16 Feb 2008 07:34:55 -0600

On Feb 15, 2008 11:50 AM, Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote:
> Try fitting regressing log(WEIGHT) against log(TOTAL) using lm
> and then transform the results into starting values for nls (or
> possibly that is sufficient and you don't need the nls results).

Also, set the trace argument to TRUE in your call to nls. This will cause nls to print the progress of the iterations including the residual sum of squares and the parameter values. What usually happens with a singular gradient is that one of the parameters, probably beta, is heading to an extreme value.

This particular model can be reduced to a one-parameter optimization problem by using the optional "plinear" algorithm.

nls(WEIGHT ~ (TOTAL^beta)/454, start = c(beta = 3), data = spottedseatrout2004.female.data, algorithm = "plinear")

> On Fri, Feb 15, 2008 at 12:41 PM, HongSheng Liao <HLiao@odu.edu> wrote:
> >
> > w.age.female.2004 <- nls(WEIGHT ~ (alpha*TOTAL^beta)/454,
> > start=list(alpha=1, beta=3),
> > data=spottedseatrout2004.female.data)
> >
> > I am trying to fit above model to length-weight data of a fish species
> > (spotted seatrout) by year (1999-2006). The convergence occurred for all
> > the years except 2002 and 2004. In these two year, R shows the error
> > called 'singular gradient' in the model. Could anyone please help me to
> > fix the error? I don't think there are any problems with my data because I
> > can fit the same model to 2004 data without any problems using SAS. Thank
> > you very much in advance.
> >
> > Hongsheng (Hank) Liao, Ph.D.
> > Lab Manager
> > Center for Quantitative Fisheries Ecology
> > 800 West 46th Street
> > Old Dominion University
> > Norfolk, Virginia 23508
> > Phone:757.683.4571
> > Fax:757.683.5293
> >
> > ______________________________________________
> > R-help_at_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.
> >
>
> ______________________________________________
> R-help_at_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.
>



R-help_at_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. Received on Sat 16 Feb 2008 - 13:40:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Feb 2008 - 15:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive