[R] 'singular gradient matrix’ when using nls() and how to make the program skip nls( ) and run on
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Sep 6 23:21:49 CEST 2007
In case 1 graph your function and then use optimize rather than nls.
In case 2 a and b may have the same effect as c on f whereas they
don't vary in case 1 so it does not matter. For example consider
minimizing f <- function(a, b) (a + b)^2 If a is fixed at zero then
the minimum occurs for b=0 but if a is not fixed then increasing a
and decreasing b by the same amount causes no change in the
result so the gradient in such a direction is zero.
On 9/5/07, Yuchen Luo <realityrandom at gmail.com> wrote:
> Dear friends.
>
> I use nls() and encounter the following puzzling problem:
>
>
>
> I have a function f(a,b,c,x), I have a data vector of x and a vectory y of
> realized value of f.
>
>
>
> Case1
>
> I tried to estimate c with (a=0.3, b=0.5) fixed:
>
> nls(y~f(a,b,c,x), control=list(maxiter = 100000, minFactor=0.5
> ^2048),start=list(c=0.5)).
>
> The error message is: "number of iterations exceeded maximum of 100000"
>
>
>
> Case2
>
> I then think maybe the value of a and be are not reasonable. So, I let nls()
> estimate (a,b,c) altogether:
>
> nls(y~f(a,b,c,x), control=list(maxiter = 100000, minFactor=0.5
> ^2048),start=list(a=0.3,b=0.5,c=0.5)).
>
> The error message is:
>
> "singular gradient matrix at initial parameter estimates".
>
>
>
> This is what puzzles me, if the initial parameter of (a=0.3,b=0.5,c=0.5) can
> create 'singular gradient matrix', then why doesn't this 'singular gradient
> matrix' appear in Case1?
>
>
>
> I have tried to change the initial value of (a,b,c) around but the problem
> persists. I am wondering if there is a way out.
>
>
>
> My another question is, I need to run 220 of nls() in my program with
> different y and x. When one of the nls() encounter a problem, the whole
> program stops. In my case, the 3rd nls() runs into a problem. I would
> still need the program to run the remaining 217 nls( )! Is there a way to
> make the program skip the problematic nls() and complete the ramaining
> nls()'s?
>
>
>
> Your help will be highly appreciated!
>
> Yuchen Luo
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
More information about the R-help
mailing list