เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การประเมินการ impute (หลายโมเดลและหลายตัวแปร)

เมื่อสร้างโมเดล imputation ขึ้นมาแล้ว ควรเปรียบเทียบกับวิธีอื่นด้วยเสมอ

ในบทเรียนนี้ เราจะให้คุณเพิ่มโมเดล imputation สุดท้ายที่มีข้อมูลเพิ่มเติมซึ่งช่วยอธิบายความผันแปรในข้อมูลได้ดียิ่งขึ้น จากนั้นจะเปรียบเทียบค่าต่าง ๆ เช่นเดียวกับที่ทำในบทเรียนที่แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การจัดการข้อมูลที่หายไปใน R

ดูคอร์ส

คำแนะนำการฝึกหัด

โดยใช้ชุดข้อมูล oceanbuoys:

  • Impute ข้อมูลด้วย impute_lm() โดยเพิ่ม year เข้าไปในโมเดล
  • รวมวิธี imputation เข้าด้วยกัน โดยกำหนดให้ ocean_imp_mean อยู่ใน mean, ocean_imp_lm_wind อยู่ใน lm_wind และ ocean_imp_lm_wind_year อยู่ใน lm_wind_year
  • ดูค่าของ air_temp_c (บนแกน x) และ humidity (บนแกน y) โดยระบายสีตามค่าที่ขาดหาย และแบ่ง facet ตามโมเดล imputation

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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(~___)
แก้ไขและรันโค้ด