用於解釋的建模背景

在 Tidyverse 中進行資料建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

課程總覽

  1. 建模導論:理論與術語
  2. 迴歸:
    • 簡單線性迴歸
    • 多元迴歸
  3. 模型評估
在 Tidyverse 中進行資料建模

一般建模框架公式

$$

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

其中:

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

兩種建模情境

建模目的可為:

  • 解釋:$\vec{x}$ 為「解釋」變數
  • 預測:$\vec{x}$ 為「預測」變數
在 Tidyverse 中進行資料建模

用於解釋的建模範例

德州大學奧斯汀分校一項關於教學評分的研究(可於 openintro.org 取得)。

「問題」:能否根據多種教師屬性來解釋教學評分的差異?

「變數」:

  • $y$:依學生評量計算的平均教學 score
  • $\vec{x}$:如 rankgenderagebty_avg 等屬性
在 Tidyverse 中進行資料建模

用於解釋的建模範例

來自 moderndive 套件(ModernDive.com):

library(dplyr)
library(moderndive)
glimpse(evals)
Observations: 463
Variables: 13
$ ID           <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
$ score        <dbl> 4.7, 4.1, 3.9, 4.8, 4.6, 4.3...
$ age          <int> 36, 36, 36, 36, 59, 59, 59, 51...
$ bty_avg      <dbl> 5.000, 5.000, 5.000, 5.000...
$ gender       <fct> female, female, female, female...
...
在 Tidyverse 中進行資料建模

探索性資料分析

探索性資料分析(EDA)的三個基本步驟:

  1. 檢視資料
  2. 建立視覺化
  3. 計算摘要統計
在 Tidyverse 中進行資料建模

探索性資料分析

library(ggplot2)
ggplot(evals, aes(x = score)) +
  geom_histogram(binwidth = 0.25) + 
  labs(x = "teaching score", y = "count")
在 Tidyverse 中進行資料建模

探索性資料分析

在 Tidyverse 中進行資料建模

探索性資料分析

# Compute mean, median, and standard deviation
evals %>%
  summarize(mean_score = mean(score), 
            median_score = median(score),
            sd_score = sd(score))
# A tibble: 1 x 3
  mean_score median_score sd_score
       <dbl>        <dbl>    <dbl>
1       4.17          4.3    0.544
在 Tidyverse 中進行資料建模

一起來練習吧!

在 Tidyverse 中進行資料建模

Preparing Video For Download...