R에서 대치(Imputation)로 결측치 다루기
Michal Oleszak
Machine Learning Engineer
대치(Imputation) = 결측값에 대한 합리적 추정값을 넣는 것
이 장에서는 공여자 기반 방법을 다룹니다:

평균 대치는 장기 평균을 중심으로 무작위 변동하는 시계열에 유리합니다.
단면 자료에는 보통 매우 좋지 않습니다:
과제: NHANES에서 Height와 Weight를 평균 대치합니다.
nhanes <- nhanes %>%
mutate(Height_imp = ifelse(is.na(Height), TRUE, FALSE)) %>%
mutate(Weight_imp = ifelse(is.na(Weight), TRUE, FALSE))
Height와 Weight의 결측값을 각각의 평균으로 바꿉니다.nhanes_imp <- nhanes %>%
mutate(Height = ifelse(is.na(Height), mean(Height, na.rm = TRUE), Height)) %>%
mutate(Weight = ifelse(is.na(Weight), mean(Weight, na.rm = TRUE), Weight))
nhanes_imp %>%
select(Weight, Height, Height_imp, Weight_imp) %>%
head()
Weight Height Height_imp Weight_imp
1 73.20000 166.2499 TRUE FALSE
2 72.30000 166.2499 TRUE FALSE
3 57.70000 158.9000 FALSE FALSE
4 88.90000 183.3000 FALSE FALSE
5 45.10000 157.6000 FALSE FALSE
6 66.77065 158.4000 FALSE TRUE
nhanes_imp %>% select(Weight, Height, Height_imp, Weight_imp) %>% marginplot(delimiter="imp")

변수 간 관계 훼손:
Height와 Weight를 평균 대치하면 양의 상관이 약해집니다.대치값의 변동성 없음:

R에서 대치(Imputation)로 결측치 다루기