How to Interpret Regression Model Diagnostics in R

How to Interpret Regression Model Diagnostics in R
Image by Editor | Canva
 

Constructing a regression model is only the initial stage of statistical analysis. It’s essential to assess whether the results are valid and reliable. A model may appear satisfactory at first but can hide issues such as nonlinearity, heteroscedasticity, outliers, or multicollinearity among predictors. In R, diagnostic plots and statistical tests provide systematic tools to detect such problems and apply corrective measures.

This article guides you through key regression diagnostics in R and explains how to interpret them.

Setting Up a Regression Model in R

Let’s start with a simple linear regression example using the built-in mtcars dataset:

 
# Fit a linear regression model
model <- lm(mpg ~ wt + hp, data = mtcars)

Using Diagnostic Plots in R

R provides four built-in plots that cover the most common issues in linear models. You can draw them all at once:

 
par(mfrow = c(2, 2))
plot(model)

You’ll get four standard diagnostic plots:

diagnostic_plots

Residuals vs Fitted

The Residuals vs Fitted plot helps assess whether the relationship between predictors and the response is adequately captured by the model. Residuals should appear as a random scatter around the horizontal line at zero. A visible curve suggests nonlinearity, while a funnel shape indicates heteroscedasticity.

Normal Q-Q Plot

The Normal Q-Q plot checks whether residuals follow a normal distribution. If the points align closely with the reference line, the assumption of normality is reasonable. Strong deviations at the tails suggest skewness, heavy-tailed errors, or the presence of outliers.

Scale-Location Plot

The Scale-Location plot examines whether residual variance is consistent across fitted values. Ideally, the points form a roughly horizontal band, suggesting homoscedasticity. A widening or narrowing pattern (funnel effect) signals heteroscedasticity.

Residuals vs Leverage

The Residuals vs Leverage plot identifies observations that exert strong influence on the regression model. Points with both large residuals and high leverage can disproportionately affect coefficients and model fit. Cook’s distance contours help highlight influential cases that may need closer inspection.

Statistical Tests for Assumptions

While diagnostic plots provide valuable visual insights, formal statistical tests can corroborate whether the model assumptions hold. These tests are not replacements for plots but serve as additional evidence to guide model evaluation. We’ll use functions from the lmtest package alongside base R.

Breusch-Pagan Test

The Breusch-Pagan test checks whether residual variance is constant across fitted values. A non-significant result (p > 0.05) supports homoscedasticity, while significance indicates heteroscedasticity.

 
library(lmtest)
bptest(model)
 
BP = 0.88072, df = 2, p-value = 0.6438

Shapiro-Wilk Test

The Shapiro-Wilk test assesses whether residuals are normally distributed. A non-significant result (p > 0.05) suggests normality is not violated, while a significant result indicates deviations from normality.

 
shapiro.test(residuals(model))
 
W = 0.92792, p-value = 0.03427

Durbin-Watson Test

The Durbin-Watson test detects autocorrelation in residuals, which is especially relevant for time series or otherwise ordered data. Values near 2 indicate independence; values closer to 0 or 4 suggest positive or negative autocorrelation.

 
library(lmtest)
dwtest(model)
 
DW = 1.3624, p-value = 0.02061

Checking Multicollinearity

When predictors are highly correlated with each other, the model suffers from multicollinearity. The Variance Inflation Factor quantifies how much the variance of a regression coefficient is increased due to multicollinearity. As a rule of thumb, VIF values above about 5 (some use 10) can indicate problematic correlation among predictors.

 
library(car)
vif(model)
 
      wt       hp 
1.766625 1.766625

Addressing Violations

When diagnostics reveal issues, you can fix them with targeted changes.

  • Fix heteroscedasticity by applying transformations, using weighted least squares, or adding robust standard errors.
  • Handle non-normality by transforming variables, removing outliers, or applying resampling methods like bootstrapping.
  • Reduce multicollinearity by removing variables, combining them, or applying regularization techniques.
  • Address outliers and influential points by correcting errors, applying robust methods, or selectively removing cases.

Conclusion

Checking regression diagnostics in R is a critical step to ensure your model results are trustworthy. Plots such as Residuals vs Fitted, Normal Q-Q, Scale-Location, and Residuals vs Leverage help identify issues like nonlinearity, heteroscedasticity, outliers, and influential points. Tests like the Breusch-Pagan, Shapiro-Wilk, Durbin-Watson, and VIF provide additional confirmation of assumption checks. By combining these tools and applying the right fixes, you can improve your model and draw more reliable conclusions.

Posted in R

Leave a Reply

Your email address will not be published. Required fields are marked *