ブートストラップによる多重代入

R による欠損データの補完処理

Michal Oleszak

Machine Learning Engineer

代入による不確実性

  • 代入は通常、分析やモデリングの前処理として行われます。
  • 欠損値の推定には不確実性が伴います。
  • この不確実性は、代入済みデータの分析において考慮する必要があります。

Ranjit Lall著「How Multiple Imputation Makes a Difference」の表紙ヘッダー。

ほぼ半数の研究で、主要な結果が消失する

R による欠損データの補完処理

ブートストラップ

ブートストラップ = 復元抽出で元のサイズのデータを生成

2つのモックデータフレーム。左は「元データ」で各行が異なる色。右は「ブートストラップサンプル」で一部の行が重複し、一部が欠落している。

R による欠損データの補完処理

ブートストラップによる多重代入

ブートストラップによる代入の5段階を示す図。「元データ」から3つの「ブートストラップサンプル」に矢印が伸び、それぞれ「代入」→「モデリング/分析」→「結果の分布」へと続く。

R による欠損データの補完処理

ブートストラップ代入:メリットとデメリット

メリット:

  • あらゆる代入手法に対応可能。
  • 解析的に求めにくい量を近似できる。
  • MCARおよびMARデータに対応。

デメリット:

  • 反復数が多い場合や計算コストが高い場合は低速。
R による欠損データの補完処理

ブートストラップの実践

calc_correlation <- function(data, indices) {






  # Return the correlation coefficient
  return(corr_coeff)
}
R による欠損データの補完処理

ブートストラップの実践

calc_correlation <- function(data, indices) {
  # Get bootstrap sample
  data_boot <- data[indices, ]




  # Return the correlation coefficient
  return(corr_coeff)
}
R による欠損データの補完処理

ブートストラップの実践

calc_correlation <- function(data, indices) {
  # Get bootstrap sample
  data_boot <- data[indices, ]
  # Impute with kNN imputation
  data_imp <- kNN(data_boot)


  # Return the correlation coefficient
  return(corr_coeff)
}
R による欠損データの補完処理

ブートストラップの実践

calc_correlation <- function(data, indices) {
  # Get bootstrap sample
  data_boot <- data[indices, ]
  # Impute with kNN imputation
  data_imp <- kNN(data_boot)
  # Calculate correlation between Weight and TotChol
  corr_coeff <- cor(data_imp$Weight, data_imp$TotChol)
  # Return the correlation coefficient
  return(corr_coeff)
}
R による欠損データの補完処理

ブートストラップの実践

library(boot)
boot_results <- boot(nhanes, statistic = calc_correlation, R = 50)
print(boot_results)
ORDINARY NONPARAMETRIC BOOTSTRAP

Call:
boot(data = nhanes, statistic = calc_correlation, R = 50)

Bootstrap Statistics :
      original      bias    std. error
t1* 0.03028306 0.007385452  0.04207152
R による欠損データの補完処理

ブートストラップ結果の可視化

plot(boot_results)

ブートストラップ結果の分布を示すヒストグラムとQ-Qプロット。いずれも分布が正規分布に近いことを示している。

R による欠損データの補完処理

ブートストラップ信頼区間

boot_ci <- boot.ci(boot_results, conf = 0.95, type = "norm")
print(boot_ci)
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 50 bootstrap replicates

CALL : 
boot.ci(boot.out = boot_results, conf = 0.95, type = "norm")

Intervals : 
Level      Normal        
95%   (-0.0596,  0.1054 )  
Calculations and Intervals on Original Scale
R による欠損データの補完処理

ブートストラップを練習しましょう!

R による欠損データの補完処理

Preparing Video For Download...