看板 R_Language 關於我們 聯絡資訊
我最近有一堆壓力的資料要分析,因為推測模式是 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 請問測試資料太乾淨反而抓不出模型是正常的嗎? -- 起初,他們追殺共產主義者,我沒有說話,因為我不是共產主義者; 接著,他們追殺猶太人,我沒有說話,因為我不是猶太人; 後來,他們追殺工會成員,我沒有說話,因為我不是工會成員; 此後,他們追殺天主教徒,我沒有說話,因為我是新教教徒; 最後,他們奔我而來,卻再也沒有人站起來為我說話了。 《First They Came(他們首次來時)》,Martin Niemoller牧師(1892-1984) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.176.35.82 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1534085006.A.B47.html
x88776544pc: 這點在 nls 的說明中 warning這塊有說, 與其方法有關 08/12 23:10
LIAR: 看到了,雖然看不懂XD,eps是甚麼啊? 08/13 23:17
LIAR: residual sum-of-squares在不同參數下應該會變化吧?為何 08/13 23:18
LIAR: 這樣還是需要noise這點我不懂。 08/13 23:18
andrew43: 牛頓法的過程需要超過一個方程式,但若只要單一個方程式 08/14 00:24
andrew43: 就可以完美解釋所有資料,也就不存在另一個不同的方程式 08/14 00:24
bmka: 沒搞清楚什麼是statistical model 08/15 13:08