Before you start
You will be able to
- Explain how multicollinearity inflates standard errors and makes slopes unstable while leaving predictions and the overall fit almost unchanged.
- Calculate a variance inflation factor and the factor by which it widens a slope’s standard error.
- Compare nested models with the general F test, and compare any models fitted to the same rows with adjusted R², AIC and BIC.
- Distinguish choosing predictors to explain from choosing them to predict, and explain why selecting predictors by their p-values misleads.
- Evaluate a model on held-out data, and state what a time-based hold-out check can and can’t show.
Review first
- Multiple regression — Partial slopes, adjusted R² and the overall F test, which this lesson extends to comparing models.
- Categorical predictors and interactions — The café, weekend and weekday dummies and the interactions whose value the nested F test judges.
- Correlation matrices — The near-perfect correlation of footfall and transactions (0.98) seen in the matrix.
- Normalisation and standardisation — Training and test sets, and keeping the test data out of every fitting step.
Fictional case A fictional coffee business founded by Ana Lim. It starts as a catering and barista-training service, opens its own cafés and an online shop for beans, and plans a canned cold brew.
The idea
Fictional case
Ana wants to know what Harbourside’s sales depend on: the number of people who come in, or the number who buy. She regresses daily sales on footfall and transactions together over the café’s 306 days. The model fits very well, but the coefficients look odd: the slope on transactions is lower than when it is alone, its standard error is almost six times as large, and the slope on footfall is small. Refitted month by month, the slopes jump around and footfall’s even turns negative.
Two predictors that say the same thing
Footfall and transactions at Harbourside correlate at 0.985: almost every visitor’s day is mirrored in the till. The table compares three fits.
| Predictors | Slope on footfall ($ per person) | Slope on transactions ($ per transaction) | R² | s ($) |
|---|---|---|---|---|
| Transactions | — | 6.64 (SE 0.048) | 0.9844 | 28.1 |
| Footfall | 3.18 (SE 0.036) | — | 0.9633 | 43.1 |
| Both | 0.44 (SE 0.133) | 5.75 (SE 0.275) | 0.9850 | 27.6 |
Adding footfall to transactions raises R² from 0.9844 to 0.9850 and lowers s by less than half a dollar: the fitted values hardly change. But the slope on transactions falls from $6.64 to $5.75 and its standard error grows from 0.048 to 0.275. Footfall’s slope, $3.18 per person alone, is $0.44 per person holding transactions fixed, with a 95% interval from $0.18 to $0.70.
This is multicollinearity: predictors so closely related that the data contain little information about each one’s separate effect. Recall that a partial slope is estimated only from the part of its predictor that the others can’t predict. Footfall holding transactions fixed varies very little, so its slope rests on small differences and is poorly determined; the same goes for transactions holding footfall fixed. Many combinations of the two slopes fit almost equally well, and least squares picks one that small changes in the data can move.
Unstable from month to month
Refit the model with both predictors one month at a time and the instability shows.
| Month | r (footfall, transactions) | Slope on footfall (SE) | Slope on transactions (SE) | Transactions alone (SE) |
|---|---|---|---|---|
| March | 0.973 | 0.24 (0.21) | 4.74 (0.43) | 5.22 (0.10) |
| April | 0.964 | −0.19 (0.20) | 6.02 (0.39) | 5.67 (0.10) |
| May | 0.996 | 1.86 (0.57) | 3.38 (1.18) | 7.20 (0.13) |
| June | 0.979 | 0.32 (0.29) | 5.08 (0.65) | 5.78 (0.13) |
| July | 0.987 | 0.62 (0.27) | 5.47 (0.57) | 6.77 (0.10) |
| August | 0.984 | 0.60 (0.35) | 5.99 (0.68) | 7.15 (0.13) |
| September | 0.958 | 0.58 (0.26) | 4.76 (0.54) | 5.90 (0.16) |
| October | 0.961 | −0.16 (0.21) | 6.25 (0.46) | 5.90 (0.13) |
| November | 0.947 | 0.07 (0.25) | 5.81 (0.48) | 5.95 (0.15) |
| December | 0.918 | 0.53 (0.20) | 4.95 (0.41) | 5.95 (0.18) |
Each month has 30 or 31 days. May, July and August include festival days.
Footfall’s slope runs from −$0.19 per person in April to $1.86 in May; the transactions slope from $3.38 to $6.25. With transactions alone the standard errors are between 0.10 and 0.18; with footfall alongside, between 0.39 and 1.18. Yet every monthly model is highly significant overall (each Significance F is below 0.001). The data can say with confidence that sales go with the two together; they can’t say how to share the credit.
In depth
The variance inflation factor
Regress predictor on all the other predictors and call that regression’s R² . The variance inflation factor is . It is the factor by which collinearity multiplies the variance of compared with a predictor unrelated to the others, so the standard error is multiplied by . With two predictors : for Harbourside, and , and .
The standard error of a slope is . Comparing transactions alone with transactions and footfall, the residual standard error s barely changes (28.1 to 27.6), so the standard error grows by about √VIF: 0.275 ÷ 0.048 is about 5.7, which is exactly . A VIF of 34 means that the 306 days give as much information about transactions’ separate slope as about 9 days would if the two predictors were unrelated.
Penn State’s STAT 462 notes treat VIFs above 4 as worth investigating and above 10 as signs of serious multicollinearity; these are conventions, and other sources use 5 and 10. A pairwise correlation can miss collinearity among three or more predictors (one can be close to a combination of two others), which the VIF catches. Collinearity is also built into models with interactions: a dummy and its product with a numeric predictor are highly correlated, which inflates the main effect’s standard error; centring the numeric predictor reduces it without changing the fit.
What to do about it
- Ask which question you are answering. Footfall, transactions and sales are a chain: people come in, some buy, purchases make sales. For “what is a visitor worth?”, regress sales on footfall alone ($3.18 per person); for “what is a transaction worth?”, on transactions alone ($6.64). With both in, footfall’s slope asks something narrower: at a given number of transactions, does a busier café sell more? Its $0.44 per person is consistent with the generator’s planted rise in the average ticket on busy days (about $0.22 per visitor at Harbourside’s typical trade, once the generator’s ticket rise is put in the log’s scaled dollars), but the interval is wide.
- Don’t drop a predictor only because its slope isn’t significant. If it is a confounder, dropping it brings back omitted-variable bias. Collinearity makes slopes imprecise, not wrong; a wide interval is the honest answer.
- Combine or get better data. Two measures of the same thing can be combined into one (a ratio such as transactions per visitor, or an average). More rows, or rows where the predictors move apart, are the only real cure.
- For prediction, it hardly matters. The model with both predictors predicts Harbourside’s sales as well as either alone, as long as the two keep moving together as they did in the data.
Comparing nested models: the general F test
Two models are nested when one (the reduced model) is the other (the full model) with some terms removed. The nested F test asks whether the removed terms together improve the fit by more than chance: : all their coefficients are zero. With SSE from each fit, q terms removed and the full model’s residual degrees of freedom,
on q and df (the general linear F test of Penn State’s notes). The overall F test is the special case in which the reduced model has no predictors; with one term removed, F is that term’s t squared. The test matters most for groups of terms, such as a set of dummies, which no single t test can judge. All the comparisons below use the same 612 café-days.
| Model | Coefficients | R² | Adjusted R² | AIC | BIC |
|---|---|---|---|---|---|
| A: weather, café, weekend, café × weekend, festival | 7 | 0.9044 | 0.9034 | 5781.6 | 5812.5 |
| B: A + high × café | 8 | 0.9086 | 0.9075 | 5756.1 | 5791.4 |
| C: B + build-up | 9 | 0.9409 | 0.9401 | 5491.1 | 5530.9 |
| D: C with six weekday dummies and their café interactions instead of the weekend | 19 | 0.9416 | 0.9398 | 5504.0 | 5587.9 |
AIC and BIC are from the Gaussian log-likelihood, as statsmodels and the B06 engine report them. Lower is better. Only differences between models fitted to the same rows mean anything.
B against A adds one term: on 1 and 604 df, which is the interaction’s t squared (); p below 0.001. C against B adds the build-up: , p below 0.001. D against C replaces the weekend dummy and its interaction with six weekday dummies and six interactions, ten extra coefficients: on 10 and 593 df, p = 0.73. The ten extra terms add nothing beyond what the weekend dummy already says, which the generator planted (weekdays alike, weekends alike). The rows share their days, as before, so all these p-values are somewhat too small.
AIC and BIC
Information criteria compare models that need not be nested, as long as they are fitted to the same rows and the same y. For least squares, apart from a constant that is the same for every model on the same data,
The first term rewards fit and the second charges for each coefficient; the model with the lowest value is preferred. BIC’s charge, per coefficient (6.4 for 612 rows), is stronger than AIC’s 2 whenever n is 8 or more, so BIC favours smaller models (Taboga’s StatLect notes describe AIC as the mildest penalty and BIC as the strongest). In the table both pick model C. A difference of a few units is not decisive; a convention many analysts use treats differences under about 2 as negligible. Neither criterion says whether the best model is good, only which of the candidates is least bad by its rule.
Overfitting and the hold-out check
A model with enough terms can follow the noise in its own data, fitting the rows it was estimated from very well and new rows badly. That is overfitting, and R² on the fitting data can’t detect it. The direct check is a hold-out: fit the model on one part of the data (the training set) and measure its errors on another part it never saw (the test set), for example by the root mean squared error, over the m test rows.
Ana fits three models of Harbourside’s footfall on March to September (214 days) and tests them on October to December (92 days). A is the multiple-regression lesson’s third model (high, rain, weekend, festival); B adds the build-up; C keeps the high, rain, festival and the build-up and throws in everything else that could be tried: weekday dummies, squares of the high and rain, their interactions, and a cubic trend in days since opening, 17 predictors.
| Model | Coefficients | Training R² | Training s | AIC | BIC | Test RMSE |
|---|---|---|---|---|---|---|
| A | 5 | 0.9477 | 18.0 | 1848.8 | 1865.6 | 29.8 |
| B | 6 | 0.9553 | 16.7 | 1817.2 | 1837.4 | 16.5 |
| C | 18 | 0.9628 | 15.7 | 1801.7 | 1862.3 | 78.6 |
Test RMSE in people. AIC and BIC from the training fit.
Model C has the best training R² and the lowest AIC, yet its test RMSE is 78.6 people, nearly five times B’s 16.5. Its cubic trend in the day, fitted to the spring build-up and the summer, bends sharply down after September: on the test days it under-predicts by 66 people on average. Model A also under-predicts, by 24 people on average, for a different reason: without the build-up its temperature slope is too steep, so it puts the colder autumn days too low. B, which BIC prefers, has a test RMSE close to its training s (16.5 against 16.7), though the comparison flatters it a little (see the caution below).
Explaining or predicting
The two aims choose predictors differently. Peak barista hours are rostered in advance from the manager’s expectation of the day’s trade, so they are known before the day and help forecast footfall: adding them to model C raises adjusted R² from 0.9401 to 0.9420. But the roster carries the calendar and the weather with it, so the weekend’s coefficient falls from 68.8 to 58.1 and the festival’s from 330.7 to 290.6. Nobody would say the roster brings people in. For a forecast, the roster is a useful summary of what the manager knows; for explaining what the weekend or a festival is worth, holding the roster fixed takes away part of the answer.
For explanation, choose predictors from how the business works, before looking at p-values: confounders in, mediators and colliders out (B05’s rules), with a stated reason for each. For prediction, any predictor available at the time of the forecast is fair, but the model must be judged on data it hasn’t seen, and a coefficient in it shouldn’t be read as an effect.
Why choosing predictors by p-value misleads
Stepwise selection adds or removes predictors one at a time by their p-values (or AIC) until no change passes the rule. It is automatic and popular, and its results mislead. Ana tries 31 meaningless candidates: a dummy for each day of the month, added one at a time to Harbourside’s model B. Two pass the 5% test (the 27th and the 29th of the month), about the 1.6 that chance alone predicts (31 × 0.05). A stepwise procedure would keep them and report their p-values as if they had been the only ones tried.
Selection also picks proxies. Harbourside’s loyalty-app membership, a running total that grows through the year, is “highly significant” added to model A (t = 10.4), because it tracks the build-up. With the build-up in the model, its p-value is 0.55. Frank Harrell’s often-quoted list of stepwise’s problems (reproduced in a Stata FAQ) includes R² values biased high, p-values without their proper meaning, confidence intervals that are too narrow, slopes biased away from zero and severe problems with collinear predictors. The cure is the one above: decide the candidate predictors from the question, test a few planned comparisons, and check any model chosen from the data on data that played no part in choosing it.
Formulas
Variance inflation factor
- Factor by which collinearity multiplies the variance of the slope on x_j
- R² of the regression of x_j on all the other predictors
The standard error is multiplied by √VIF. With two predictors R_j² = r². VIF above 4 (investigate) or 10 (serious) are conventions, not tests.
Standard error of a slope in a multiple regression
- Standard error of the slope on x_junits of y per unit of x_j
- Residual standard error of the modelunits of y
- Sum of squared deviations of x_junits of x_j squared
- Variance inflation factor of x_j
With one predictor VIF = 1 and this is the simple-regression standard error.
Nested (general linear) F test
- Test statistic for H₀: every removed coefficient is 0
- Residual sums of squares of the reduced and full modelsunits of y squared
- Number of coefficients removed from the full model to get the reduced one
- Number of rows (the same for both fits)
- Number of coefficients in the full model, counting the intercept
Assumes. The reduced model is the full model with some terms removed; both fitted to the same rows; the full model’s conditions hold.
Excel: F.DIST.RT(F, q, n − p_F). With q = 1, F is the removed term’s t².
AIC and BIC for least squares
- Number of rows
- Residual sum of squaresunits of y squared
- Number of coefficients, counting the intercept
Assumes. Models fitted to the same rows and the same y; up to a constant n(ln 2π + 1), which software adds (statsmodels and the B06 engine do) and which cancels in differences.
Lower is better. Differences of about 2 or less are usually treated as negligible (a convention).
Root mean squared error on a test set
- Number of test rows
- Actual value and the prediction of a model fitted without the test rowsunits of y
Excel: SQRT(AVERAGE((actual − predicted)^2)) over the test rows.
Worked examples
Fictional figures
Brackenfold Removals (fictional) regresses the hours each house move takes on the number of crew and the cubic metres moved. Regressed on crew and the other predictors, cubic metres have R² = 0.84, because bigger moves get bigger crews. What is the VIF for cubic metres, and by what factor does collinearity widen its slope’s standard error? If the slope on cubic metres has a standard error of 0.05 hours per cubic metre, what would it be if cubic metres were unrelated to the other predictors (with the same s)?
- VIF: .
- Standard-error factor: .
- Without collinearity, holding s and the spread of cubic metres fixed: hours per cubic metre.
Answer. VIF = 6.25; the standard error is 2.5 times what it would be without collinearity (0.05 instead of 0.02 hours per cubic metre).
What it means. Above Penn State’s threshold of 4 for a closer look, but not alarming. The firm can still estimate the volume effect; its interval is 2.5 times as wide as it would be if crew size didn’t follow the job.
Fictional figures
Model C of footfall at both cafés has 9 coefficients and SSE = 274,275; model D replaces the weekend dummy and its café interaction with six weekday dummies and six interactions, 19 coefficients and SSE = 271,078, over the same 612 café-days. Test whether D’s extra terms are needed, and compare the models by BIC.
- Check the nesting: the weekend dummy is the Saturday dummy plus the Sunday dummy, and its interaction is the sum of their interactions, so every model C can fit, D can too. D has more coefficients.
- F: on 10 and 593 df.
- p-value:
=F.DIST.RT(0.70,10,593)≈ 0.73. There is no evidence that the weekdays, or the weekend days, differ among themselves once the weekend dummy is in. - BIC: for C against for D. The ten extra coefficients cost in penalty and reduce the fit term by only 7.2.
Answer. F = 0.70 on 10 and 593 df, p = 0.73: keep the weekend dummy and drop the weekday dummies. BIC agrees (C is lower by 57).
What it means. The test judges the ten terms together, which ten separate t tests can’t do: with ten tests at 5%, one would often pass by chance. The generator planted a weekend effect and no weekday differences, and the test agrees.
Fictional figures
Ana wants a model to forecast Harbourside’s daily footfall for the roster. She fits models A, B and C on March to September and tests them on October to December (the table in In depth). Which should she use, and what should she tell the manager about its accuracy?
- Rank by the training data: C has the highest R² (0.963) and the lowest AIC; BIC prefers B. The criteria disagree, so the training data alone don’t settle it.
- Rank by the test data: B’s RMSE is 16.5 people, A’s 29.8 and C’s 78.6. C’s cubic trend in the day extrapolates badly; A is biased because it lacks the build-up.
- Check B for bias: its average test error is −1.7 people, small beside its RMSE. Its test RMSE is close to its training s (16.7), so there is no sign of overfitting, though quieter autumn days make that comparison a little kind.
- State the limits: one autumn, 92 days, no festivals, the build-up over; the next spring, with festivals and a new season, could behave differently.
Answer. Use model B (high, rain, weekend, festival, build-up), refitted on all ten months. Expect typical errors of about 17 people a day in quiet months, and somewhat more in busy ones.
What it means. The test was used to choose among three models, so its RMSE is now slightly optimistic for the chosen one. Ana should keep checking the forecasts against each month’s actual footfall and refit as the year’s data come in.
Explore
Common mistakes
“The slope on footfall isn’t significant, so footfall doesn’t matter.”
With transactions in the model, footfall’s slope asks whether a busier café sells more at the same number of transactions: a narrow question that collinearity makes hard to answer. Alone, footfall has a slope of $3.18 per person with a tiny standard error. Non-significance under collinearity means “can’t separate”, not “no link”.
“High VIFs mean the model is useless.”
They mean the slopes involved are imprecise. The fitted values and predictions are fine for rows like the data’s, and the other slopes are unaffected. Whether that matters depends on whether you need the separate slopes.
“The model with the highest R² is the best.”
R² never falls when terms are added. Harbourside’s 17-predictor model had the best training R² and lowest AIC and forecast the autumn worst. Judge models by adjusted R², a nested F test, AIC or BIC, and above all by data they haven’t seen.
“Stepwise selection found the significant predictors for me.”
Tried enough times, meaningless predictors pass by chance (2 of 31 day-of-month dummies did), and proxies for something left out pass easily (loyalty members, standing in for the build-up). The p-values after selection don’t mean what they say. Choose candidates from the question and check the result on new data.
“I chose the model on the test set, so its test RMSE is an honest measure of accuracy.”
Once the test set has picked the winner it is part of the fitting process, and its RMSE is optimistic for that model. Keep a final check set untouched, or say that the reported error was used for the choice.
“A random split is the most rigorous hold-out.”
For data in time, a random split puts each test day next to training days that are almost the same, so it measures interpolation. A forecast extrapolates: test on later data than you fit on.
Guided practice
Work through these with hints when you need them. Every hint and every worked solution is there to be used.
Loading four questions…
On your own
No hints this time. Answer, check, and read the feedback; the solution appears once you have answered or if you ask for it. Your first answers count toward mastery.
Loading six questions…
In practice
Every analyst who builds a regression with more than a couple of predictors meets both problems in this lesson. Marketing-mix models put television, search and social spend in one regression, and the channels are often bought in the same weeks: their separate returns come with wide intervals and change sign from one year’s model to the next. Credit-scoring and demand-forecasting teams choose among hundreds of candidate predictors, and the ones that survive are judged on a later time period, never on the data that chose them. In both settings the professional habit is the same: say what the model is for, choose candidates for a reason, report uncertainty honestly, and test on data the model hasn’t seen.
Fictional case
Ana’s note to the operations manager: “For forecasting Harbourside’s daily footfall I recommend the five-predictor model (temperature, rain, weekend, festival days and the café’s build-up). Fitted on March to September, it predicted October to December with a typical error of about 17 people a day (busier months may see larger misses); a model with every term I could think of fitted the summer better and missed the autumn by nearly 80. For explaining sales, footfall and transactions move almost together (VIF 34), so a model with both can’t say which matters: a visitor is worth about $3.18 in sales and a transaction about $6.64, each on its own, and the model shouldn’t be asked to split them. Peak barista hours improve the footfall forecast a little, but they reflect the manager’s own expectations, so I have left them out of any model meant to say what the weather or the weekend is worth.”
The note separates the two aims and gives each its own model. It reports the forecasting model’s accuracy on held-out months in the units the manager plans with, and names the alternative that looked better on paper and failed. It explains collinearity in one sentence without the jargon, and gives the two simple slopes as answers to two simple questions. And it states which predictor was left out of the explanatory model and why: the judgement that no automatic procedure makes.
Module 4 checks whether the chosen models’ assumptions hold: residual plots and the Durbin–Watson statistic for the days’ dependence in assumptions-and-diagnostics, logs and curves in transformations-and-influence. A model chosen by any of this lesson’s methods still needs those checks before its standard errors or intervals are trusted.
Knowledge check
Six questions, one attempt each, no hints. Score 80% or more to complete the lesson; you can take it again at any time.
Loading six questions…
Summary
- Multicollinearity is predictors so closely related that the data carry little information about each one’s separate slope: Harbourside’s footfall and transactions correlate at 0.985.
- It inflates standard errors and makes slopes unstable (footfall’s monthly slope ran from −$0.19 to $1.86 per person) without biasing them or harming predictions.
- VIF_j = 1/(1 − R_j²) multiplies the slope’s variance; its square root multiplies the standard error. Harbourside’s VIF of 34 widens the transactions slope’s SE about 5.8 times.
- The nested F test, F = ((SSE_R − SSE_F)/q) ÷ (SSE_F/(n − p_F)), judges a group of terms at once: six weekday dummies and their interactions add nothing to the weekend dummy (F = 0.70, p = 0.73).
- AIC = n ln(SSE/n) + 2p and BIC = n ln(SSE/n) + p ln n compare models on the same rows; BIC charges more per coefficient. Lower is better; small differences are negligible.
- Overfitting shows only on new data: a 17-predictor model with the best training fit forecast Harbourside’s autumn with an RMSE of 78.6 people against 16.5 for a five-predictor model. Test forward in time for a forecast.
- Choose predictors from the question: for explanation, confounders in and mediators out; for prediction, anything known in advance, judged on held-out data. Selecting by p-value finds chance and proxies.
Key formulas
- Variance inflation factor
- Standard error of a slope in a multiple regression
- Nested (general linear) F test
- AIC and BIC for least squares
- Root mean squared error on a test set
Terms introduced
- Multicollinearity
- Strong linear relationships among the predictors of a regression, which inflate the standard errors of their slopes and make the slopes unstable; perfect multicollinearity makes them impossible to estimate.
- Variance inflation factor
- For a predictor x_j, 1/(1 − R_j²), where R_j² is from regressing x_j on the other predictors: the factor by which collinearity multiplies the variance of its slope. Abbreviated VIF.
- Nested F test
- The F test of whether the terms dropped from a full regression model to give a reduced one improve the fit: F = ((SSE_R − SSE_F)/q) ÷ (SSE_F/(n − p_F)). Also called the general linear F test or partial F test.
- AIC
- Akaike information criterion: a measure for comparing models fitted to the same data, −2 × log-likelihood + 2p; for least squares n ln(SSE/n) + 2p plus a constant. Lower is better.
- BIC
- Bayesian (Schwarz) information criterion: −2 × log-likelihood + p ln n, which charges more per coefficient than AIC once n is 8 or more and so favours smaller models. Lower is better.
- Overfitting
- Fitting a model so closely to its own data, noise included, that it predicts new data worse than a simpler model would.
- Stepwise selection
- Choosing a regression’s predictors automatically by adding or removing them one at a time according to p-values or an information criterion. Its p-values, intervals and R² are biased in the model’s favour.
Sources
- Penn State Eberly College of Science. STAT 462: Applied Regression Analysis, section 10.7, “Detecting Multicollinearity Using Variance Inflation Factors”. online.stat.psu.edu/stat462/node/180
- Penn State Eberly College of Science. STAT 462: Applied Regression Analysis, “The general linear F-test”. online.stat.psu.edu/stat462/node/135
- Holmes, A., Illowsky, B. & Dean, S. Introductory Business Statistics 2e, section 13.4, “The Regression Equation” (multicollinearity). OpenStax. openstax.org/books/introductory-business-statistics-2e/pages…
- Taboga, M. “Linear regression — Model selection criteria”. Lectures on probability theory and mathematical statistics, StatLect. statlect.com/fundamentals-of-statistics/linear-regression-mo…
- Sribney, W. “Problems with stepwise regression” (quoting F. Harrell and R. Conroy). Stata FAQ, StataCorp. stata.com/support/faqs/statistics/stepwise-regression-proble…
- Penn State Eberly College of Science. STAT 462: Applied Regression Analysis, Lesson 11, “Model Building”. online.stat.psu.edu/stat462/node/89
