Lesson 7
Fitted Values and Residuals
Big question
How do fitted values and residuals work with several x variables?
Lesson progress
Complete checkpoints as you learn
Learning objectives
- Explain fitted values and residuals in plain language.
- Use ceteris paribus correctly in an interpretation.
- Connect the lesson idea to a formula, graph, Python result, or real example.
Simple explanation
A fitted value uses every estimated coefficient and every explanatory variable in the row. The residual is actual y minus fitted y.
Key terms
- ceteris paribus
- Other included factors held fixed for interpretation.
- omitted-variable bias
- Bias that can arise when a relevant omitted factor is related to an included regressor.
- multicollinearity
- Strong but not perfect relationships among explanatory variables.
Core formula
Use plain-language interpretation before algebra.
Example
A positive residual means the model underpredicted the observation. A negative residual means it overpredicted.
Interactive visual
Residual calculator and observation table
Original Module 3 visual for Fitted Values and Residuals.
y variable
wage
The dependent variable. It is the outcome students want to explain.
x variable
education
The explanatory variable. It is used to describe changes in wage.
Live Python
Fitted Values and Residuals Python example
Fitted Values and Residuals Python example
Stdout
Run Python to see results here.
Status / stderr
Ready to run Python in your browser.
Line-by-line guide
- Line 1Load a Python library needed for data work or regression.
- Line 2Load a Python library needed for data work or regression.
- Line 3Load a Python library needed for data work or regression.
- Line 5Load the dataset into a pandas DataFrame.
- Line 6Create a log version of the variable so coefficients can be read approximately as percentages.
- Line 7Add an intercept column to the regression design matrix.
- Line 8Create or update a Python object used in the analysis.
- Line 9Estimate an ordinary least squares regression.
- Line 10Display a result so students can inspect the output.
Python walkthrough
- 1Load the dataset and keep only variables needed for the current model.
- 2Construct the dependent variable and explanatory-variable matrix.
- 3Add a constant so the regression includes an intercept.
- 4Fit OLS and interpret coefficients with the controls held fixed.
Live notebook
Run this lesson as a notebook
Open an editable notebook cell-by-cell, run Python in the browser, and download the `.ipynb` file for later.
Related dataset
WAGE1
Estimated time
25 to 40 min
Packages
pandas, numpy, matplotlib
Expected output
Printed Python results that can be compared with the lesson explanation.
Learning goals
- Load and inspect WAGE1.
- Run the Python cells connected to Fitted Values and Residuals.
- Interpret the output using fitted values and residuals.
Common errors
- File not found: check that WAGE1.DTA is installed or use the course data folder.
- Package import error: use the browser notebook first, then download for local Jupyter if your local packages differ.
- Column name error: compare your variable names with the dataset variables listed for this notebook.
Dataset path helper
import pandas as pd
df = pd.read_stata("/data/WAGE1.DTA")
df.head()Interactive activity
PartiallingOutVisualizer
Inspect fitted values and residuals
Read actual, fitted, and residual values for several observations.
Controlled prediction
Interpretation sentence
Holding experience and tenure fixed, one more year of education changes predicted log wage by about 0.075 in this teaching setup.
Residual sketch
Variable role check
In a wage model with education as the focal x, classify experience.
Precision check
Larger samples tighten estimates. Under the Gauss-Markov assumptions, OLS has the smallest variance among linear unbiased estimators.
Control overlap
VIF: 2.22
SE index: 0.136
Try it yourself
Write one plain-English sentence explaining the main idea from this lesson.
Common mistakes
Check these before you move on.
A regression coefficient describes a pattern unless the assumptions or research design support a causal interpretation.
Quick quiz
What is the safest interpretation focus in Fitted Values and Residuals?
Quick quiz
Which interpretation habit is most important in Fitted Values and Residuals?
Quick quiz
Why is HPRICE1 a reasonable practice dataset here?
Key takeaway
Fitted Values and Residuals helps turn multiple regression output into a careful ceteris paribus interpretation.