Get startedGet started for free

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.

This exercise is part of the course

Hierarchical and Mixed Effects Models in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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)])
Edit and Run Code