Menampilkan hasil
Langkah terakhir, dan bisa dibilang yang paling penting dalam membuat model, adalah membagikan hasilnya.
Dalam latihan ini, Anda akan mengekstrak estimasi tingkat county dan memvisualisasikannya dengan ggplot2. Kemiringan efek-acak tingkat county perlu ditambahkan ke kemiringan efek-tetap untuk mendapatkan estimasi kemiringan bagi setiap county.
Selain penjumlahan tersebut, kode juga mengurutkan county berdasarkan tingkat kejahatan (estimasi kemiringan) untuk membantu memvisualisasikan data dengan jelas.
Model yang sebelumnya Anda sesuaikan, glmer_out, telah dimuat untuk Anda.
Latihan ini adalah bagian dari kursus
Model Hierarki dan Mixed Effects di R
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Extract out the fixed-effect slope for Year2
Year2_slope <- fixef(___)['Year2']
# Extract out the random-effect slopes for county
county_slope <- ranef(___)$County
# Create a new column for the slope
county_slope$slope <- county_slope$Year2 + Year2_slope
# Use the row names to create a county name column
county_slope$county <- rownames(county_slope)
# Create an ordered county-level factor based upon slope values
county_slope$county_plot <- factor(county_slope$county,
levels = county_slope$county[order(county_slope$slope)])