Lesson 1 of 7

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 lm model 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.

The trouble with one number

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).

RInteractive R
set.seed(1) n <- 160 sqft <- round(runif(n, 600, 2600)) price <- round(60000 + 180 * sqft + rnorm(n, 0, 28 * sqft)) # spread grows with sqft homes <- data.frame(sqft, price) head(homes, 4) #> sqft price #> 1 1131 245571 #> 2 1344 296833 #> 3 1746 431874 #> 4 2416 391814

  

Now fit the line and ask it about the client's 1,500 square foot flat:

RInteractive R
fit <- lm(price ~ sqft, data = homes) flat <- data.frame(sqft = 1500) round(predict(fit, flat)) # the single-number point prediction #> 1 #> 329113

  

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.