為解釋而建模的問題

在 Tidyverse 中進行資料建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

回顧:一般建模架構公式

$$ y = f(\vec{x}) + \epsilon $$

其中:

  • $y$:關注的結果變數
  • $\vec{x}$:解釋/預測變數
  • $f()$:$y$ 與 $\vec{x}$ 的關係函式,亦即「訊號」
  • $\epsilon$:非系統性誤差,亦即「雜訊」
在 Tidyverse 中進行資料建模

建模問題

考慮 $y = f(\vec{x}) + \epsilon$。

  1. $f()$ 與 $\epsilon$ 為未知
  2. 資料中有 $y$ 與 $\vec{x}$ 的 $n$ 筆觀測可用
  3. 目標:擬合模型 $\hat{f}()$,在忽略 $\epsilon$ 下「近似」$f()$
  4. 換句話說:把「訊號」與「雜訊」分開
  5. 之後可產生擬合/預測值 $\hat{y} = \hat{f}(\vec{x})$
在 Tidyverse 中進行資料建模

為解釋而建模:範例

在 Tidyverse 中進行資料建模

關係的 EDA

library(ggplot2)
library(dplyr)
library(moderndive)

ggplot(evals, aes(x = age, y = score)) +
  geom_point() + 
  labs(x = "age", y = "score",
       title = "Teaching score over age")
在 Tidyverse 中進行資料建模

關係的 EDA

在 Tidyverse 中進行資料建模

抖動散佈圖

library(ggplot2)
library(dplyr)
library(moderndive)

# Use geom_jitter() instead of geom_point()
ggplot(evals, aes(x = age, y = score)) +
  geom_jitter() + 
  labs(x = "age", y = "score",
       title = "Teaching score over age (jittered)")
在 Tidyverse 中進行資料建模

抖動散佈圖

在 Tidyverse 中進行資料建模

相關係數

在 Tidyverse 中進行資料建模

計算相關係數

evals %>% 
  summarize(correlation = cor(score, age))
# A tibble: 1 x 1
  correlation
        <dbl>
1      -0.107
在 Tidyverse 中進行資料建模

一起來練習吧!

在 Tidyverse 中進行資料建模

Preparing Video For Download...