R的nls / nlsLM

时间:2017-04-11 14:13:31

标签: r regression non-linear-regression

我希望使用像brian s. cheng这样的logit函数进行非线性回归 Fox & Weisberg

我想去most pain-free waynls一起去了,但得到了错误

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
NA/NaN/Inf in foreign function call (arg 1)

我检查过我没有NaN, Inf or similar,发现我有Singular gradient error。但是,我不使用零残留人工数据(因为不应该)。因为它与nls的内部有关,所以我转向nlsLM,但错误仍然存​​在。我该怎么办?

我的数据是https://pastebin.com/iTXQcBzB

我的代码是

nlsLM(y ~ SSlogis(x, Asym, xmid, scal), mydata) % Error in lm.fit
nlsLM(y ~ theta1/(1 + exp(-(theta2 + theta3 * x))), mydata) % Singular gradient

提供的数据实际上只是一部分而我的完整代码更像是

mydata %>%
  group_by(groupNr) %>%
  do(regmodel = nls(.$y ~ SSlogis(.$x, Asym, xmid, scal), ., 
     start = c(Asym = max(.$y), xmid = mean(.$x), scal = 1)))

1 个答案:

答案 0 :(得分:0)

您需要更好的起始值:

nls(y ~ SSlogis(x, Asym, xmid, scal), mydata, 
    start = c(Asym = max(mydata$y), xmid = mean(mydata$x), scal = 1))

,并提供:

Nonlinear regression model
  model: y ~ SSlogis(x, Asym, xmid, scal)
   data: mydata
     Asym      xmid      scal 
2.304e+04 5.519e+00 3.065e-01 
 residual sum-of-squares: 477139282

Number of iterations to convergence: 8 
Achieved convergence tolerance: 5.271e-06