Skip to content

The least-squares line

Fit sales on advertising by least squares from ten weeks of data: compute the slope and intercept by formula, say what they mean in dollars, and predict sales within the range of the data.

It opens on

Over ten weeks, advertising rose from $10,000 to $26,000 and weekly sales from $128,000 to $195,000. Does each extra $1,000 of advertising go with about $0.4, $4.2 or $42 thousand more sales?

Why it matters

Budgets and forecasts rest on a fitted line that turns planned advertising into expected sales, and a manager needs to know how it is built, what its numbers mean and where it stops being trustworthy.

Good to know first

  • scatter plot

Step by step

  1. Fitting the line

    Compute b = Sxy / Sxx and a = ȳ − b x̄ for the ten weeks and write the line ŷ = a + bx.

    A common mix-up

    The best line passes through as many dots as possible.

    In fact: The least-squares line minimises the sum of squared misses, and it can pass through no dot at all.

  2. What the slope and intercept mean

    Interpret the slope and intercept in context and use the line to predict and find a residual.

    A common mix-up

    The intercept is the sales we would make with no advertising.

    In fact: It is the line's value at 0, outside the data range, so it may mean nothing in practice.

  3. Prediction, extrapolation and how well the line fits

    Separate predictions inside the data range from extrapolation, and read r and r² for the line.

    At advertising 21, inside the range, ŷ = 89.23 + 4.2106 × 21 = 177.65. At advertising 30, outside it, ŷ = 89.23 + 4.2106 × 30 = 215.55.

    ŷ(21) = 177.65 and ŷ(30) = 215.55

    A common mix-up

    A line with r² near 1 can predict anywhere on the x axis.

    In fact: The fit describes the range of the data, and r² says nothing about extrapolation.

Try it

A fit has x̄ = 5, ȳ = 40, Sxx = 20 and Sxy = 60. Find the line.Answer

b = 3 and a = 40 − 3 × 5 = 25, so ŷ = 25 + 3x

Hint: b = Sxy / Sxx, then a = ȳ − b x̄

Using ŷ = 89.23 + 4.2106x, find the predicted sales and the residual for the week with advertising 22 and sales 184.Answer

ŷ = 181.86 and e = 2.14

Hint: Predict first, then actual minus predicted

A fit is based on prices from $5 to $12. A manager predicts sales at a price of $20. What is the problem?Answer

$20 is outside the data, so it is extrapolation and the line may not hold

Hint: Compare 20 with the data range

What sales does the line predict in a week with advertising at its average, $17,900?Answer

164.6, the mean sales, since the line passes through the point of means

Predict sales for a week with advertising of 18.Answer

89.23 + 4.2106 × 18 = 165.02

The least-squares line

30 minutes every month. No card.