[R] nls not solving

Peter Ehlers ehlers at ucalgary.ca
Tue Mar 1 01:31:43 CET 2011


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



More information about the R-help mailing list