Prediction Intervals You Can Trust
Rohan is a real-estate agent. A client walks in with a 1,500 square foot flat and asks the only question that matters: "What will it sell for?" Rohan's model gives him one number, $329,000. He could say that out loud. He would also be wrong, because almost no flat sells for exactly its predicted price. What the client actually needs is a range Rohan can stand behind.
This whole course is about turning a single guess into an honest range: an interval you can promise will contain the truth a stated fraction of the time. It starts here, with the interval your regression already knows how to build, and the quiet way that interval can betray you.
By the end of this lesson you will be able to:
- Tell a confidence interval (about the average) apart from a prediction interval (about one new outcome), and say which one a client needs
- Read a 90% prediction interval out of an
lmmodel in R, and say exactly what "90%" promises - Test whether an interval keeps that promise, and see why the textbook interval under-covers exactly when it matters most
Prerequisites: you can fit a line with lm() and you know a residual is actual minus predicted (OLS regression, regression assumptions), plus basic R (vectors, data.frame). Every new term is defined as it appears.
A point prediction is a promise you cannot keep
Let us build Rohan's market and watch the problem appear. Each lesson runs in a fresh R session, so we create the data right here (run this once). Price climbs with size at about $180 a square foot, but look closely at the noise: its spread GROWS with size, because big homes vary far more than small ones (renovations, location, a bidding war).
Now fit the line and ask it about the client's 1,500 square foot flat:
There it is: $329,113. That is the model's best single guess, and it is the model's average home at 1,500 square feet. But the client is not selling the average flat. They are selling one flat, and one flat lands somewhere in a wide cloud around that average. Quote the single number and Rohan is wrong almost every time. The honest move is to quote a range.
A prediction interval comes with a coverage promise
A prediction interval is a range built around the prediction so that a genuinely new outcome falls inside it a stated fraction of the time. Write its lower and upper bounds as \([L, U]\). A 90% prediction interval is built to satisfy
\[ P\big(L \le Y_{\text{new}} \le U\big) = 0.90 \]
read out loud: the probability that a brand-new home's actual sale price \(Y_{\text{new}}\) lands between \(L\) and \(U\) is 90%. That "90%" is the interval's coverage, and it is a promise: run this on many new homes and about nine in ten should fall inside. You do not derive it by hand, lm builds it for you when you ask:
So instead of "$329,000", Rohan can say "very likely between $250,000 and $408,000." That range is honest. It is also uncomfortably wide, and the width is not a bug: it is the real spread of what one flat can fetch. A number that hides that spread is not more accurate, only more confident.
The mean is not the home
There are TWO intervals you can put around a regression prediction, and confusing them is the most common mistake in this whole topic.
A confidence interval captures the uncertainty in the line itself, the average price of ALL 1,500 square foot flats. Ask R for it and it is narrow:
Only about $6,000 either side. With 160 sales we have pinned the average flat down tightly. A prediction interval captures where ONE new home lands, so on top of that it must carry the home-to-home scatter around the average. That is why it was ten times wider ($250k to $408k).
Slide the sample size below. Watch the green confidence band collapse onto the line as data piles up (we learn the average ever more precisely), while the orange prediction band barely narrows: a single new home always carries its own irreducible noise, no matter how much data you gather.
The formula makes the split explicit. The normal-theory prediction interval for a new home at size \(x_0\) is
\[ \hat y_0 \;\pm\; t_{1-\alpha/2,\,n-2}\; s\sqrt{\,1 + \tfrac{1}{n} + \tfrac{(x_0-\bar x)^2}{S_{xx}}\,} \]
where \(\hat y_0\) is the point prediction, \(s\) is the residual standard deviation (the typical miss), \(t\) is a multiplier from the t-distribution that sets the level, \(n\) is the sample size, \(\bar x\) the mean size, and \(S_{xx}=\sum_i(x_i-\bar x)^2\) the spread of the sizes. The confidence interval is the SAME formula but without the \(1\) under the root. That lone \(1\) is the scatter of an individual home, the piece that never shrinks with more data, and the whole reason a prediction interval stays wide.
Which range do you quote the client?
Rohan's client wants to know what THEIR specific 1,500 square foot flat will sell for. Rohan has both intervals in front of him: a confidence interval of $322,785 to $335,441, and a prediction interval of $250,360 to $407,866. Which should he quote, and why?
That formula trusts a bell curve
Look back at the prediction-interval formula. It leans on a single number \(s\), one typical miss for the whole dataset. That is only fair if every home scatters around the line by roughly the same amount, the equal-variance (homoskedasticity) assumption behind every regression. Rohan's market breaks it on purpose: we built the noise to grow with size. Let us catch it red-handed by comparing the average miss for small versus large homes.
A typical small home misses the line by about $28,000; a typical big home misses by about $44,000, over half again as much. The single pooled \(s\) that lm plugs into the interval is just an average of the two. So the interval it builds is too WIDE for small homes and too NARROW for big ones. You can see the fan in the residuals themselves:
The band that looked so reasonable is quietly the wrong width almost everywhere. The only way to know how badly is to test it.
Does a 90% interval really cover 90%?
There is exactly one honest way to check an interval: take a pile of fresh homes whose true prices you know, and count how many land inside their own intervals. That fraction is the empirical coverage. If the interval is honest, it should come out near 0.90.
Let us run exactly that recipe on 5,000 brand-new homes drawn from the same market:
0.897. The interval looks like it kept its promise. But an average across all homes can hide a lot. Rohan's clients with the priciest listings are exactly the big homes, so let us mark those out and look at them separately in a moment.
Uncover the failure
inside is TRUE for every fresh home whose real price fell within its 90% interval, and big is TRUE for the larger homes. Rohan sold every client the same "90% confident" range. Compute the coverage among the BIG homes alone, the expensive listings where a miss costs the most. Fill in the blank.
Show answer
big_coverage <- mean(inside[big])
big_coverage
#> [1] 0.8213439
mean(inside[!big]) # the small homes, for contrast
#> [1] 0.9744939What went wrong, and what fixes it?
Rohan's 90% interval covered 97% of small homes but only 82% of the big ones, even though it averaged out near 90% overall. What is the cause, and the right fix?
References
A few authoritative places to take prediction intervals further:
- An Introduction to Statistical Learning, ch. 3 (free PDF) - its "prediction intervals versus confidence intervals" discussion is the exact distinction this lesson turns on.
- Penn State STAT 501: Regression Methods - free lessons that derive the interval you asked
lmfor, with the formula and its assumptions spelled out. - R documentation: predict.lm - the
interval = "confidence"versus"prediction"argument you used, straight from the source. - Angelopoulos and Bates (2023), A Gentle Introduction to Conformal Prediction - where this course heads next: distribution-free intervals whose coverage holds even when the bell curve does not.
Lesson 1 complete
You can now turn a point prediction into an honest range. A confidence interval is about the average outcome, narrow and shrinking with data; a prediction interval is about one new outcome, wide because it carries the irreducible scatter that never shrinks. You know what its "90%" promises, how to ask lm for it, and how to test whether it delivers by measuring empirical coverage on fresh data.
And you saw the crack: when the errors are not the tidy, equal-variance bell the formula assumes, that single interval is the wrong width, under-covering exactly the high-stakes cases. The comfortable overall 90% was an average hiding an 82%.
Next, Lesson 2: Split Conformal Prediction. Instead of trusting a formula's assumptions, you will build an interval whose coverage is guaranteed by the data itself, holding at or above your target no matter what the errors look like, using only a held-out calibration set and a single quantile.