1. Visually inspect the fit of your models
Using glance() you learned which of your 77 models fit the underlying data well and which do not.
You can get more insight into the fit of a model by comparing the original values of life expectancy to the ones predicted by the model for each observation.
2. Building augmented datframes
To do this you first need to build a data frame that contains both the predicted and the original values.
This requires first using map() and augment() to work on the list column containing the models to create nested data frames containing both the original and the predicted values. Then you can use unnest() on this new column to simplify these data frames allowing further exploration.
Let's visualize some of these models.
3. Model for Italy $R^2: 0.99$
First, let's look at the Italy model, where, based on the rsquared of 0.99, we can expect that a linear model will fit the data well.
You can compare the fit of the model with the original data by plotting both on the same plot.
In this example I used ggplot2 to plot the original values of life expectancy as a scatterplot using the geom_point() layer and I added the linear model fit as a red line using the geom_line() layer.
Using this plot it is clear that the model was able to fit the data well.
4. Model for Fiji $R^2: 0.82$
Next let's look at Fiji model which has an r-squared value lower than the model for Italy.
By plotting this data you can see that a linear model does a decent job, but there is clearly room for improvement since it looks like after 1990 the growth of life expectancy levels off.
5. Model for Kenya $R^2: 0.42$
Finally, let's look at an example where the Rsquared is much lower. From this plot you can see that a linear model does not adequately capture the relationship of life expectancy with year.
As you can see from these three examples, augment() and ggplot make it easy to visually explore the fit of a model.
6. Let's practice!
Now it's your turn to use these tools to visualize the fit of your best and worst fitting models.