Basic Statistics Intro
Simple Linear Regression: The Least Squares Method
The core of simple linear regression is the least squares method. This method finds the line that best fits the data by minimizing the sum of the squared differences between the observed values of the dependent variable and the values predicted by the regression line. These notes walk through the entire process—from setting up the problem to calculating and interpreting the regression line.
The Problem Setup
Suppose a restaurant wants to predict the tip amount based on the total bill amount. Data from six meals is collected as matched pairs.
Meal | Total Bill (x) | Tip (y) |
|---|---|---|
1 | 34 | 5 |
2 | 108 | 17 |
3 | 64 | 11 |
4 | 88 | 8 |
5 | 99 | 14 |
6 | 51 | 5 |
Dependent variable (y): tip amount (what we want to predict)
Independent variable (x): total bill amount (used to make the prediction)
It does not make sense to reverse the roles; the bill amount logically influences the tip, not the other way around.
If only the tip data were available (ignoring the bill), the best prediction for any future tip would be the mean of the tips, which is 10.Thatmodel(ahorizontallineaty = 10$) produced a sum of squared residuals (SSE) of 120. The regression model should produce a smaller SSE to be considered useful.
The Least Squares Criterion
The least squares criterion is expressed as:
yi = actual observed value of the dependent variable (the real tip)
y^i = predicted value of the dependent variable from the regression line
The goal is to find the line that makes this sum as small as possible — that is, minimize the total squared vertical distance between the data points and the line.
Key idea: The least squares method chooses the line that minimizes the sum of the squared differences between observed and predicted values.
Steps to Find the Regression Line
Step 1: Scatter Plot
Always start by plotting the data. A correctly scaled scatter plot reveals the overall pattern and potential outliers. For this data, the horizontal axis should start near the smallest bill (34)andtheverticalaxisnearthesmallesttip(5) to avoid distortion.
Step 2: Check for a Linear Pattern
Visually inspect whether the points fall roughly along a straight line. If the data form a random blob (no linear pattern), regression is inappropriate. Here, the points show a clear upward trend, so linear regression is reasonable.
Step 3: Correlation Coefficient (Optional but Recommended)
Compute the Pearson correlation coefficient r. For this data, r=0.866, indicating a strong, positive, linear relationship. This supports the visual impression and will be useful in later analyses.
Step 4: Descriptive Statistics and the Centroid
Calculate the mean of each variable:
Mean bill (xˉ) = $74
Mean tip (yˉ) = $10
The point (xˉ,yˉ) = (74,10) is called the centroid. The regression line must pass through the centroid. Knowing this gives one fixed point on the line, which simplifies finding the line.
Calculating the Slope and Intercept
The general form of the regression line is:
where:
b1 = slope of the line
b0 = y-intercept
Formula for Slope (b1)
The numerator is the sum of the products of the deviations of x and y from their means. The denominator is the sum of the squared deviations of x.
Formula for Intercept (b0)
Once the slope is known, the intercept follows directly.
Worked Example with Table
Set up a table to compute the necessary sums:
Meal | Bill (x) | Tip (y) | xi−xˉ | yi−yˉ | (xi−xˉ)(yi−yˉ) | (xi−xˉ)2 |
|---|---|---|---|---|---|---|
1 | 34 | 5 | -40 | -5 | 200 | 1600 |
2 | 108 | 17 | 34 | 7 | 238 | 1156 |
3 | 64 | 11 | -10 | 1 | -10 | 100 |
4 | 88 | 8 | 14 | -2 | -28 | 196 |
5 | 99 | 14 | 25 | 4 | 100 | 625 |
6 | 51 | 5 | -23 | -5 | 115 | 529 |
Sum = 615 | Sum = 4206 |
Numerator (sum of product deviations) = 615
Denominator (sum of squared x deviations) = 4206
Compute the slope:
Now compute the intercept:
Thus, the regression line is:
or equivalently:
Note: Regression is sensitive to rounding. It is best practice to keep values to four decimal places. Manual calculations may differ slightly from software output due to rounding. For example, Excel gave y^=0.1462x−0.8203, which is essentially the same.
The centroid (74,10) satisfies this equation, confirming it lies on the line.
Interpreting the Regression Coefficients
Slope (b1=0.1462): For every $1 increase in the total bill, the predicted tip amount increases by about $0.15 (more precisely, $0.1462).
Intercept (b0=−0.8188): When the bill is 0,thepredictedtipisapproximately∗∗−0.82**. This has no practical meaning in this context (a negative tip is impossible). The intercept is a mathematical necessity of the line, but it may or may not make sense in real-world terms. Always interpret it with caution.
Conclusion and What's Next
The least squares method provides a systematic way to find the best-fitting line for a set of paired data. The steps are:
Create a correctly scaled scatter plot and confirm a linear pattern.
(Optional) Compute the correlation coefficient.
Find the means of x and y and locate the centroid.
Use the formulas to calculate the slope and intercept.
Assemble the regression line equation.
This line must pass through the centroid. The next step is to evaluate whether this regression line is actually a good model — that is, does it reduce the sum of squared residuals significantly compared to simply using the mean of y? That question is addressed by measures such as R2 and by comparing the SSE from regression (which will be smaller than 120) with the SSE from the mean-only model.

Ask anything
We've read this whole study set, so questions about it get the best answers.