결측치: 무엇이 잘못될 수 있나

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

Michal Oleszak

Machine Learning Engineer

학습 내용

이 과정을 마치면 다음을 수행할 수 있습니다:

  • 결측치가 왜 별도 처리가 필요한지 이해합니다.
  • 통계 검정과 시각화 도구로 결측 패턴을 탐지합니다.
  • 통계·머신러닝 모델로 대치(imputation)를 수행합니다.
  • 대치로 인한 불확실성을 분석과 예측에 반영해 더 견고하게 만듭니다.
R에서 대치(Imputation)로 결측치 다루기

선수 지식

이 과정은 다음 주제에 익숙하다고 가정합니다:

  • dplyr과 파이프 연산자(%>%)로 기본 데이터 조작
  • 선형/로지스틱 회귀 모델(lm(), glm())
  • 기본 확률 개념: 확률변수, 분포
R에서 대치(Imputation)로 결측치 다루기

결측치 기본

결측치를 다루는 최선의 방법은 처음부터 없게 하는 것입니다.

안타깝게도 결측치는 어디에나 있습니다:

  • 설문조사 무응답
  • 데이터 수집 장비의 기술적 문제
  • 서로 다른 출처의 데이터 결합
  • ...

결측치에 항상 유의해야 합니다.

1 Orchard, T., and M. A. Woodbury. 1972. “A Missing Information Principle: Theory and Applications.” In Proceedings of the Sixth Berkeley Symposium on Mathematical Statistics and Probability, 1:697–715.
R에서 대치(Imputation)로 결측치 다루기

NHANES 데이터

head(nhanes, 3)
  Age Gender Weight Height Diabetes TotChol Pulse PhysActive
1  16   male   73.2  172.0    FALSE    3.00    76       TRUE
2  17   male   72.3  176.0    FALSE    2.61    74       TRUE
3  12   male   57.7  158.9    FALSE    4.27    80       TRUE
nhanes %>% is.na() %>% colSums()
Age     Gender     Weight     Height   Diabetes    TotChol    Pulse   PhysActive 
0       0          9          8        1            85        32      26
R에서 대치(Imputation)로 결측치 다루기

불완전한 데이터로 선형 회귀

model_1 <- lm(Diabetes ~ Age + Weight, 
              data = nhanes)

summary(model_1)의 일부:

Residual standard error: 0.08571 on 804 
degrees of freedom (10 observations 
deleted due to missingness)

Adjusted R-squared:  0.005706 
F-statistic: 3.313 on 2 and 804 DF,  
p-value: 0.03691
model_2 <- lm(Diabetes ~ Age + Weight +
              TotChol, data = nhanes)

summary(model_2)의 일부:

Residual standard error: 0.08264 on 718 
degrees of freedom (95 observations
deleted due to missingness)

Adjusted R-squared:  0.008422 
F-statistic: 3.041 on 3 and 718 DF,
p-value: 0.02834
R에서 대치(Imputation)로 결측치 다루기

핵심 요점

  • 통계 소프트웨어가 결측치를 조용히 무시하는 경우가 있습니다.
  • 그 결과, 서로 다른 모델을 비교하기 어려울 수 있습니다.
  • 불완전한 관측치를 모두 제거하면 편향이 발생할 수 있습니다.
  • 결측치가 있으면 반드시 적절히 처리해야 합니다.
R에서 대치(Imputation)로 결측치 다루기

연습해 봅시다!

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

Preparing Video For Download...