R语言使用nls拟合,为什么总说循环次数大于50

使用R语言进行模型拟合,start那个里面应该填什么呀,运行后总是提示错误“循环次数大于50”,这是为什么呀

nls的数据源必须有误差。不能精确等于公式返回值(零残差)。循环次数大于50通常是使用 函数精确返回值 作为数据源去拟合函数。必须给y值加上随机误差。


z=function(x,a,b){a*sin(x)+b*cos(x)}
x=seq(1,10,9/500)
y=z(x,1,1) # a=1 b=1 æ˜¯æœŸæœ›æ‹Ÿåˆå‡ºçš„结果。
cor=data.frame(x=x,y=y)
cor$res=runif(length(cor$x),min=-0.005,max=0.005)
cor$yres=cor$y+cor$res
#yres =y加上随机误差,y是精确返回值
> nls(cor$yres~z(cor$x,a,b),data=cor,start=list(a=0.8,b=1.3))
Nonlinear regression model
  model: cor$yres ~ z(cor$x, a, b)
   data: cor
     a      b 
0.9999 1.0002 
 residual sum-of-squares: 0.004213

Number of iterations to convergence: 1 
Achieved convergence tolerance: 2.554e-07

#使用精确返回值拟合就会出错。
> nls(cor$y~z(cor$x,a,b),data=cor,start=list(a=1,b=1))
Error in nls(cor$y ~ z(cor$x, a, b), data = cor, start = list(a = 1, b = 1)) : 
  å¾ªçŽ¯æ¬¡æ•°è¶…过了50这个最大值
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-01
每张身份证.注册财付通的次数最大只能注册十次.比如说.你这个身份证注册了财付通.然后注销了.再第二次用这身份证注册财付通. 这身份证也就使用了两次了.无论是你注销.重...身份已超注册次数能解除吗本回答被网友采纳
相似回答