Suppose a city notices that places with higher bus fares tend to have fewer bus riders. How could we put a number on that pattern? We could draw a line through a scatterplot. But which line? A line can be placed in many ways, and “looks about right” is not a rule another researcher can reproduce.
Ordinary least squares, usually shortened to OLS, gives us a precise rule: choose the line that makes the sum of squared vertical prediction errors as small as possible. That rule produces a useful summary of the data. It does not, by itself, tell us that changing fares caused ridership to change.
A line as a compact description
Let be an observed explanatory variable for unit —for example, the bus fare in a city—and let be an outcome such as weekly rides. A simple linear regression writes the fitted outcome as
Here is the fitted value: what the line predicts at . The number is the intercept, and is the slope. The observed value will usually not fall exactly on the line. Its residual is
A positive residual means the observed outcome is above the prediction; a negative residual means it is below. Residuals let us see where and by how much the line misses. They are not the same as the unobserved influences in an economic model: they are calculated from observed outcomes and fitted predictions.
Why square the residuals?
If we simply added residuals, positive and negative misses could cancel. OLS instead chooses and to minimize the residual sum of squares:
Squaring makes every contribution nonnegative and gives larger misses more weight. This is a choice of loss function: OLS treats a miss twice as large as another as four times as costly in the objective. That can make the fitted line sensitive to unusual points, so it is worth looking at a plot rather than trusting a coefficient alone.
To find the minimizing line, take derivatives of with respect to the intercept and slope and set them equal to zero. For the intercept,
so the residuals sum to zero. For the slope,
Solving these conditions gives
The slope is large in magnitude when and move together strongly relative to how much varies. The intercept then makes the fitted line pass through the sample means . In the usual model with an intercept, the fitted residuals also have zero sample mean and are uncorrelated with the included values. These are mathematical properties of the fitted line—not evidence that all relevant economic influences have been accounted for.
What the slope says—and what it does not
In a simple regression, is the change in the fitted outcome associated with a one-unit increase in . Its units are “units of per unit of .” If is dollars per ride and is thousands of rides per week, then means the fitted weekly ridership is 2,000 trips lower for a one-dollar higher fare in this sample’s line.
That is an association. It is not automatically the effect of raising a fare. Cities with high fares may also have different incomes, population densities, service quality, or commuting patterns. Those factors may be related to both fares and ridership. OLS has minimized a particular set of prediction errors; it has not created the missing comparison of what ridership would have been in the same city under a different fare.
With several explanatory variables, a linear fitted equation can be written
Now describes the change in the fitted outcome associated with a one-unit increase in while the other included variables are held fixed. This “holding fixed” is a comparison inside the regression model. It does not prove that every confounding difference has been controlled or that the remaining association is causal. The design and assumptions behind the comparison still matter.
Summarizing fit without worshipping it
For a simple in-sample regression with an intercept, one common fit statistic is :
It compares the fitted line’s squared residuals with the squared deviations we would have if we predicted every observation using the sample mean alone. An of 0.80 means the line reduces that in-sample squared-error measure by 80% relative to the mean-only baseline, under this definition. It does not mean the predictor caused 80% of the outcome, that 80% of predictions are correct, or that the model will predict new observations equally well.
A high can coexist with a bad causal story, influential outliers, or an inappropriate straight-line shape. A low can still accompany a useful estimate of a particular slope. Plot the data, inspect residuals, check units and ranges, and ask whether the linear summary fits the question. Predictions far beyond the observed values are extrapolations; the data provide less support for them.
Worked example
Four fictional cities have the following average bus fares and weekly bus rides: , , , and , where fares are dollars per ride and ridership is in thousands. Find the OLS line, calculate its fitted values and residuals, and interpret the slope and without making a causal claim.
Step 1 — calculate the sample means. The average fare and average ridership are
Step 2 — calculate the slope. Use the OLS formula:
so
The fitted line falls by two thousand weekly rides for each additional dollar of fare in this sample.
Step 3 — calculate the intercept. The line passes through :
Therefore the fitted equation is
Step 4 — calculate predictions and residuals. For fares 1, 2, 3, and 4, the fitted ridership values are 8, 6, 4, and 2 thousand. Subtract fitted from observed:
| Fare | Observed rides | Fitted rides | Residual | | ---: | ---: | ---: | ---: | | 1 | 9 | 8 | 1 | | 2 | 5 | 6 | -1 | | 3 | 3 | 4 | -1 | | 4 | 3 | 2 | 1 |
The residual sum of squares is
Step 5 — calculate . The total sum of squares around the mean ridership is
Thus
The fitted line reduces squared prediction error by about 83.3% relative to predicting the sample mean for every city. The negative slope describes a strong downward linear association in these four fictional observations. It does not show that raising a fare would cause the same ridership change: four cities may differ in many other ways, and the example supplies no causal design.
Where this leads
OLS gives economists a reproducible way to summarize conditional relationships, produce fitted values, and measure residual variation. Its algebra answers “which line best fits these data under squared error?” It does not answer “what would happen if we changed ?” The next topic, Causal Inference: From Correlation to Credible Comparisons, will ask what additional comparison and assumptions are needed before a regression coefficient can support a causal interpretation.