Stepwise Regression — Definition, Formula & Example
Stepwise regression (also called stepwise selection) is a way to build a multiple regression model by adding or removing predictor variables one at a time. At each step it keeps the change that best improves a chosen score.
Stepwise regression is an automated variable-selection procedure for multiple regression. It starts from an initial model, which is empty for forward selection and contains every candidate predictor for backward elimination. At each step it adds or deletes the single predictor that most improves a criterion, such as a partial F-test p-value, AIC, BIC, or adjusted . Bidirectional stepwise selection allows both moves at every step. The procedure stops when no single addition or deletion improves the criterion.
Key Formula
Where:
- = Adjusted coefficient of determination, one common stopping criterion
- = Proportion of variation in the response explained by the model
- = Number of observations
- = Number of predictors in the model
How It Works
First pick a criterion and a starting model. In forward selection, you fit every one-predictor model and keep the best one. Then you try adding each remaining predictor and keep the best addition. Backward elimination runs the other way and drops the weakest predictor at each step. Bidirectional stepwise selection also rechecks earlier choices, so a variable added early can be removed later. The search is greedy: it never tests every possible subset, so it can miss the best overall model.
Worked Example
Problem: A realtor has data on n = 21 homes and wants to predict sale price in dollars. The candidate predictors are square footage, distance to downtown (miles), and number of bedrooms. The one-predictor models have R² values of 0.60 (square footage), 0.30 (distance), and 0.40 (bedrooms). Square footage plus distance gives R² = 0.72. Square footage plus bedrooms gives R² = 0.62. All three predictors together give R² = 0.73. Use forward selection with adjusted R² as the criterion.
Step 1: Square footage has the highest R² of the one-predictor models, so it enters first. Compute its adjusted R² with k = 1.
Step 2: Adding distance (0.72) beats adding bedrooms (0.62), so test distance with k = 2. Adjusted R² rises from 0.579 to 0.689, so distance stays in the model.
Step 3: Try adding bedrooms with k = 3. Plain R² rises slightly to 0.73, but adjusted R² falls from 0.689 to 0.682. The extra predictor does not earn its place, so the procedure stops.
Answer: Forward selection keeps square footage and distance to downtown, with adjusted R² ≈ 0.689. Bedrooms is left out because it lowers adjusted R² to about 0.682.
Why It Matters
Stepwise selection is built into common statistical software. One example is R's step() function, which uses AIC by default. You will meet it in applied regression and econometrics courses. Knowing its flaws helps you see why many analysts now prefer cross-validation or penalized methods such as LASSO.
Common Mistakes
Mistake: Reporting the final model's p-values and confidence intervals as if the predictors had been chosen in advance.
Correction: The same data both picked the variables and tested them, so those p-values come out too small and the intervals too narrow. Treat a stepwise model as exploratory. Confirm it on new data or with cross-validation, and do not read the selected variables as causes.
