呈現結果
建立模型的最後一步,通常也是最重要的一步,就是分享結果。
在這個練習中,你會抽取郡層級的估計值,並用 ggplot2 繪圖。要得到每個郡的斜率估計,需要把郡層級的隨機效應斜率加到固定效應的斜率上。
除了這個加總以外,程式碼也會依照犯罪率(也就是斜率估計)對郡進行排序,幫助你更清楚地視覺化資料。
你先前配適的模型 glmer_out 已為你載入。
本練習屬於課程
R 的階層式與混合效果模型
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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)])