How to find good start values for nls function?

后端 未结 3 1605
野趣味
野趣味 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:50

    This can be written with two linear parameters (.lin1 and .lin2) and one nonlinear parameter (b) like this:

    a*(1-exp(-x/b)) + c  
    = (a+c) - a * exp(-x/b)
    = .lin1 + .lin2 * exp(-x/b)
    

    where .lin1 = a+c and .lin2 = -a (so a = - .lin2 and c = .lin1 + .lin2) This lets us use "plinear" which only requires specification of a starting value for the single nonlinear parameter (eliminating the problem of how to set the starting values for the other parameters) and which converges despite the starting value of b=75 being far from that of the solution:

    nls(y ~ cbind(1, exp(-x/b)), start = list(b = 75), alg = "plinear")
    

    Here is the result of a run from which we can see from the size of .lin2 that the problem is badly scaled:

    > x <- c(77.87,87.76,68.6,66.29)
    > y <- c(1,1,0.8,0.6)
    > nls(y ~ cbind(1, exp(-x/b)), start = list(b = 75), alg = "plinear")
    Nonlinear regression model
      model:  y ~ cbind(1, exp(-x/b)) 
       data:  parent.frame() 
             b      .lin1      .lin2 
     3.351e+00  1.006e+00 -1.589e+08 
     residual sum-of-squares: 7.909e-05
    
    Number of iterations to convergence: 9 
    Achieved convergence tolerance: 9.887e-07 
    > R.version.string
    [1] "R version 2.14.2 Patched (2012-02-29 r58660)"
    > win.version()
    [1] "Windows Vista (build 6002) Service Pack 2"
    

    EDIT: added sample run and comment on scaling.

提交回复
热议问题