The Least-Squares Regression Line, Worked by Hand: House Size and Price
October 21, 2026
Simple linear regression fits a straight line to data to describe the relationship between two variables and to make predictions. The least-squares line minimizes the sum of the squared vertical distances between the data points and the line. Its slope is b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², and its intercept is a = ȳ − b x̄.
We will fit a line to illustrative data on six homes: size in square feet (x) and sale price in thousands of dollars (y). The data are x = 800, 1000, 1200, 1500, 1800, 2200 and y = 155, 180, 220, 250, 310, 360.
Skip the math and get your answer instantly:
Open the Average Calculator →Step 1: Means
The mean size is x̄ = 8,500 ÷ 6 = 1,416.7 square feet. The mean price is ȳ = 1,475 ÷ 6 = 245.8 thousand dollars. The regression line always passes through the point (x̄, ȳ).
Compute the deviations of each x and y from their means; these are the building blocks for the sums.
Step 2: Sums of Products and Squares
Σ(x − x̄)² = 1,368,333. Σ(x − x̄)(y − ȳ) = 203,417. Σ(y − ȳ)² = 30,421. The slope is b = 203,417 ÷ 1,368,333 = 0.1487 thousand dollars per square foot, or $148.66 per square foot. The intercept is a = 245.83 − 0.1487 × 1,416.67 = 35.2 thousand dollars.
The fitted line is: predicted price = 35.2 + 0.1487 × size, in thousands of dollars.
| Size (sq ft) | Actual price ($k) | Predicted price ($k) | Residual ($k) |
|---|---|---|---|
| 800 | 155 | 154.2 | +0.8 |
| 1,000 | 180 | 183.9 | -3.9 |
| 1,200 | 220 | 213.6 | +6.4 |
| 1,500 | 250 | 258.2 | -8.2 |
| 1,800 | 310 | 302.8 | +7.2 |
| 2,200 | 360 | 362.3 | -2.3 |
Interpretation
The slope says that each additional square foot is associated with about $149 more in price in this sample. The intercept ($35,200) is the predicted price of a zero-square-foot home, which is not meaningful by itself but is needed to position the line. The correlation coefficient is r = 203,417 ÷ √(1,368,333 × 30,421) = 0.997, and R² = 0.994, so 99.4% of the variation in price in this sample is explained by size. The data were chosen to be neatly linear; real housing data have far more scatter because of location, condition, and market timing.
The residuals are the differences between the actual and predicted values. They sum to zero, and a plot of residuals should show no pattern if a straight line is appropriate.
Making Predictions
For a 1,400-square-foot home, the predicted price is 35.2 + 0.1487 × 1,400 = $243.4 thousand. For a 2,000-square-foot home, $332.6 thousand. The typical size of the prediction error is the standard error of the estimate, here about $6.7 thousand, though uncertainty is larger for individual homes than for averages.
Do not extrapolate far beyond the range of the data (800 to 2,200 square feet). A 5,000-square-foot house would be predicted at $778,500, which might be badly wrong, because luxury homes follow different pricing patterns.
Using Tools and Checking Assumptions
In a spreadsheet use SLOPE, INTERCEPT, RSQ, and FORECAST.LINEAR, or the trendline option on a scatter chart. Check that the relationship looks linear, residuals have roughly constant spread, no extreme outliers dominate, and observations are independent. When assumptions fail, consider transforming variables (for example, the logarithm of price) or using multiple regression with more predictors like location and age.
Frequently Asked Questions
What is the least-squares line?
The straight line that minimizes the sum of squared vertical distances between the data and the line.
How do I calculate the slope?
Divide the sum of products of deviations by the sum of squared x deviations.
What does R-squared mean?
The share of the variation in y explained by the linear relationship with x.
Can I use the line to predict outside my data?
Cautiously. Extrapolation can be unreliable.
What is a residual?
The difference between an actual value and the value predicted by the line.