開始使用免費開始

在 R 擬合 Poisson 迴歸

在這個練習中,你會使用 glm() 擬合 Poisson 迴歸。 R 的 GLM 與線性模型使用相同的公式表示法:response ~ predictor。 不過,這個模型還需要用引數 family = ... 指定誤差或分佈家族。 若要擬合 Poisson 迴歸,將 family 設為 "poisson"(記得在 poisson 外面加上引號 ")。

你會使用一個模擬資料集,其中自變數為 time,應變數為 count

真實的資料例子可能是得分次數、網頁點擊次數,或是你在窗外看到的鳥類數量。

本練習屬於課程

R 的廣義線性模型

檢視課程

練習說明

  • 使用資料框 dat,以 poisson family 擬合一個以 time 預測 count 的 Poisson 迴歸。將模型存為 poisson_out
  • poisson_out 列印到螢幕上。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# fit y predicted by x with data.frame dat using the poisson family
poisson_out <- ___

# print the output
print(___)
編輯並執行程式碼