Poisson 迴歸

R 的廣義線性模型

Richard Erickson

Instructor

足球示例

R 的廣義線性模型

Poisson 分布(λ=2、10)與相同參數常態分布的示意圖。

R 的廣義線性模型

Poisson 分布

  • 離散整數:x = 0, 1, 2, 3, ...

  • 期望與變異數參數 $\lambda$

  • $P(x) = \frac{\lambda^x e^{-\lambda}}{x!}$

  • 固定區域/時間(例如每場比賽的進球數)

R 的廣義線性模型

R 中的 Poisson 分布

    dpois(x = ..., lambda = ...)
R 的廣義線性模型

R 中 GLM 的需求

  • 離散計數:0, 1, 2, 3...
  • 已定義的區域與時間
  • 係數為對數尺度
R 的廣義線性模型

R 中的 Poisson GLM

glm(y ~ x, data = dat, family = 'poisson')
R 的廣義線性模型

不適用 Poisson 分布的情況

  • 非計數或非正數資料(如 1.4 或 -2)
  • 樣本區域或時間不固定(如 trees km$^{-1}$ vs. trees m$^{-1}$)
  • 平均數 $\gtrsim$30
  • 過度離散資料
  • 零過度資料
R 的廣義線性模型

公式與截距

  • 比較或截距
  • 比較 formula = y ~ x
  • 無截距 formula = y ~ x - 1
R 的廣義線性模型

每場進球數

  • 兩位球員,要用哪種做法?
  • 想比較球員差異,用比較模型:

     glm(goal ~ player, data = scores, family = "poisson")
    
  • 想知道每位球員的平均值,用無截距:

     glm(goal ~ player - 1, data = scores, family = "poisson")
    
R 的廣義線性模型

一起來練習吧!

R 的廣義線性模型

Preparing Video For Download...