Tutorials › Regression Analysis (Undergraduate) › A Worked Stepwise Analysis

Subset and Stepwise Selection · Tutorial 664 of 991

A Worked Stepwise Analysis

Work through three stepwise procedures on one dataset, check every model change, and assess how sensitive the final models are to the selection thresholds.

Advanced 12 min read

What You'll Learn

  • Apply forward selection using partial F tests and an entry threshold.
  • Apply backward elimination by checking deletion p-values from the full model.
  • Trace bidirectional selection, including its rechecks after each change.
  • Verify which predictors enter or leave by calculating the relevant partial F statistics.
  • Compare selected models when the entry and removal thresholds change.
  • Explain why a stepwise-selected model and its ordinary p-values require cautious interpretation.

Why Work Through a Stepwise Path?

Stepwise selection is a search procedure: it builds or reduces a regression model through a sequence of comparisons between nested models. The final model depends not only on the data, but also on the search direction, the rule for adding or deleting predictors, and the thresholds used. Tracing the calculations makes those choices visible. It also helps prevent a consequential mistake: confusing a p-value that is small enough to retain a predictor with one that is large enough to remove it.

The example below uses the same hypothetical data for forward selection, backward elimination, and bidirectional selection. The aim is not to claim that any one selected model is objectively correct. It is to show exactly how each procedure follows its stated rule, and how modest threshold changes can produce a different answer.

Model, Tests, and Selection Rules

Suppose data were recorded for \(n=30\) hypothetical service centers. The response \(Y\) is each center’s mean follow-up delay, measured in days. Four candidate quantitative predictors are \(A\) (staffing hours), \(B\) (referral volume), \(C\) (a measure of urban location), and \(D\) (outreach spending). Each candidate model includes an intercept. These variables are used only to illustrate the calculations; the example does not describe a real study.

For a full-rank model with \(k\) predictors, the residual degrees of freedom are \(n-k-1\). Its residual sum of squares, abbreviated RSS, is the sum of squared residuals and therefore has units of days squared here. To test whether adding one predictor improves a reduced model, compare that model with the larger, nested model using a partial F test. The hypotheses are that the additional predictor’s coefficient is zero, conditional on the predictors already in the model, versus that it is not zero.

Definition: In forward selection, start with the intercept-only model and add the eligible predictor with the smallest partial-test p-value if that p-value is at or below the entry threshold. In backward elimination, start with the full candidate model and remove the predictor with the largest deletion p-value if it is above the removal threshold. Bidirectional selection allows additions and deletions as the model changes. In each procedure, the rule must specify the threshold and how ties are handled.

We use an entry threshold of 0.10 and a removal threshold of 0.10. Thus, a candidate may enter when its p-value is at most 0.10, and a predictor is removed only when its deletion p-value is greater than 0.10. These are illustrative decision rules, not universal recommendations. For the usual exact partial F tests, assume a correctly specified linear mean model for the comparisons, independent errors with mean zero and constant variance, and normally distributed errors. The same observations must be used in every compared model. These assumptions provide the standard reference distribution for the tests; the selection arithmetic itself does not establish that the assumptions hold.

A Small Set of Regression Summaries

The following hypothetical fits provide the RSS values needed to trace the paths. The null model contains only an intercept. The other rows give selected candidate models; all fit summaries use the same 30 centers. Since adding predictors cannot increase RSS, the listed values decrease along each nested path.

ModelPredictorsRSSResidual degrees of freedom
NullNone80.029
AA38.028
BB45.028
CC50.028
DD70.028
ABA, B29.027
ACA, C34.027
ABCA, B, C25.026
ABCDA, B, C, D23.525

Additional fits used to check deletion decisions have RSS \(37.0\) for \(BC\), \(27.0\) for \(ABD\), \(31.0\) for \(ACD\), and \(35.0\) for \(BCD\). Each is a hypothetical regression summary, not an estimate from an actual service-center study. Assuming each compared model is full rank and each added predictor increases the design-matrix rank by one, these comparisons have numerator degrees of freedom 1.

Why the Partial F Calculation Works

For a reduced model with RSS \(RSS_R\) and a larger model with RSS \(RSS_F\), adding \(q\) predictors reduces RSS by \(RSS_R-RSS_F\). The partial F statistic divides the reduction per added predictor by the larger model’s residual mean square. For a single predictor, \(q=1\).

$$ F=\frac{(RSS_R-RSS_F)/q}{RSS_F/df_F} $$

Here \(df_F\) is the residual degrees of freedom in the larger model. For a prespecified comparison, under the null hypothesis and the linear-model assumptions stated above, and provided the larger model has the required rank, this statistic has an \(F\) distribution with \(q\) and \(df_F\) degrees of freedom. In a stepwise path, comparisons are selected adaptively, so their p-values are nominal per-comparison values and do not by themselves provide selection-adjusted inference or overall error control. For one added predictor, a large value indicates a reduction in RSS that is large relative to the residual mean square. The p-value is the upper-tail probability from that reference distribution.

For example, the test for adding \(B\) to model \(A\) compares RSS 38.0 with RSS 29.0. Substitution gives:

$$ F=\frac{38.0-29.0}{29.0/27} =\frac{9.0}{1.0741} =8.379 $$

The reference distribution is \(F_{1,27}\), giving \(p\approx0.007426\). This is a test of \(B\) conditional on \(A\), not a test of \(B\) in isolation.

Worked Example: Forward Selection

Worked Example: Forward Selection

Start with the intercept-only model. At each step, compare the current model with each available one-predictor addition, choose the addition with the smallest p-value, and enter it only if its p-value is at most 0.10.

Step 1: Choose the first predictor. The initial comparisons are against the null model. For adding \(A\), for example, \(F=(80.0-38.0)/(38.0/28)=30.95\). The corresponding statistics for \(B\), \(C\), and \(D\) are \(21.78\), \(16.80\), and \(4.000\), respectively. The largest statistic, and thus the smallest p-value, is for \(A\). Its p-value is below 0.10, so enter \(A\).

Step 2: Test additions to \(A\). Adding \(B\) gives \(F=(38.0-29.0)/(29.0/27)=8.379\), with \(p\approx0.007426\). Adding \(C\) gives \(F=(38.0-34.0)/(34.0/27)=3.176\), with \(p\approx0.086\). The available comparison for adding \(D\) has RSS 37.0 for \(AD\), giving \(F=(38.0-37.0)/(37.0/27)=0.730\), with \(p\) above 0.10. The smallest p-value is for \(B\), so enter \(B\); the current model is \(AB\).

Step 3: Test additions to \(AB\). Adding \(C\) gives

$$ F=\frac{29.0-25.0}{25.0/26} =\frac{4.0}{0.9615} =4.160 $$

The p-value is approximately 0.0517. Adding \(D\) gives \(F=(29.0-27.0)/(27.0/26)=1.926\), with \(p\approx0.177\). Therefore, \(C\) has the smaller p-value and qualifies for entry because \(0.0517\leq0.10\). The current model becomes \(ABC\).

Step 4: Check remaining additions. Adding \(D\) to \(ABC\) gives \(F=(25.0-23.5)/(23.5/25)=1.596\), with \(p\approx0.2182\). This is above 0.10, so \(D\) does not enter. Forward selection stops at \(ABC\).

Worked Example: Backward Elimination

Worked Example: Backward Elimination

Start with the full model \(ABCD\). At each step, identify the predictor with the largest deletion p-value. Remove it only if that p-value is greater than 0.10.

Step 1: Test deletions from \(ABCD\). Deleting \(D\) changes RSS from 23.5 to 25.0, so its statistic is \(F=(25.0-23.5)/(23.5/25)=1.596\), with \(p\approx0.2182\). This exceeds 0.10, so remove \(D\). The new model is \(ABC\). The other deletion p-values in \(ABCD\) are below 0.10, so \(D\) is the predictor removed at this step.

Step 2: Test deletions from \(ABC\). Deleting \(C\) gives

$$ F=\frac{29.0-25.0}{25.0/26}=4.160, \qquad p\approx0.0517. $$

Since \(0.0517\) does not exceed 0.10, retain \(C\). The deletion p-values for \(A\) and \(B\) are also below 0.10: their reduced-model RSS values are 37.0 for \(BC\) and 34.0 for \(AC\), giving \(F=(37.0-25.0)/(25.0/26)=12.48\) for deleting \(A\) and \(F=(34.0-25.0)/(25.0/26)=9.360\) for deleting \(B\). Backward elimination stops at \(ABC\).

The key decision is the comparison of 0.0517 with the removal threshold. Although the p-value may look borderline, the stated rule removes a predictor only when its deletion p-value is greater than 0.10. The rule therefore retains \(C\).

Worked Example: Bidirectional Selection

Worked Example: Bidirectional Selection

Bidirectional selection allows an addition when an eligible predictor meets the entry rule and checks whether current predictors should be removed using the removal rule. Begin with the null model and use the same 0.10 thresholds.

The first addition is \(A\), followed by \(B\), as in forward selection. After \(B\) enters, the model is \(AB\). Its deletion tests give \(p\approx0.0006409\) for removing \(A\) and \(p\approx0.007426\) for removing \(B\). Both are below 0.10, so neither predictor is removed.

The next eligible addition is \(C\), with \(p\approx0.0517\). Once it enters, the model is \(ABC\). The deletion p-value for \(C\) is approximately 0.0517, and those for \(A\) and \(B\) are also below 0.10, so no term is deleted. The remaining candidate \(D\) has \(p\approx0.2182\) when added to \(ABC\), so it does not enter. Bidirectional selection also stops at \(ABC\).

With these summaries and rules, all three procedures finish at \(ABC\). Their paths differ in where they start and which comparisons they make, but their final model happens to agree.

Threshold Sensitivity and Interpretation

The agreement at a 0.10 threshold does not mean the selected model is insensitive to the rule. The addition of \(C\) to \(AB\) has \(p\approx0.0517\). If the entry threshold were tightened to 0.05, forward selection would stop at \(AB\), because \(0.0517\) is above 0.05. Bidirectional selection using 0.05 for entry would likewise not add \(C\). In backward elimination with a 0.05 removal threshold, \(C\) would be removed from \(ABC\), because its deletion p-value, 0.0517, exceeds 0.05. In each case, the resulting model would be \(AB\).

This comparison shows why a threshold is part of the procedure rather than a property discovered from the data. A p-value just above or below a cutoff does not create a sharp scientific distinction. The cutoff determines a mechanical decision; it does not prove that a predictor has no relationship with the response when excluded, or that a retained predictor is important in every practical sense.

The regression coefficients in a selected model describe fitted associations conditional on the other included predictors, in their stated units. For example, a coefficient for staffing hours would express the fitted change in mean follow-up delay, in days, associated with a one-hour difference in staffing hours while holding the other included predictors fixed. It would not by itself establish a causal effect. Moreover, because these predictors were chosen by repeatedly searching the same data, ordinary coefficient p-values and confidence intervals do not automatically account for that search. Selection results should be reported as results of a specified procedure, with the thresholds and search path made clear.

Common Mistakes

  • Reversing the deletion rule. Wrong: “The deletion p-value is 0.0517, so remove \(C\) at a 0.10 removal threshold.” Correction: removal requires a p-value greater than 0.10, and 0.0517 is smaller, so retain \(C\).
  • Using a marginal test for a conditional decision. The decision to add \(C\) to \(AB\) uses the partial test comparing \(AB\) with \(ABC\), not the test of \(C\) alone against the null model.
  • Stopping after an addition without rechecking. In bidirectional selection, addition and deletion checks are made as specified by the procedure; a change to the model can change the conditional tests.
  • Treating the chosen model as certain. The selected set can change with the thresholds or procedure. Report the rule and the observed path rather than implying that selection has identified a uniquely true model.
  • Reading association as causation. A selected regression coefficient is an adjusted association under the model, not proof that changing the predictor would cause the response to change.
Key takeaway: A stepwise result is reproducible only when the starting model, candidate predictors, test, entry and removal rules, and thresholds are explicit. In this example, all three methods select \(ABC\) at thresholds of 0.10, but each yields \(AB\) under the stated 0.05 sensitivity check.

Check Your Understanding

Use the stated dataset summaries and selection rules to answer these questions.

  1. When adding \(B\) to model \(A\), what are the reduced and larger model RSS values, and why is the test conditional on \(A\)?
  2. At a 0.10 entry threshold, why does \(C\) enter after \(A\) and \(B\) have been selected?
  3. In backward elimination, what is the deletion p-value for \(C\) in \(ABC\), and what does the 0.10 rule require?
  4. Which predictor is removed first from \(ABCD\), and what feature of its deletion p-value determines that decision?
  5. What final model does forward selection produce if its entry threshold is changed to 0.05?
  6. Why should an ordinary p-value for a coefficient in a selected model be interpreted cautiously?