我最近有一堆压力的资料要分析,因为推测模式是 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
请问测试资料太干净反而抓不出模型是正常的吗?