R] nls model singular gradient matrix at initial parameter, > estimates

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

R] nls model singular gradient matrix at initial parameter, > estimates

Prof J C Nash (U30A)
I have a section (6.4.2) about "singular gradient" (actually singular
Jacobian to numerical analysts) in my recent book "Nonlinear parameter
optimization using R tools". nls() is prone to this, though having all
the starting values the same in many functions can be asking for trouble
of this sort, as is any function involving expm(). (If you search on
R-help archives, you'll find where there is discussion of how this can
result in huge timing differences in two similar methods of calculation.
But that is about timing rather than computational failure.)

To avoid some of the "singular gradient" issues, try package nlmrt. Note
that it's nlxb() has a slightly different call in that more arguments
need to be explicitly specified.


On 15-05-27 06:00 AM, [hidden email] wrote:

> Message: 34
> Date: Wed, 27 May 2015 01:23:35 +0000
> From: oussama belmejdoub <[hidden email]>
> To: "[hidden email]" <[hidden email]>
> Subject: [R] nls model singular gradient matrix at initial parameter
> estimates
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset="iso-8859-1"
> Greetings,
> I'm trying to use the nls function in my statistics project but I'm really finding lot of difficulties.
> I have a function called apinene_modele_prediction that calculates the estimations:
> library(expm); #exp of a matrixapinene_modele_prediction <- function(t,theta) { x0=c(100,0,0,0,0) A=matrix(c(-(theta[1]+theta[2]),theta[1],theta[2],0,0,0,0,0,0,0,0,0,-(theta[3]+theta[4]),theta[3],theta[4],0,0,0,0,0,0,0,theta[5],0,-theta[5]),5,5) X=x0 for (i in t[2:length(t)]){ X=c(X,x0%*%expm(A*i)) }return(X)}
> My "t" vector is given by:
> t=seq(0,100,by=2)
> And the real observations "y" ara given to us  in a txt file called "data.txt" that I have joined to this message.
> So when I try to fit the "theta" in my model starting with: theta=c(0.2,0.2,0.2,0.2,0.2)
> And doing:
> theta_appr <-nls(y~apinene_modele_prediction(t,theta),start=list(theta=c(0.2,0.2,0.2,0.2,0.2)))
> I always got the ERROR : singular gradient matrix at initial parameter estimates
> And, when I try: nls(y~apinene_modele_prediction(t,c(theta,theta,theta,theta,theta)),start=list(theta=0.2))
> I got the result: Nonlinear regression model  model: y ~ apinene_modele_prediction(t, c(theta, theta, theta, theta,     theta))   data: parent.frame()  theta0.04403 residual sum-of-squares: 219002
> But I need to have the elements of the theta to be different and not equal.
> Thanks in advance for your help.    
> -------------- next part --------------
> An embedded and charset-unspecified text was scrubbed...
> Name: data.txt
> URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150527/37052351/attachment-0001.txt>

[hidden email] mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.