2017-04-11 202 views
-1

我想要做一個非線性迴歸與邏輯函數brian s. cheng,基於 Fox & Weisberg奇異梯度誤差與R的nls/nlsLM

我想去的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))) 

回答

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 
+0

好像在正確的方向邁出的一步,但現在我(我有多個數據集是像這樣的,我需要做的是爲所有這些)我得到的錯誤'錯誤qr.default(.swts * attr(rhs,「gradient」)):NA/NaN/Inf在外部函數調用中(arg 1)'我在問題中發佈了代碼來說明我在做什麼。 – Make42

+0

我創建了一個顯示錯誤的pastebin:https://pastebin.com/ZiVxJQMk – Make42