開始使用免費開始

評估插補(多個模型與變數)

當你建立插補模型時,把它拿來和另一種方法比較通常是個好主意。

在這個單元中,你要再加入一個最終的插補模型,額外納入一個有助於解釋資料變異的資訊。接著,如同上一個單元,你會比較這些值。

本練習屬於課程

在 R 中處理遺漏值

檢視課程

練習說明

使用 oceanbuoys 資料集:

  • 使用 impute_lm() 進行插補,並把 year 加入模型。
  • 將各種插補方法合併:把 ocean_imp_mean 放到 meanocean_imp_lm_wind 放到 lm_windocean_imp_lm_wind_year 放到 lm_wind_year
  • 檢視 air_temp_c(x 軸)與 humidity(y 軸)的值,依是否為遺漏值著色,並依插補模型分面。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Build a model adding year to the outcome
ocean_imp_lm_wind_year <- bind_shadow(___) %>%
  impute_lm(air_temp_c ~ wind_ew + wind_ns + ___) %>%
  impute_lm(humidity ~ wind_ew + wind_ns + ___) %>%
  add_label_shadow()

# Bind the mean, lm_wind, and lm_wind_year models together
bound_models <- bind_rows(mean = ocean_imp_mean,
                          lm_wind = ocean_imp_lm_wind,
                          lm_wind_year = ___,
                          .id = "imp_model")

# Explore air_temp and humidity, coloring by any missings, and faceting by imputation model
ggplot(___, aes(x = ___, y = ___, color = any_missing)) + 
  geom_point() + facet_wrap(~___)
編輯並執行程式碼