From Paired Observations to a Fitted Line
In “Computing Slope and Intercept From Summary Statistics,” we found a regression line from the correlation, standard deviations, and means. Here we start one step earlier: with the individual paired data. We will calculate the least-squares line by hand for five observations, using sums that can be found directly from a data table.
Let \(x\) be the predictor and \(y\) the response. Each row must contain the two values measured on the same case. The fitted line has the form \(\hat{y}=a+bx\), where \(b\) is the slope and \(a\) is the intercept. We will use raw sums to find the slope, then use the means to find the intercept.
The numerator and denominator have useful interpretations. The numerator is the sum of paired deviations from the means, and the denominator is the sum of squared deviations of the predictor values from their mean. In symbols, these are \(S_{xy}=\sum(x_i-\bar{x})(y_i-\bar{y})\) and \(S_{xx}=\sum(x_i-\bar{x})^2\), so the slope is \(b=S_{xy}/S_{xx}\). The raw-sums formula calculates those same quantities without first writing every deviation from a mean.
The predictor values must vary; if they are all identical, the denominator is zero and there is no least-squares slope to calculate. In ordinary use, the data should also be paired quantitative observations, with the explanatory and response roles chosen before calculating. These calculations give the fitted line for the data at hand; they do not, by themselves, establish causation.
A Hand-Calculation Routine
A small table helps keep each operation organized. Alongside \(x\) and \(y\), calculate \(x^2\) and \(xy\) for every row. Add each column, then substitute the totals into the raw-sums formula. The product \(xy\) must be computed separately within each row before adding; it is not the product of the column totals.
Label \(x\) as the predictor and \(y\) as the response. Keep each response value in the same row as its corresponding predictor value.
For each row, find \(x^2\) and \(xy\). Add the \(x\), \(y\), \(x^2\), and \(xy\) columns.
Substitute the four totals and \(n\) into the raw-sums formula. Check that the denominator is positive when the predictor values vary.
Find \(\bar{x}\) and \(\bar{y}\), calculate \(a=\bar{y}-b\bar{x}\), and write \(\hat{y}=a+bx\).
Confirm that substituting \(\bar{x}\) into the line gives approximately \(\bar{y}\). When convenient, also compare the raw sums with sums of deviations from the means.
The check at the mean point follows from the intercept formula: \(a+b\bar{x}=\bar{y}\). This is a useful arithmetic check, not a separate fitting method. Keep extra digits during the calculation and round the coefficients only when writing the final equation.
Worked Example: Practice Time and a Skills Score
Suppose five fictional participants record practice time \(x\), in hours, and a skills score \(y\), in points. We will find the line that predicts skills score from practice time. The data are invented for calculation practice.
| Participant | \(x\), hours | \(y\), points | \(x^2\) | \(xy\) | |
|---|---|---|---|---|---|
| 1 | 1 | 2 | 1 | 2 | |
| 2 | 2 | 3 | 4 | 6 | |
| 3 | 3 | 5 | 9 | 15 | |
| 4 | 4 | 4 | 16 | 16 | |
| 5 | 5 | 6 | 25 | 30 | |
| Sum | 15 | 20 | 55 | 69 |
Worked Example: Calculate the Line From Raw Sums
There are \(n=5\) paired observations. The table gives \(\sum x=15\), \(\sum y=20\), \(\sum x^2=55\), and \(\sum xy=69\). Substitute these totals into the slope formula:
The means are \(\bar{x}=15/5=3\) hours and \(\bar{y}=20/5=4\) points. Calculate the intercept:
The fitted line is \(\hat{y}=1.3+0.9x\). Its slope is \(0.9\) points per hour: in these observations, for each additional hour of practice, the line’s predicted skills score increases by \(0.9\) point. The intercept predicts \(1.3\) points at zero hours of practice; whether that prediction is meaningful depends on the context and the observed range.
Check the mean point: \(1.3+(0.9)(3)=4\), which equals \(\bar{y}\). As a second arithmetic check, the centered predictor values are \(-2,-1,0,1,2\), and the centered response values are \(-2,-1,1,0,2\). Their paired products sum to \(4+1+0+0+4=9\), and the squared predictor deviations sum to \(4+1+0+1+4=10\). Thus \(S_{xy}/S_{xx}=9/10=0.9\), matching the raw-sums calculation.
Worked Example: Trail Distance and Rest Stops
In another invented set of five observations, \(x\) is a hiker’s distance along a trail, in kilometers, and \(y\) is the number of rest stops recorded by that point. Find the line that predicts rest stops from distance.
Worked Example: Keep the Paired Products Straight
The paired values are \((2,9),(4,8),(6,6),(8,5),(10,2)\). The calculation totals are:
Using \(n=5\), calculate the slope:
Both means equal \(30/5=6\). Therefore:
The fitted line is \(\hat{y}=11.1-0.85x\), with predicted rest stops per kilometer as the slope’s units. For each additional kilometer, the line’s predicted number of rest stops decreases by \(0.85\). This describes the observed association in the invented data; it does not mean that traveling farther causes the number of earlier rest stops to decrease.
Check the mean point: \(11.1-0.85(6)=11.1-5.1=6\), equal to \(\bar{y}\). The negative numerator gives a negative slope, which is consistent with the downward pattern in these paired observations.
Worked Example: Operating Time and Energy Use
A fictional equipment log records operating time \(x\), in hours, and energy use \(y\), in kilowatt-hours, for five operating periods. This example uses predictor values that are not consecutive whole numbers, but the same calculation applies.
Worked Example: Calculate With Less Evenly Spaced Predictor Values
The paired data are \((10,3),(12,4),(15,6),(18,7),(20,8)\). First calculate the column totals:
There are five observations, so the slope is:
The means are \(\bar{x}=75/5=15\) hours and \(\bar{y}=28/5=5.6\) kilowatt-hours. The intercept is:
The fitted equation is \(\hat{y}=-1.9+0.5x\). The slope is \(0.5\) kilowatt-hour per operating hour. For each additional operating hour, the line’s predicted energy use increases by \(0.5\) kilowatt-hour. The intercept is the predicted energy use at zero operating hours, but that value may not be practically meaningful for this equipment log.
Check: \(-1.9+(0.5)(15)=-1.9+7.5=5.6\), which matches the mean energy use. The centered values provide another check: the \(x\)-deviations are \(-5,-3,0,3,5\), whose squares sum to \(68\). The \(y\)-deviations are \(-2.6,-1.6,0.4,1.4,2.4\); their paired products with the \(x\)-deviations sum to \(13+4.8+0+4.2+12=34\). Thus \(34/68=0.5\), the same slope.
Common Mistakes and AP Exam Tips
Raw-data calculations involve several sums that can look similar. Keep the order of operations visible and check that each total comes from the correct column. A carefully labeled table is often the simplest way to prevent a small arithmetic mistake from changing both coefficients.
- Multiplying the totals instead of adding paired products. \(\sum xy\) is found by multiplying \(x\) and \(y\) within each row and adding those products. It is not generally equal to \((\sum x)(\sum y)\).
- Confusing \(\sum x^2\) with \((\sum x)^2\). Square each predictor value and then add to find \(\sum x^2\). Square the predictor total only where the formula explicitly uses \((\sum x)^2\).
- Breaking the pairing. If a \(y\)-value is placed on the wrong row, the \(xy\) total no longer describes the original paired data. Preserve the original pairings throughout the calculation.
- Reversing predictor and response. The denominator uses the predictor values \(x\), and the line predicts \(y\) from \(x\). Switching the roles changes the regression problem.
- Finding the intercept with the wrong means. Use \(a=\bar{y}-b\bar{x}\), not \(\bar{x}-b\bar{y}\). The resulting equation must predict the response.
- Rounding too soon. Keep full calculator or fraction precision for the slope while finding the intercept, then round the final coefficients. A small rounding difference in the mean-point check is acceptable.
- Interpreting the slope as an actual change for every case. The slope describes how the line’s predicted response changes per predictor unit. Individual observed responses can differ from their predictions.
For a complete AP-style calculation, identify the predictor and response, show the substituted raw sums for the slope, calculate the intercept using the two means, and write the equation with \(\hat{y}\) on the left. If interpretation is requested, state the slope’s direction, variables, and response units per predictor unit. A mean-point check is a concise way to confirm the intercept.
Check Your Understanding
For each question, treat \(x\) as the predictor and \(y\) as the response.
- For the five pairs \((1,4),(2,5),(3,5),(4,7),(5,9)\), calculate \(\sum x\), \(\sum y\), \(\sum x^2\), and \(\sum xy\).
- For those same pairs, use the raw-sums formula to calculate the slope of the least-squares line.
- Using the data in question 1, calculate the intercept and write the fitted equation.
- Explain why \(\sum xy\) is not found by multiplying \(\sum x\) by \(\sum y\).
- A proposed fitted line has \(\bar{x}=4\), \(\bar{y}=7\), and predicts \(7.3\) when \(x=4\). What does this suggest about the calculation or rounding?