Data and statistics · cheat sheet

Simple linear regression

A straight-line model of how a result (y) changes with one input (x): y = b0 + b1 × x, fitted to the data, used to understand and predict.

Common practice
6 steps
Used by Process Improvement Specialist

What it is

Simple linear regression fits the straight line y = b0 + b1 × x that best matches the data (least squares). The slope b1 says how much y changes for each unit of x.

When to use it

When one input seems to drive a result and you want to know by how much, and to predict.

Why it works

It turns “these go together” into “this much change in x gives this much change in y”, which is what decisions need.

Do

  • Look at a plot of residuals against predicted values: it should look like random scatter.

Don't

  • Predicting far outside the data.
  • Ignoring a pattern in the residuals.
  • Treating R² as the only test of a good model.

Step by step

  1. Plot
  2. Fit
  3. Slope and p-value
  4. R²
  5. Residuals
  6. Predict with an interval
Also called: Regression line, least squares, residualsPrint the blank template ↗

Worked example

The situation. The café's temperature and sales.

  1. Sales = -2.5 + 15.00 × temperature; R² 1.00.

The result. Stock levels follow the forecast; waste fell by a third.

Regression worksheet Print blank
PartValue
Slope15.00 more drinks per degree
Intercept-2.5
R²1.00
Prediction at 25 °C372 drinks

Filled in for: The café's temperature and sales.

PartValue

Copy this structure, or print the blank version and fill it in by hand. Equation y = b0 + b1 × x · R² · p-value of slope · residual check (pattern? spread?) · prediction and interval

Before you use it: check these

CheckIf it fails
Residuals look random, with even spreadTry a curve or a transformation
Residuals roughly normalPredictions are fine; intervals less so: transform or use more data
Predict only inside the data's rangeCollect data for the range you need

How to do it with real data

The full calculation, as it happens in the story: the data, every step, how to read the result, and the spreadsheet functions to do it yourself.

Worked example with real data

How much does each routine slot shorten the wait?

From Day 38: How much difference would it make? of the Process Improvement Specialist story

Astrid (Data Analyst) fits a straight line through the 20 weeks: median wait against routine slots offered.

Median wait against routine slots, with the fitted line05101520220233246259272Routine slots offered per weekMedian wait (days)259, 8261, 9270, 8265, 7254, 9262, 8259, 9263, 8254, 8263, 9263, 8240, 10234, 10235, 11225, 11243, 12222, 12238, 13230, 12228, 13

Step by step

  1. Fit the lineleast squares: the line that makes the squared vertical distances smallest
  2. Equationwait = 35.85 − 0.105 × slots
  3. Slopeeach extra routine slot a week= −0.105 days; 10 slots ≈ 1 day shorter
  4. Is the slope real?t = −0.1051 ÷ 0.0143= t = −7.36, p below 0.0001
  5. R²share of the variation in weekly waits explained by slots= 0.75
  6. Residualsactual − predicted; typical size 0.97 days, no pattern, roughly normal= model is reasonable
  7. Prediction at 262 slots35.85 − 0.105 × 262; 95% confidence interval for the average ±0.61, prediction interval for one week ±2.13= 8.3 days
WeekRoutine slots offeredUrgent use of routine slots (%)Median wait (days)
Week 1259118
Week 2261139
Week 3270158
Week 4265117
Week 5254149
Week 6262108
Week 7259149
Week 8263128
Week 9254118
Week 10263129
Week 11263128
Week 122401210
Week 13234810
Week 142351411
Week 152251011
Week 162431812
Week 172221312
Week 182381613
Week 192301212
Week 202281513

How to read the result

Slots explain three quarters of the week-to-week variation. Getting back to 262 routine slots a week would bring the weekly median back to about 8.3 days: better, but not the 5-day goal on its own.

What it led to

Restoring lost capacity is necessary but not enough. Model the other causes together.

Do it in a spreadsheet

Slope and intercept=SLOPE(D2:D21,B2:B21) and =INTERCEPT(D2:D21,B2:B21)
R²=RSQ(D2:D21,B2:B21)
Full output=LINEST(D2:D21,B2:B21,TRUE,TRUE), or Data Analysis, Regression
Prediction=FORECAST.LINEAR(262,D2:D21,B2:B21)
Try it yourself: Why is the prediction interval (±2.13) so much wider than the confidence interval (±0.61)?

The confidence interval is for the average wait of all weeks with 262 slots. The prediction interval is for one single week, which also varies around that average.

In the roles

How a Process Improvement Specialist uses it

Weekly median wait = 35.85 − 0.105 × routine slots; R² 0.75; 262 slots predicts 8.3 days ± 2.1.

Questions people ask

Confidence or prediction interval?

Confidence: for the average at a given x. Prediction: for one new value, always wider.

Related techniques

← All techniques and tools