Skip to main content

Introductory Statistics

Section 9.3 Checking model conditions using graphs

Multiple regression methods using the model
\begin{equation*} \hat{y} = \beta_0 + \beta_1x_1 + \beta_2x_2 + \cdots + \beta_kx_k \end{equation*}
generally depend on the following four conditions:
  1. the residuals of the model are nearly normal (less important for larger data sets),
  2. the variability of the residuals is nearly constant,
  3. the residuals are independent, and
  4. each variable is linearly related to the outcome.

Subsection 9.3.1 Diagnostic plots

Diagnostic plots can be used to check each of these conditions. We will consider the model from the Lending Club loans data, and check whether there are any notable concerns:
\begin{align*} \widehat{\text{rate}} \amp = 1.921 + 0.974 \times \mathbb{1}_{\text{income\_ver = source\_only}} + 2.535 \times \mathbb{1}_{\text{income\_ver = verified}}\\ \amp \qquad + 0.021 \times \text{debt\_to\_income} + 4.896 \times \text{credit\_util} + 0.387 \times \text{bankruptcy}\\ \amp \qquad + 0.154 \times \text{term} + 0.228 \times \text{credit\_checks} \end{align*}
Check for outliers
In theory, the distribution of the residuals should be nearly normal; in practice, normality can be relaxed for most applications. Instead, we examine a histogram of the residuals to check if there are any outliers: Figureย 9.3.1 is a histogram of the residuals. Since this is a very large data set, only particularly extreme observations would be a concern in this particular case. There are no extreme observations that might cause a concern.
If we intended to construct what are called prediction intervals for future observations, we would be more strict and require the residuals to be nearly normal. Prediction intervals are further discussed in an online extra on the OpenIntro website: www.openintro.org/d?id=stat_extra_linear_regression_supp
A histogram is shown for residuals, where values range from about -10 to 20. The data is right skewed and centered near 0. The bin -10 to -5 represents about 2% of the values. The bin -5 to 0 represents about 40% of the values. The bin 0 to 5 represents about 45% of the values. The bin 5 to 10 represents about 10% of the values. The remaining bins above 10 have less than 3% of the data.
Figure 9.3.1. A histogram of the residuals.
Absolute values of residuals against fitted values
A plot of the absolute value of the residuals against their corresponding fitted values (\(\hat{y}_i\)) is shown in Figureย 9.3.2. This plot is helpful to check the condition that the variance of the residuals is approximately constant, and a smoothed line has been added to represent the approximate trend in this plot. There is more evident variability for fitted values that are larger, which weโ€™ll discuss further.
A scatterplot showing absolute residuals on the vertical axis against fitted values on the horizontal axis, with a smoothed trend line overlaid showing slightly increasing variability at higher fitted values.
Figure 9.3.2. Comparing the absolute value of the residuals against the fitted values (\(\hat{y}_i\)) is helpful in identifying deviations from the constant variance assumption.
Residuals in order of their data collection
This type of plot can be helpful when observations were collected in a sequence. Such a plot is helpful in identifying any connection between cases that are close to one another. The loans in this data set were issued over a 3 month period, and the month the loan was issued was not found to be important, suggesting this is not a concern for this data set. In cases where a data set does show some pattern for this check, time series methods may be useful.
Residuals against each predictor variable
We consider a plot of the residuals against each of the predictors in Figureย 9.3.3. For those instances where there are only 2-3 groups, box plots are shown. For the numerical outcomes, a smoothed line has been fit to the data to make it easier to review. Ultimately, we are looking for any notable change in variability between groups or pattern in the data.
Here are the things of importance from these plots:
  • There is some minor differences in variability between the verified income groups.
  • There is a very clear pattern for the debt-to-income variable. What also stands out is that this variable is very strongly right skewed: there are few observations with very high debt-to-income ratios.
  • The downward curve on the right side of the credit utilization and credit check plots suggests some minor misfitting for those larger values.
First set of diagnostic plots showing residuals against income verification, debt-to-income, and credit utilization.
Second set of diagnostic plots showing residuals against bankruptcy status and term.
Third set of diagnostic plots showing residuals against credit checks.
Figure 9.3.3. Diagnostic plots for residuals against each of the predictors. For the box plots, weโ€™re looking for notable differences in variability. For numerical predictors, we also check for trends or other structure in the data.
Having reviewed the diagnostic plots, there are two options. The first option is to, if weโ€™re not concerned about the issues observed, use this as the final model; if going this route, it is important to still note any abnormalities observed in the diagnostics. The second option is to try to improve the model, which is what weโ€™ll try to do with this particular model fit.

Subsection 9.3.2 Options for improving the model fit

There are several options for improvement of a model, including transforming variables, seeking out additional variables to fill model gaps, or using more advanced methods that would account for challenges around inconsistent variability or nonlinear relationships between predictors and the outcome.
The main concern for the initial model is that there is a notable nonlinear relationship between the debt-to-income variable observed in Figureย 9.3.3. To resolve this issue, weโ€™re going to consider a couple strategies for adjusting the relationship between the predictor variable and the outcome.
Letโ€™s start by taking a look at a histogram of debt_to_income in Figureย 9.3.4. The variable is extremely skewed, and upper values will have a lot of leverage on the fit. Below are several options:
If we inspected the data more closely, weโ€™d observe some instances where the variable takes a value of 0, and since \(\log(0)\) and \(1 / x\) are undefined when \(x = 0\text{,}\) weโ€™ll exclude these transformations from further consideration.
โ€‰1โ€‰
There are ways to make them work, but weโ€™ll leave those options to a later course.
A square root transformation is valid for all values the variable takes, and truncating some of the larger observations is also a valid approach. Weโ€™ll consider both of these approaches.
A histogram showing debt-to-income ratio with extreme right skew, where most values are below 50 but a few extend to over 150.
Figure 9.3.4. Histogram of debt_to_income, where extreme skew is evident.
To try transforming the variable, we make two new variables representing the transformed versions:
Square root
We create a new variable, sqrt_debt_to_income, where all the values are simply the square roots of the values in debt_to_income, and then refit the model as before. The result is shown in the left panel of Figureย 9.3.5. The square root pulled in the higher values a bit, but the fit still doesnโ€™t look great since the smoothed line is still wavy.
Truncate at 50
We create a new variable, debt_to_income_50, where any values in debt_to_income that are greater than 50 are shrunk to exactly 50. Refitting the model once more, the diagnostic plot for this new variable is shown in the right panel of Figureย 9.3.5. Here the fit looks much more reasonable, so this appears to be a reasonable approach.
The downside of using transformations is that it reduces the ease of interpreting the results. Fortunately, since the truncation transformation only affects a relatively small number of cases, the interpretation isnโ€™t dramatically impacted.
Two residual plots are shown, each with a flexible trend line overlaid. The first residual plot is against the variable "Square root of Debt to Income", which shows relative stability of the trend line with some deviation downwards on the right where there are almost no values and so is less relevant. The second residual plot is against the variable "Debt to Income, truncated at 50", which shows general stability in the trend line throughout the plot.
Figure 9.3.5. Residual plots for transformed versions of the debt-to-income variable.
As a next step to evaluate the new model using the truncated version of debt_to_income, we would complete all the same procedures as before. The other two issues noted while inspecting diagnostics in Subsectionย 9.3.1 are still present in the updated model. If we choose to report this model, we would want to also discuss these shortcomings to be transparent in our work. Depending on what the model will be used for, we could either try to bring those under control, or we could stop since those issues arenโ€™t severe. Had the non-constant variance been a little more dramatic, it would be a higher priority. Ultimately we decided that the model was reasonable, and we report its final form here:
\begin{align*} \widehat{\text{rate}} \amp = 1.562 + 1.002 \times \mathbb{1}_{\text{income\_ver = source\_only}} + 2.436 \times \mathbb{1}_{\text{income\_ver = verified}}\\ \amp \qquad + 0.048 \times \text{debt\_to\_income\_50} + 4.694 \times \text{credit\_util} + 0.394 \times \text{bankruptcy}\\ \amp \qquad + 0.153 \times \text{term} + 0.223 \times \text{credit\_checks} \end{align*}
A sharp eye would notice that the coefficient for debt_to_income_50 is more than twice as large as what the coefficient had been for the debt_to_income variable in the earlier model. This suggests those larger values not only were points with high leverage, but they were influential points that were dramatically impacting the coefficient.

โ€œAll models are wrong, but some are usefulโ€ โ€” George E.P. Box.

The truth is that no model is perfect. However, even imperfect models can be useful. Reporting a flawed model can be reasonable so long as we are clear and report the modelโ€™s shortcomings.
Donโ€™t report results when conditions are grossly violated. While there is a little leeway in model conditions, donโ€™t go too far. If model conditions are very clearly violated, consider a new model, even if it means learning more statistical methods or hiring someone who can help. To help you get started, OpenIntro developed a couple additional sections that you may find on their website. These sections provide a light introduction to what are called interaction terms and to fitting nonlinear curves to data, respectively:

Exercises 9.3.3 Exercises

1. Baby weights, Part VI.

Exerciseย 9.1.4.3 presents a regression model for predicting the average birth weight of babies based on length of gestation, parity, height, weight, and smoking status of the mother. Determine if the model assumptions are met using the plots below. If not, describe how to proceed with the analysis.
A histogram of residuals is shown, which has a bell-shaped distribution, is centered at 0, and has a standard deviation of about 12.
A scatterplot of "residuals" (vertical axis) against "fitted values". The residuals do not show any pattern for different fitted values.
A scatterplot of "residuals" (vertical axis) against "order of collection". The residuals do not show any pattern across the order of collection variable.
A scatterplot of "residuals" (vertical axis) against "length of gestation". The residuals do not show any pattern for different lengths of gestation.
A scatterplot of "residuals" (vertical axis) against "parity", which only takes values 0 and 1. The residuals do not show any apparent patterns across the values 0 and 1 of parity.
A scatterplot of "residuals" (vertical axis) against "height of mother". The residuals do not show any pattern for different values of "height of mother".
A scatterplot of "residuals" (vertical axis) against "weight of mother". The residuals do not show any pattern for different values of "weight of mother".
A scatterplot of "residuals" (vertical axis) against "smoke", which only takes values 0 and 1. The residuals do not show any pattern for the 0 and 1 values of smoke.

2. Movie returns, Part I.

A FiveThirtyEight.com article reports that โ€œHorror movies get nowhere near as much draw at the box office as the big-time summer blockbusters or action/adventure movies ... but thereโ€™s a huge incentive for studios to continue pushing them out. The return-on-investment potential for horror movies is absurd.โ€ To investigate how the return-on-investment compares between genres and how this relationship has changed over time, an introductory statistics student fit a model predicting the ratio of gross revenue of movies from genre and release year for 1,070 movies released between 2000 and 2018. Using the plots given below, determine if this regression model is appropriate for these data.
A histogram is shown for "Residuals", which take values from about -15 to 100. The shape of the distribution is extremely right-skewed but centered at 0. The bin -15 to -10 represents about 1% of the values. The bin -10 to -5 represents about 1% of the values. The bin -5 to 0 represents about 65% of the values. The bin 0 to 5 represents about 25% of the values. The bin 5 to 10 represents about 2% of the values. The bin 10 to 15 represents about 1% of the values. The remaining bins above 15 have far less than 1% of the data.
A scatterplot is shown. The horizontal axis is for "Fitted Values", which takes values between 2.5 and 12. The vertical axis is for "Residuals" and takes values from -15 to about 90, though only about a dozen values have residuals larger than 25. The points are also colored for different genres: Action, Adventure, Comedy, Drama, and Horror. The points for Action, Adventure, Comedy, and Drama are clustered on the left with Fitted Values between 2.5 and 3.5, and the residuals for these points are largely between -5 and 12. The Horror points have Fitted Values between about 11 and 12, with residuals for these points largely between -10 and 25.
A dot plot is shown for "residuals", where points are broken up into different genres: Action, Adventure, Comedy, Drama, and Horror. The residuals for Action, Adventure, Comedy, and Drama groups have residuals for these points largely between -5 and 12. The Horror genre residuals are largely between -10 and 25.
A scatterplot is shown for "residuals" (vertical axis) against "order of collection" (horizontal axis) from 1 to about 1100. The variability of residuals for the order of collection values from 0 to 600 largely range between -3 and positive 5. The variability of residuals for the order of collection values from 600 to 800 largely range between -5 and positive 10. The variability of residuals for the order of collection values above 800 largely range between -8 and positive 15.
A scatterplot is shown for "residuals" (vertical axis) against "release year" (horizontal axis) from 2010 to 2018. For each year in the range, the residuals largely range between roughly -10 and positive 12.