대치 수행 및 추적

R에서 결측치 다루기

Nicholas Tierney

Statistician

학습 개요

대치로 데이터 구조 이해하기

대치값 시각화와 탐색

  • 결측 탐색을 위한 대치
  • 결측값 추적
  • 대치값과 데이터 비교 시각화
R에서 결측치 다루기

대치를 활용한 데이터 구조 이해

impute_below(c(5,6,7,NA,9,10))
5.00000  6.00000  7.00000  4.40271  9.00000 10.00000
R에서 결측치 다루기

impute_below

  • impute_below_if():
impute_below_if(data, is.numeric)
  • impute_below_at():
impute_below_at(data, vars(var1,var2))
  • impute_below_all():
impute_below_all(data)
R에서 결측치 다루기

결측값 추적

df
# A tibble: 6 x 1
   var1
  <dbl>
1     5
2     6
3     7
4    NA
5     9
6    10
impute_below_all(df)
# A tibble: 6 x 1
   var1
  <dbl>
1  5   
2  6   
3  7   
4  4.40
5  9   
6 10
R에서 결측치 다루기

결측값 추적

bind_shadow(df)
# A tibble: 6 x 2
   var1 var1_NA
  <dbl> <fct>  
1  5    !NA    
2  6    !NA    
3  7    !NA    
4  NA    NA     
5  9    !NA    
6 10    !NA
bind_shadow(df) %>% impute_below_all()
# A tibble: 6 x 2
   var1 var1_NA
  <dbl> <fct>  
1  5    !NA    
2  6    !NA    
3  7    !NA    
4  4.40 NA     
5  9    !NA    
6 10    !NA
R에서 결측치 다루기

히스토그램으로 대치값과 실제값 비교 시각화

aq_imp <- airquality %>%
   bind_shadow() %>% 
   impute_below_all()

ggplot(aq_imp,
       aes(x = Ozone,
           fill = Ozone_NA)) + 
   geom_histogram()

R에서 결측치 다루기

패싯으로 대치값과 실제값 비교 시각화

ggplot(aq_imp,
       aes(x = Ozone,
           fill = Ozone_NA)) + 
  geom_histogram() + 
  facet_wrap(~ Month)

R에서 결측치 다루기

패싯으로 대치값 시각화

ggplot(aq_imp,
       aes(x = Ozone,
           fill = Ozone_NA)) + 
  geom_histogram() + 
  facet_wrap(~ Solar.R_NA)

R에서 결측치 다루기

산점도로 대치값과 실제값 비교 시각화

aq_imp <- airquality %>%
  bind_shadow() %>% 
  add_label_shadow() %>%
  impute_below_all()

ggplot(aq_imp,
       aes(x = Ozone,
           y = Solar.R,
           color = any_missing)) + 
  geom_point()

R에서 결측치 다루기

Vamos praticar!

R에서 결측치 다루기

Preparing Video For Download...