Re: [R] nls not solving

2011-03-01 Thread Schatzi
Here is a reply by Bart:
Yes you're right (I should have taken off my glasses and looked closer).
However, the argument is essentially the same:

Suppose you have a solution with a,b,k,l. Then for any positive c, [a+b-bc]
+ [bc] + (bc) *exp(kl')exp(-kx) is also a solution, where l'
= l - log(c)/k  .

Cheers,
Bert

(Feel free to post this correction if you like)


This is from me:
The problem with dropping the l parameter is that it is supposed to
account for the lag component. This equation was published in the literature
and has been being solved in SAS. When I put it in excel, it solves, but not
very well as it comes to a different solution for each time that I change
the starting values. As such, I'm not sure how SAS solves for it and I'm not
sure what I should do about the equation. Maybe I should just drop the
parameter a. Thanks for the help.

-- 
View this message in context: 
http://r.789695.n4.nabble.com/nls-not-solving-tp3328647p3329936.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] nls not solving

2011-03-01 Thread Peter Ehlers

On 2011-03-01 06:38, Schatzi wrote:

Here is a reply by Bart:
Yes you're right (I should have taken off my glasses and looked closer).
However, the argument is essentially the same:

Suppose you have a solution with a,b,k,l. Then for any positive c, [a+b-bc]
+ [bc] + (bc) *exp(kl')exp(-kx) is also a solution, where l'
= l - log(c)/k  .

Cheers,
Bert

(Feel free to post this correction if you like)


This is from me:
The problem with dropping the l parameter is that it is supposed to
account for the lag component. This equation was published in the literature
and has been being solved in SAS. When I put it in excel, it solves, but not
very well as it comes to a different solution for each time that I change
the starting values. As such, I'm not sure how SAS solves for it and I'm not
sure what I should do about the equation. Maybe I should just drop the
parameter a. Thanks for the help.


When you say 'published in the literature' you should
provide a reference; you may be misinterpreting what's
published.

If SAS provides a 'solution', then there's an added
assumption being made (perhaps 'l' is being fixed?).
What Excel does is of little interest.

'Dropping' the parameter 'a' is equivalent to setting a=0.
You could also set, say, a = -10 or l = 50, or ...
The point is that, as Bert says, the model is
nonidentifiable.

Peter Ehlers

__
R-help@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] nls not solving

2011-02-28 Thread Schatzi
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.

__
R-help@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.


Re: [R] nls not solving

2011-02-28 Thread Schatzi
By the way, sorry about the reposts. I subscribed but wasn't sure what was
happening. Hopefully this worked.

-- 
View this message in context: 
http://r.789695.n4.nabble.com/nls-not-solving-tp3328647p3328659.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] nls not solving

2011-02-28 Thread Bert Gunter
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 a,l 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 adele_thomp...@cargill.com 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.

 __
 R-help@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.




-- 
Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@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.


Re: [R] nls not solving

2011-02-28 Thread Schatzi
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.

-- 
View this message in context: 
http://r.789695.n4.nabble.com/nls-not-solving-tp3328647p3328862.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] nls not solving

2011-02-28 Thread Peter Ehlers

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

__
R-help@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.