我正在尝试使用以下代码运行nls并获取已知参数:
我创建了一个data.frame:
xx = 1:100
yy = 0.5*xx^2
dd = data.frame(xx,yy)
str(dd)
'data.frame': 100 obs. of 2 variables:
$ xx: int 1 2 3 4 5 6 7 8 9 10 ...
$ yy: num 0.5 2 4.5 8 12.5 18 24.5 32 40.5 50 ...
head(dd)
xx yy
1 1 0.5
2 2 2.0
3 3 4.5
4 4 8.0
5 5 12.5
6 6 18.0
我在数据上运行nls:
> nls(yy ~ A*(xx^B), data=dd)
Error in nls(yy ~ A * xx^B, data = dd) :
number of iterations exceeded maximum of 50
In addition: Warning message:
In nls(yy ~ A * xx^B, data = dd) :
No starting values specified for some parameters.
Initializing ‘A’, ‘B’ to '1.'.
Consider specifying 'start' or using a selfStart model
我尝试添加' start'参数:
> nls(yy ~ A*(xx^B), data=dd, start=c(A=0.1, B=0.1))
Error in numericDeriv(form[[3L]], names(ind), env) :
Missing value or an infinity produced when evaluating the model
错误在哪里?为什么我没有得到参数A = 0.5和B = 2?
答案 0 :(得分:2)
阅读?nls
帮助页面。特别是关于在人工"零残留"上使用nls的警告数据。试试
yy = 0.5*xx^2 + rnorm(length(xx))
添加一些噪音