Linear Regression Models

Linear regression is one of the most powerful and widely used tools in statistics. It allows us to model the relationship between two quantitative variables by fitting a straight line through a scatter plot of data. The goal is to find the line that best summarises the trend in the data, enabling us to describe how one variable changes as another variable changes, and to make predictions for new values. The most common method for fitting this line is called the method of least squares, which finds the line that minimises the sum of the squared vertical distances between each data point and the line itself. These vertical distances are called residuals. By minimising the total squared residual, the least-squares line is guaranteed to be the single best linear fit to the data in a precise mathematical sense. Linear regression is used across virtually every field of science, economics, medicine, and engineering. Understanding how to fit, interpret, and critically evaluate a least-squares regression line is an essential skill in data exploration. In this article you will learn the formulas for computing the regression line, how to interpret its slope and intercept in context, and how to assess the quality of the fit using the coefficient of determination, r².

Key takeaways
  • Identify the Explanatory and Response Variables
  • Calculate Summary Statistics
  • Compute the Slope b₁
  • Compute the Intercept b₀
  • Write the Regression Equation and Interpret
  • Examine Residuals

Identify the Explanatory and Response Variables

Before fitting any line, decide which variable is the explanatory variable (also called the independent or predictor variable, placed on the x-axis) and which is the response variable (also called the dependent variable, placed on the y-axis). For example, if you are studying how hours of study (x) predicts exam score (y), hours of study is the explanatory variable.

Calculate Summary Statistics

You need five summary statistics: the means x̄ and ȳ, the standard deviations sₓ and sᵧ, and the correlation coefficient r. These can be computed from your data set or read from a statistics calculator. The means tell you where the centre of the data lies, the standard deviations describe the spread, and r describes the strength and direction of the linear association (r ranges from −1 to +1).

Compute the Slope b₁

The slope of the least-squares line is given by b₁ = r · (sᵧ / sₓ). The slope tells you, on average, how many units y changes for each one-unit increase in x. Notice that the slope has the same sign as r: if the association is positive (r > 0), the line slopes upward; if negative (r < 0), it slopes downward. The ratio sᵧ/sₓ rescales the correlation from standardised units into the original units of the data.

Compute the Intercept b₀

The intercept is found by using the fact that the least-squares line always passes through the point (x̄, ȳ), the intersection of the two means. Substituting into ŷ = b₀ + b₁x gives b₀ = ȳ − b₁x̄. The intercept is the predicted value of y when x = 0. Be cautious: this may not always be meaningful in context if x = 0 is outside the range of your data.

Write the Regression Equation and Interpret

Write the equation as ŷ = b₀ + b₁x, replacing ŷ, b₀, b₁, x with the actual variable names and values. For example: predicted score = 42.3 + 5.8 × (hours studied). Always interpret the slope in context: 'For each additional hour studied, the predicted exam score increases by 5.8 points.' Check whether the intercept is meaningful. Finally, compute r² to describe how much of the variability in y is explained by the linear relationship with x.

Examine Residuals

A residual is the difference between an observed y value and the value predicted by the regression line: e = y − ŷ. By construction, the sum of all residuals equals zero for the least-squares line. Plotting residuals against x (a residual plot) is essential for checking whether a linear model is appropriate. A good fit shows residuals scattered randomly around zero with no pattern. A curved pattern in the residual plot signals that a linear model may not be the best choice.

The Key Equation

y^=b0+b1x,b1=r⋅sysx,b0=yˉ−b1xˉ\hat{y} = b_0 + b_1 x, \quad b_1 = r \cdot \frac{s_y}{s_x}, \quad b_0 = \bar{y} - b_1\bar{x}
  • \hat{y} — Predicted value of y (units of y): The value of the response variable predicted by the regression model for a given x; pronounced 'y-hat'.
  • b_0 — Intercept (units of y): The predicted value of y when x = 0; the point where the regression line crosses the y-axis.
  • b_1 — Slope (units of y per unit of x): The average change in y for each one-unit increase in x.
  • r — Correlation coefficient (dimensionless): Measures the strength and direction of the linear association between x and y; ranges from −1 to +1.
  • s_y,\; s_x — Standard deviations of y and x (units of y; units of x): Measures of spread; their ratio rescales the correlation into slope units.
  • \bar{x},\; \bar{y} — Means of x and y (units of x; units of y): The arithmetic means of each variable; the least-squares line always passes through (x̄, ȳ).

Worked Example

Problem. A statistics student records the number of hours seven classmates studied for a maths test and their resulting scores. The summary statistics are: x̄ = 4.0 hours, ȳ = 68.0 points, sₓ = 1.5 hours, sᵧ = 9.0 points, r = 0.85. (a) Find the least-squares regression line. (b) Predict the score for a student who studied for 5 hours. (c) Calculate and interpret r².

y^=47.6+5.1x;y^(5)=73.1 points;r2=0.7225\hat{y} = 47.6 + 5.1x; \quad \hat{y}(5) = 73.1 \text{ points}; \quad r^2 = 0.7225

Answer. Regression line: ŷ = 47.6 + 5.1x. Predicted score for 5 hours = 73.1 points. r² ≈ 72.3%.

Figure
Diagram
Least-Squares Regression Line with ResidualsHours Studied (x)Exam Score (y)ŷ = 47.6 + 5.1x12345675060708090Data pointsRegression lineResiduals (y − ŷ)
Origins · 1 minCarl Friedrich Gauss and how this was discovered
CF
Carl Friedrich Gauss
1777–1855 · German

Gauss developed the method of least squares around 1795 (at age 18!) and published it formally in 1809 in his work on the orbits of celestial bodies. He used the method to predict the location of the dwarf planet Ceres after it was lost behind the sun, successfully predicting where it would reappear. His formulation of least squares is the mathematical foundation for all linear regression. Independently, Adrien-Marie Legendre also published the method in 1805, leading to a famous priority dispute. Gauss is said to have discovered the least-squares method as a teenager, long before publishing it. He is also famous for constructing a 17-sided regular polygon (heptadecagon) using only a compass and straightedge — a result that had eluded mathematicians for 2000 years.

  • Correlation Coefficient — The correlation coefficient r is a direct input to the least-squares slope formula, and r² measures how well the regression line fits the data.
  • Residuals and Residual Plots — Residuals are the differences between observed and predicted values; analysing them is essential for verifying that a linear regression model is appropriate.
  • Scatter Plots — Regression lines are plotted on scatter plots; identifying a linear pattern in a scatter plot is the first step before fitting a regression model.
  • Coefficient of Determination (r²) — r² measures the proportion of variability in the response variable explained by the regression model, and is the primary measure of fit quality.
  • Extrapolation and Prediction — Using a regression line to predict y for values of x outside the data range (extrapolation) is a common misuse of linear regression that students must recognise and avoid.