結合並比較多種插補模型
為了評估不同的插補方法,我們需要把它們放進同一個 dataframe。接下來,你會使用資料集 oceanbuoys 比較三種處理遺漏值的方法。
- 第一種方法只使用完整觀測(complete 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