Displaying the results
The last, and arguably most important step in creating a model, is sharing the results.
During this exercise, you'll extract out the county-level estimates and plot them with ggplot2. The county-level random-effect slopes need to be added to the fixed-effect slopes to get the slope estimates for each county.
In addition to this addition, the code includes ordering the counties by rate of crime (the slope estimates) to help visualize the data clearly.
The model you previously fit, glmer_out has been loaded for you.
Den här övningen är en del av kursen
Hierarchical and Mixed Effects Models in R
Interaktiv övning med praktiskt arbete
Testa den här övningen genom att slutföra den här exempelkoden.
# 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)])