R에서 대치(Imputation)로 결측치 다루기
Michal Oleszak
Machine Learning Engineer

장점:
MNAR 민감도 분석 가능.
단점:
nhanes를 20회 대치:
library(mice)
nhanes_multiimp <- mice(nhanes, m = 20)
각 대치 데이터셋에 선형회귀 적합:
lm_multiimp <- with(nhanes_multiimp, lm(Weight ~ Height + TotChol + PhysActive))
회귀 결과 통합:
lm_pooled <- pool(lm_multiimp)
summary(lm_pooled, conf.int = TRUE, conf.level = 0.95)
estimate std.error statistic df p.value 2.5 % 97.5 %
(Intercept) -122.964 10.933 -11.247 735.389 0.000 -144.428 -101.500
Height 1.086 0.060 18.158 796.106 0.000 0.968 1.203
TotChol 2.653 0.884 3.003 305.460 0.003 0.915 4.392
PhysActive -1.746 1.422 -1.228 733.957 0.220 -4.536 1.045

mice()의 defaultMethod 인자: 길이 4의 문자열 벡터로 다음을 지정합니다.
nhanes_multiimp <- mice(nhanes, m = 20,
defaultMethod = c("pmm", "logreg", "polyreg", "polr"))
predictorMatrix는 각 변수를 대치할 때 사용할 예측 변수를 결정합니다.
nhanes_multiimp <- mice(nhanes, m = 20)
nhanes_multiimp$predictorMatrix
Age Gender Weight Height Diabetes TotChol Pulse PhysActive
Age 0 1 1 1 1 1 1 1
Gender 1 0 1 1 1 1 1 1
Weight 1 1 0 1 1 1 1 1
Height 1 1 1 0 1 1 1 1
Diabetes 1 1 1 1 0 1 1 1
TotChol 1 1 1 1 1 0 1 1
Pulse 1 1 1 1 1 1 0 1
PhysActive 1 1 1 1 1 1 1 0
pred_mat <- quickpred(nhanes, mincor = 0.25)
nhanes_multiimp <- mice(nhanes, m = 20, predictorMatrix = pred_mat)
print(pred_mat)
Age Gender Weight Height Diabetes TotChol Pulse PhysActive
Age 0 0 0 0 0 0 0 0
Gender 0 0 0 0 0 0 0 0
Weight 1 1 0 0 0 0 1 0
...
R에서 대치(Imputation)로 결측치 다루기