合并并比较多种插补模型
为了评估不同的插补方法,我们需要把它们放入同一个数据框中。接下来,您将使用数据集 oceanbuoys 比较三种处理缺失数据的方法。
- 第一种方法只使用完整观测(completed cases),已加载为
ocean_cc。 - 第二种方法使用基于风的线性模型进行插补预测,已加载为
ocean_imp_lm_wind。
您将创建第三个插补数据集 ocean_imp_lm_all,使用线性模型,并用变量 wind_ew、wind_ns、year、latitude、longitude 来插补变量 sea_temp_c、air_temp_c 和 humidity。
然后,您将把所有数据集合并在一起(ocean_cc、ocean_imp_lm_wind 和 ocean_imp_lm_all),命名为 bound_models。
本练习是课程的一部分
在 R 中处理缺失数据
练习说明
- 创建名为
ocean_imp_lm_all的插补数据集,使用线性模型,并用变量wind_ew、wind_ns、year、latitude、longitude来插补变量sea_temp_c、air_temp_c和humidity。 - 将所有数据集合并到同一个对象中,命名为
bound_models。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create an imputed dataset using a linear models
ocean_imp_lm_all <- bind_shadow(oceanbuoys) %>%
add_label_shadow() %>%
impute_lm(sea_temp_c ~ wind_ew + wind_ns + ___ + ___ + ___) %>%
impute_lm(air_temp_c ~ wind_ew + wind_ns + ___ + ___ + ___) %>%
impute_lm(humidity ~ wind_ew + wind_ns + ___ + ___ + ___)
# Bind the datasets
bound_models <- bind_rows(cc = ___,
imp_lm_wind = ___,
imp_lm_all = ___,
.id = "imp_model")
# Look at the models
bound_models