Question
A courier charges a $20 dispatch fee plus $3 per kilometre for a delivery. An analyst observes four jobs with distances 1, 2, 3 and 4 km, and their exact corresponding charges, with no noise. The analyst wants to use least squares to fit a line predicting the charge in dollars from distance in kilometres.
Find the fitted intercept and slope when both are free. Then calculate the least-squares slope when the analyst forces the intercept to zero, and explain which deliveries that constrained model will underprice or overprice. Why is forcing the line through the origin more than a cosmetic change?
Get hint
Hint 1
Write the four charges using \(y_i=20+3x_i\). The unrestricted line can fit all four observations perfectly.
Check your answer
Solution
The four observations are \((x_i,y_i)=(1,23),(2,26),(3,29),(4,32)\). An unrestricted affine fit \(y=a+bx\) can reproduce each exactly with \((a,b)=(20,3)\); because distances vary and zero residual is minimal, this is the unique least-squares solution. Equivalently, the normal equations \(\sum(y_i-a-bx_i)=0\) and \(\sum x_i(y_i-a-bx_i)=0\) give the same coefficients.
With the intercept constrained to zero, minimize \(\sum_i(y_i-b_0x_i)^2\). Differentiating yields
\[
0=-2\sum_i x_i(y_i-b_0x_i),\qquad
b_0=\frac{\sum_i x_iy_i}{\sum_i x_i^2}.
\]
Here \(\sum x_i=10\), \(\sum x_i^2=30\), and the actual charges satisfy \(y_i=20+3x_i\), so
\[
\sum x_iy_i=20(10)+3(30)=290,
\qquad b_0=\frac{290}{30}=\boxed{\frac{29}{3}}.
\]
The forced-origin slope is inflated by
\[
b_0-3=20\frac{\sum x_i}{\sum x_i^2}=\frac{20}{3}\ \text{dollars/km},
\]
because the missing $20 fixed fee is pushed into the per-kilometre coefficient. The prediction error (prediction minus actual) at distance \(x\) is
\[
\frac{29}{3}x-(20+3x)=\frac{20}{3}(x-3).
\]
It is negative at 1 and 2 km, zero at 3 km, and positive at 4 km. Fitting through the origin asserts that a zero-kilometre dispatch would cost $0, contradicting the known fixed fee; that is a substantive model restriction, not a display choice.
Assumptions
Delivery charges are exactly \(20+3x\) dollars, with \(x\) in kilometres, at the four specified distances.
Unweighted ordinary least squares is used with equal weight for all four observations.
Final Answer
With an intercept: \(\widehat y=20+3x\). Through the origin: \(\widehat y=(29/3)x\approx9.667x\) dollars. The constrained fit underpredicts at 1–2 km, is exact at 3 km, and overpredicts at 4 km.