# nls not solving

7 messages
Open this post in threaded view
|

## nls not solving

 I am running the following nls equation. I tried it with data that excel was fitting and got the error: singular gradient matrix at initial parameter estimates I thought it was due to a low number of points (6), but when I create a dataset, I get the same problem. If I remove the parameter "a," then it can find a solution. Does anyone know what I can do to fit this model? vardata<- rnorm(73,mean=0,sd=5) x<-0:72 a<-1 b<-50 k<-0.05 l<-5 startt<-c(a,b,k,l) yf<-a+b*(1-exp(-k*(x-l))) y<-yf+vardata nmodel<-nls(y~a+b*(1-exp(-k*(x-l))), start=list(a=1,b=50,k=0.05,l=5)) In theory, practice and theory are the same. In practice, they are not - Albert Einstein
Open this post in threaded view
|

## Re: nls not solving

 By the way, sorry about the reposts. I subscribed but wasn't sure what was happening. Hopefully this worked. In theory, practice and theory are the same. In practice, they are not - Albert Einstein
Open this post in threaded view
|

## Re: nls not solving

 In reply to this post by Schatzi Well, since no one else has replied, let me state the obvious: The model is nonidentifiable.  It is of the form: y = a + b(1 - exp(kl)) - b exp(-kx) Suppose you have a solution. Suppose with your solution, a + b(1 -exp(kl)) = C, say. Then a = C - b(1-exp(kl)). Hence you have generated an infinite number of pairs by solving for one in terms of the other that give the exact same solution. That is, the model is nonidentifiable. Whence your error. Removing "a" or "l" makes the model identifiable. -- Bert On Mon, Feb 28, 2011 at 12:23 PM, Schatzi <[hidden email]> wrote: > I am running the following nls equation. I tried it with data that excel was > fitting and got the error: > singular gradient matrix at initial parameter estimates > I thought it was due to a low number of points (6), but when I create a > dataset, I get the same problem. If I remove the parameter "a," then it can > find a solution. Does anyone know what I can do to fit this model? > > vardata<- rnorm(73,mean=0,sd=5) > x<-0:72 > a<-1 > b<-50 > k<-0.05 > l<-5 > startt<-c(a,b,k,l) > yf<-a+b*(1-exp(-k*(x-l))) > y<-yf+vardata > > nmodel<-nls(y~a+b*(1-exp(-k*(x-l))), > start=list(a=1,b=50,k=0.05,l=5)) > > -- > View this message in context: http://r.789695.n4.nabble.com/nls-not-solving-tp3328647p3328647.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] 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. > -- Bert Gunter Genentech Nonclinical Biostatistics ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: nls not solving

 I am not sure how you simplified the model to: y = a + b(1 - exp(kl)) - b exp(-kx) I tried simplifying it but only got to: y = a + b - b * exp(kl) * exp(-kx) I agree that the model must not be identifiable. That makes sense, especially given that removing either a or l makes the model work. Can you please further explain the math though as I am not understanding it? I do not see you obtained your equation and when I tried to solve using your equation I got quite different numbers. Thank you. In theory, practice and theory are the same. In practice, they are not - Albert Einstein
Open this post in threaded view
|

## Re: nls not solving

 On 2011-02-28 14:14, Schatzi wrote: > I am not sure how you simplified the model to: > y = a + b(1 - exp(kl)) - b exp(-kx) > > I tried simplifying it but only got to: > y = a + b - b * exp(kl) * exp(-kx) > > I agree that the model must not be identifiable. That makes sense, > especially given that removing either a or l makes the model work. Can you > please further explain the math though as I am not understanding it? I do > not see you obtained your equation and when I tried to solve using your > equation I got quite different numbers. Thank you. You can obviously write your function as   f <- f(x, A, B, K) {A - B * exp(-Kx)} i.e. in terms of *3* parameters. In that form, it's apple pie for nls().   fm <- nls(y ~ f(x, A, B, K),             start = list(A = 50, B = 60, K = 1)   coef(fm)   xx <- seq(0, 72, length = 101)   yy <- predict(fm, newdata = list(x = xx))   plot(x, y)   lines(xx, yy, col = "red") Peter Ehlers ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.