評估插補:跨多個變數
到目前為止,我們已經介紹過如何檢視單一變數或成對變數及其插補值。不過,有時你會想同時查看多個變數的插補情況。為了達成這件事,你需要先做一些資料清理與重整。本課會示範如何進行這類資料整理;在 nabular 資料的情境下,這可能會有點棘手。shadow_long() 這個函式能把資料轉成適合這類視覺化的結構。
本練習屬於課程
在 R 中處理遺漏值
練習說明
- 使用
shadow_long()來收集ocean_imp_mean的插補資料,聚焦於humidity與air_temp_c。 - 列印並檢視資料。
- 使用
geom_histogram()以長條圖探索插補結果,將數值放在 x 軸、以遺漏狀態填色,並以variable分面呈現。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Gather the imputed data
ocean_imp_mean_gather <- shadow_long(___,
___,
___))
# Inspect the data
___
# Explore the imputations in a histogram
ggplot(ocean_imp_mean_gather,
aes(x = value, fill = value_NA)) +
geom_histogram() +
facet_wrap(~variable)