代入の実行と追跡

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での欠損データの扱い方

Ayo berlatih!

Rでの欠損データの扱い方

Preparing Video For Download...