How to calculate a linear regression line by hand
The linear regression line, , is calculated by minimizing the sum of squared vertical residuals between observed data and the line. This method applies when you have a set of bivariate numerical data and need to model the linear relationship without statistical software.
The setup
Define your data pairs as and count the number of pairs . Compute the five fundamental sums: , , , , and . Calculate the sample means and .
The steps
- Calculate the sums of squares for and : and . 2. Calculate the slope . 3. Calculate the y-intercept . 4. Write the final equation as .
Checking the result
Verify that the point lies exactly on your calculated line by testing if . Additionally, verify that the sign of your slope matches the sign of .
Common errors
Rounding intermediate calculations, especially the means or sums of squares, causes severe compounding errors in the final slope and intercept. Another common error is swapping the independent variable and dependent variable , which produces an entirely different regression line.
Worked example
Calculate the linear regression line for the following five data points: .
First, find . Compute the sums: . . . . Compute the means: . . Next, calculate the sums of squares: . . Calculate the slope: . Calculate the intercept: . The final regression line is .
FAQ
Run your own problem
References: OpenStax Introductory Statistics, Chapter 12: Linear Regression and Correlation · Moore, McCabe, Craig: Introduction to the Practice of Statistics
See also