How to find good start values for nls function?

后端 未结 3 1604
野趣味
野趣味 2021-02-09 09:54

I don\'t understand why I can\'t have a nls function for these data. I have tried with a lot of different start values and I have always the same error.

Here is what I h

3条回答
  •  你的背包
    2021-02-09 10:55

    I struggle to find an interpretation to your parameters: a is a slope, b the speed of convergence, and a+c the limit, but c by itself does not seem to mean much. After reparametrizing your function, the problem disappears.

    f <- function (x, a,b,c) a + c * exp(-x/abs(b))
    nls(y~f(x, a, b, c), data=dt, start=list(a=1, b=75, c=-5), trace=TRUE)
    

    However, the value of c looks very, very high: that is probably why the model initially failed to converge.

    Nonlinear regression model
      model:  y ~ f(x, a, b, c) 
       data:  dt 
             a          b          c 
     1.006e+00  3.351e+00 -1.589e+08 
     residual sum-of-squares: 7.909e-05
    
    Number of iterations to convergence: 9 
    Achieved convergence tolerance: 2.232e-06 
    

    Here is another, more reasonable parametrization of the same function.

    g <- function (x, a,b,c) a * (1-exp(-(x-c)/abs(b)))
    nls(y~g(x, a, b, c), data=dt, start=list(a=1, b=75, c=-5), trace=TRUE)
    
    Nonlinear regression model
      model:  y ~ g(x, a, b, c) 
       data:  dt 
         a      b      c 
     1.006  3.351 63.257 
     residual sum-of-squares: 7.909e-05
    
    Number of iterations to convergence: 10 
    Achieved convergence tolerance: 1.782e-06 
    

提交回复
热议问题