2017-08-11 22 views
1

我有一個奇怪的問題繪製glm的擬合值。glm擬合值鏡像/將不匹配

我的代碼是:

Data <- data.frame("Sp" = c(111.4, 185, 231, 272.5, 309, 342, 371, 399, 
    424, 447, 469, 489, 508, 527, 543, 560, 575, 589, 603, 616, 630, 642, 653, 
    664, 675, 685, 695, 705, 714, 725, 731, 740), "nrC" = 1:32) 

modell <- glm(Sp ~ nrC, data = Data, family = Gamma) 
pred <- predict(modell, newdata = data.frame("nrC" = 1:32), type = "response") 

plot(Data$nrC, Data$Sp, xlim = c(0, 40), ylim = c(50, 1000)) 
lines(Data$nrC, pred, col = "blue") 

表示擬合值的藍線似乎是確定,除了被水平鏡像。
我對此比較新,所以也許我在這裏錯過了一些明顯的東西,但我無法弄清楚什麼是錯的。
這樣做與提供的數據here完全一樣。

我很感激任何提示!

回答

1

對於這個數據集,gamma分佈並不完全正確。圖中顯示的數據顯示了一個平方根查找函數。嘗試指定這樣的模型:

modell <- glm(Sp ~ sqrt(nrC), data = Data, family = gaussian) 
pred <- predict(modell, newdata = data.frame("nrC" = 1:32), type = "response") 

plot(Data$nrC, Data$Sp, xlim = c(0, 40), ylim = c(50, 1000)) 
lines(Data$nrC, pred, col = "blue") 
+0

非常感謝!現在看起來好多了。好像我需要更多地發掘分佈。 – Julian