评估插补:跨多个变量
到目前为止,我们已经介绍了如何查看单个变量或成对变量及其插补值。不过,有时您需要同时查看多个变量的插补情况。为此,您需要进行一些数据清洗与重整。本课将讲解如何完成这类数据整理;在处理 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)