繪製 Poisson 迴歸

R 的廣義線性模型

Richard Erickson

Instructor

何時在 Poisson 中使用 geom_smooth

  • 最適合連續自變數
  • 例如:劑量增加與每 cm$^2$ 的癌細胞數
  • 否則改用 boxplot 或類似圖形工具
R 的廣義線性模型

癌細胞劑量研究

  • 模擬資料
  • 劑量反應
    • x:Dose
    • y:每 cm$^2$ 的癌細胞數
R 的廣義線性模型

繪製散點

ggplot(data = dat, aes(x = dose, y = cells)) +
    geom_point()

含散點的 ggplot

R 的廣義線性模型

抖動散點

ggplot(data = dat, aes(x = dose, y = cells)) +
   geom_jitter(width = 0.05, height = 0.05)

ggplot2 抖動散點示例。

R 的廣義線性模型

geom_smooth()

ggplot(data = dat, aes(x = dose, y = cells)) +
   geom_jitter(width = 0.05, height = 0.05)
   geom_smooth()

在抖動散點上疊加預設 geom_smooth() 的示例

R 的廣義線性模型

在 geom_smooth() 中使用 GLM

ggplot(data = dat, aes(x = dose, y = cells)) +
   geom_jitter(width = 0.05, height = 0.05)
   geom_smooth(method = 'glm')

使用 geom_smooth() 與預設 GLM(即 LM)的示例

R 的廣義線性模型

在 geom_smooth() 中的 Poisson GLM

ggplot(data = dat, aes(x = dose, y = cells)) +
   geom_jitter(width = 0.05, height = 0.05) +
   geom_smooth(method = 'glm', method.args = list(family = 'poisson'))

Poisson 迴歸圖示例

R 的廣義線性模型

步驟總結

  • 繪製不重疊的點
  • 加上 Poisson 趨勢線
  • 美化圖表(此處略)
R 的廣義線性模型

一起來練習吧!

R 的廣義線性模型

Preparing Video For Download...