9 Residual Plots for Assessing Your Regression Models

btd
2 min readNov 16, 2023

Creating residual plots is an essential step in the analysis of regression models. These plots help you assess the assumptions of the model and identify potential issues such as heteroscedasticity, non-linearity, or outliers. Below are several types of residual plots commonly used in regression analysis, along with example code in Python using the matplotlib and seaborn libraries. The examples assume you have a fitted regression model.

1. Residuals vs. Fitted Values Plot:

This plot helps you check for linearity and homoscedasticity.

import matplotlib.pyplot as plt
import seaborn as sns

# Assuming 'model' is your fitted regression model
residuals = model.resid
fitted_values = model.fittedvalues

# Plotting
sns.scatterplot(x=fitted_values, y=residuals)
plt.axhline(y=0, color='r', linestyle='--')
plt.title("Residuals vs. Fitted Values")
plt.xlabel("Fitted Values")
plt.ylabel("Residuals")
plt.show()

2. Normal Q-Q Plot:

This plot assesses the normality of residuals.

import statsmodels.api as sm
import matplotlib.pyplot as plt

# Assuming 'model' is your fitted regression model
residuals = model.resid

# Plotting
sm.qqplot(residuals, line='s')
plt.title("Normal Q-Q Plot")
plt.show()

--

--

btd
btd

No responses yet