How can one perform linear regression by hand?

Linear regression is a statistical technique used to establish a relationship between two variables by fitting a straight line through a set of data points. It can be performed by hand using a series of calculations and equations. First, the data points are plotted on a graph and a line is drawn to visually represent the relationship between the variables. Next, the slope and intercept of the line are determined using the least squares method. This involves calculating the sum of the squared distances between the data points and the line, and then finding the values that minimize this sum. Once the slope and intercept are determined, they can be used to create an equation for the line of best fit. This equation can then be used to make predictions and analyze the relationship between the variables. By performing these calculations by hand, one can gain a deeper understanding of the linear regression process and its results.

Perform Linear Regression by Hand


Simple linear regression is a statistical method you can use to quantify the relationship between a predictor variable and a response variable.

This tutorial explains how to perform simple linear regression by hand.

Example: Simple Linear Regression by Hand

Suppose we have the following dataset that shows the weight and height of seven individuals:

Simple linear regression dataset

Use the following steps to fit a linear regression model to this dataset, using weight as the predictor variable and height as the response variable.

Step 1: Calculate X*Y, X2, and Y2

Linear regression by hand calculation

Step 2: Calculate ΣX, ΣY, ΣX*Y, ΣX2, and ΣY2

Linear regression by hand

Step 3: Calculate b0

The formula to calculate bis: [(ΣY)(ΣX2) – (ΣX)(ΣXY)]  /  [n(ΣX2) – (ΣX)2]

In this example, b= [(477)(222755) – (1237)(85125)]  /  [7(222755) – (1237)2] = 32.783

Step 4: Calculate b1

The formula to calculate bis: [n(ΣXY) – (ΣX)(ΣY)]  /  [n(ΣX2) – (ΣX)2]

In this example, b= [7(85125) – (1237)(477)]  /  [7(222755) – (1237)2] = 0.2001

Step 5: Place band b1 in the estimated linear regression equation.

In our example, it is ŷ = 0.32783 + (0.2001)*x

How to Interpret a Simple Linear Regression Equation

Here is how to interpret this estimated linear regression equation: ŷ = 32.783 + 0.2001x

b0 = 32.7830. When weight is zero pounds, the predicted height is 32.783 inches. Sometimes the value for b0 can be useful to know, but in this example it doesn’t actually make sense to interpret b0 since a person can’t weigh zero pounds.

b= 0.2001. A one pound increase in weight is associated with a 0.2001 inch increase in height.

Simple Linear Regression Calculator

We can double check our results by inputting our data into the simple linear regression calculator:

This equation matches the one that we calculated by hand.

x