我最近有一堆壓力的資料要分析,因為推測模式是 y ~ a/(x+b),所以想用nls解。
我先用假的資料
> x=seq(-4,-1.5,0.1)
> y=-1.58/(x-3.78)
> plot(x,y)
> m<-nls(y~a/(x+b))
Error in nls(y ~ a/(x + b)) : number of iterations exceeded maximum of 50
In addition: Warning message:
In nls(y ~ a/(x + b)) : No starting values specified for some parameters.
Initializing ‘a’, ‘b’ to '1.'.
Consider specifying 'start' or using a selfStart model
這樣會有錯誤。
但是如果我把y加上一些noise
> y=-1.58/(x-3.78)+rnorm(length(x),0,0.01)
> m<-nls(y~a/(x+b))
Warning message:
In nls(y ~ a/(x + b)) : No starting values specified for some parameters.
Initializing ‘a’, ‘b’ to '1.'.
Consider specifying 'start' or using a selfStart model
> m
Nonlinear regression model
model: y ~ a/(x + b)
data: parent.frame()
a b
-1.698 -4.339
residual sum-of-squares: 0.001832
Number of iterations to convergence: 9
Achieved convergence tolerance: 3.167e-06
>
這樣就可以解出a,b(理論值是-1.58,-3.78)
我想請問為何太乾淨的資料反而會跑不出來?
不加rnorm的y我甚至有試過直接帶入正確答案當起始值:
start = list(a=-1.58,b=-3.78),但是還是一樣有
number of iterations exceeded maximum of 50
請問測試資料太乾淨反而抓不出模型是正常的嗎?