1. Home
  2. Explore
  3. Mathematics
  4. Basic Statistics Intro

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

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 (xxx)

Tip (yyy)

1

34

5

2

108

17

3

64

11

4

88

8

5

99

14

6

51

5

  • Dependent variable (yyy): tip amount (what we want to predict)

  • Independent variable (xxx): 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(ahorizontallineat10. That model (a horizontal line at10.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:

min⁡∑i=1n(yi−y^i)2\min \sum_{i=1}^{n} (y_i - \hat{y}_i)^2min∑i=1n​(yi​−y^​i​)2
  • yiy_iyi​ = actual observed value of the dependent variable (the real tip)

  • y^i\hat{y}_iy^​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(34) and the vertical axis near the smallest tip (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 rrr. For this data, r=0.866r = 0.866r=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ˉ\bar{x}xˉ) = $74

  • Mean tip (yˉ\bar{y}yˉ​) = $10

The point (xˉ,yˉ)(\bar{x}, \bar{y})(xˉ,yˉ​) = (74,10)(74, 10)(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:

y^i=b0+b1xi\hat{y}_i = b_0 + b_1 x_iy^​i​=b0​+b1​xi​

where:

  • b1b_1b1​ = slope of the line

  • b0b_0b0​ = yyy-intercept

Formula for Slope (b1b_1b1​)

b1=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2b_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}b1​=∑(xi​−xˉ)2∑(xi​−xˉ)(yi​−yˉ​)​

The numerator is the sum of the products of the deviations of xxx and yyy from their means. The denominator is the sum of the squared deviations of xxx.

Formula for Intercept (b0b_0b0​)

b0=yˉ−b1xˉb_0 = \bar{y} - b_1 \bar{x}b0​=yˉ​−b1​xˉ

Once the slope is known, the intercept follows directly.

Worked Example with Table

Set up a table to compute the necessary sums:

Meal

Bill (xxx)

Tip (yyy)

xi−xˉx_i - \bar{x}xi​−xˉ

yi−yˉy_i - \bar{y}yi​−yˉ​

(xi−xˉ)(yi−yˉ)(x_i - \bar{x})(y_i - \bar{y})(xi​−xˉ)(yi​−yˉ​)

(xi−xˉ)2(x_i - \bar{x})^2(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 xxx deviations) = 4206

Compute the slope:

b1=6154206≈0.1462b_1 = \frac{615}{4206} \approx 0.1462b1​=4206615​≈0.1462

Now compute the intercept:

b0=yˉ−b1xˉ=10−(0.1462×74)=10−10.8188≈−0.8188b_0 = \bar{y} - b_1 \bar{x} = 10 - (0.1462 \times 74) = 10 - 10.8188 \approx -0.8188b0​=yˉ​−b1​xˉ=10−(0.1462×74)=10−10.8188≈−0.8188

Thus, the regression line is:

y^=−0.8188+0.1462x\hat{y} = -0.8188 + 0.1462 xy^​=−0.8188+0.1462x

or equivalently:

y^=0.1462x−0.8188\hat{y} = 0.1462 x - 0.8188y^​=0.1462x−0.8188

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\hat{y} = 0.1462x - 0.8203y^​=0.1462x−0.8203, which is essentially the same.

The centroid (74,10)(74, 10)(74,10) satisfies this equation, confirming it lies on the line.


Interpreting the Regression Coefficients

  • Slope (b1=0.1462b_1 = 0.1462b1​=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.8188b_0 = -0.8188b0​=−0.8188): When the bill is 0,thepredictedtipisapproximately∗∗−0, the predicted tip is approximately **-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:

  1. Create a correctly scaled scatter plot and confirm a linear pattern.

  2. (Optional) Compute the correlation coefficient.

  3. Find the means of xxx and yyy and locate the centroid.

  4. Use the formulas to calculate the slope and intercept.

  5. 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 yyy? That question is addressed by measures such as R2R^2R2 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.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent