資料是隨機缺漏嗎?

R 的可擴展資料處理

Michael Kane

Assistant Professor, Yale University

R 的可擴展資料處理

缺漏資料的型態

  • Missing Completely at Random (MCAR)
  • Missing at Random (MAR)
  • Missing Not at Random (MNAR)
R 的可擴展資料處理

MCAR

Missing Completely at Random

  • 無法預測哪些值會缺漏
  • 可直接刪除缺漏資料
R 的可擴展資料處理

MAR

Missing at Random

  • 缺漏與資料集中的其他變數有關
  • 使用多重插補推測可能的缺漏值
R 的可擴展資料處理

MNAR

Missing Not at Random

  • 不是 MCAR 或 MAR
  • 變數之間存在確定性關係
R 的可擴展資料處理

本課如何處理缺漏資料

  • 完整處理缺漏超出本課程範圍

  • 我們會檢查資料是否可能為 MCAR,並刪除缺漏值

R 的可擴展資料處理

快速檢查 MAR

  • 將某欄重新編碼:缺漏為 1,否則為 0
  • 以邏輯斯迴歸回歸其他變數到該欄
  • 顯著的 p 值表示可能為 MAR
  • 對其他有缺漏的欄重複此步驟
  • 有些 p 值可能偶然顯著,請依回歸次數調整顯著性門檻
R 的可擴展資料處理

MAR 快速檢查範例

# Our dependent variable
is_missing <- rbinom(1000, 1, 0.5)

# Our independent variables data_matrix <- matrix(rnorm(1000*10), nrow = 1000, ncol = 10) # A vector of p-values we'll fill in p_vals <- rep(NA, ncol(data_matrix))
R 的可擴展資料處理

MAR 快速檢查範例

# Perform logistic regression
for (j in 1:ncol(data_matrix)) {
 s <- summary(glm(is_missing ~ data_matrix[, j]), 
              family = binomial)
              p_vals[j] <- s$coefficients[2, 4]
 }

# Show the p-values p_vals
0.5930082 0.7822695 0.7560343 0.3689330 0.8757048 
0.8812320 0.8281008 0.4888898 0.4781299 0.5655739
R 的可擴展資料處理

一起來練習吧!

R 的可擴展資料處理

Preparing Video For Download...