Linear Regression Notes
These Linear Regression Notes explain how to find the straight line that best fits a set of points, with the working shown line by line. The method finds the mean of x and of y, works out how far each value is from its mean, and uses the totals of those differences to get the slope. The intercept then makes the line pass through the point of the two means. The answer is the line of best fit, drawn through the points on a scatter plot, and the same pattern works for any paired data.
Step-by-step method
- Set up the problem.
- Write the formulas.
- Find the mean of the x values and of the y values.
- Subtract the means from each value.
- Multiply and square the differences.
- Add up the two new columns.
- Find the slope b.
- Find the intercept a.
- Write the equation of the line.
- Draw the line through the points.
Formula: Line of Best Fit Formula
This is the equation of the line. a is where it crosses the y-axis and b is its slope.
Formula: Slope Formula
This formula gives the slope b. Divide the total of the products by the total of the squared x differences.
Formula: Intercept Formula
This formula gives the intercept a. Take b times the mean of x away from the mean of y.
Useful Tips to Remember
The regression line \(\hat{y} = a + bx\) predicts \(y\) from \(x\), where \(b\) is the slope and \(a\) is the intercept. Predictions are only reliable inside the range of the data, so extending the line far beyond it is risky. The line always passes through the point \((\bar{x}, \bar{y})\). Check the correlation coefficient to see how well the line fits.
Required knowledge
- How to find the mean, covered in the Mean Calculator.
- How to add up a column of numbers, covered in the Sum Calculator.
Where Is Linear Regression Used?
Linear regression fits the straight line \(\hat{y} = a + bx\) that best matches a set of data points, so one quantity can be predicted from another. Businesses use it to forecast sales from advertising spend, scientists use it to find trends in experimental results, and economists use it to study how prices affect demand. The slope shows how much \(y\) changes for each unit of \(x\), which is often the most useful number in the analysis. It is also one of the simplest and most widely used models in machine learning.
- Forecasting sales from advertising spend
- Predicting house prices from their size
- Finding trends in scientific experiments
- Estimating how demand changes with price
- Building simple prediction models in machine learning
Linear Regression Practice Problems
Example 1 fits a line with a positive slope, and Example 2 fits one with a negative slope. Examples 3 and 4 give you two more problems of the same kind to try. Try finding the slope and intercept yourself before checking each step.
The worked examples below go through the same pattern from start to finish, so you can compare every step with your own working. Try each problem on paper first, then open the example and check your working one step at a time, so you can see exactly which step went wrong if your answer does not match. Use them to check your answers and to understand why each step works.
See Example 1 Hide Example 1
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formulas.
- Find the mean of the x values and of the y values.
- Subtract the means from each value.
- Multiply and square the differences.
- Add up the two new columns.
- Find the slope b.
- Find the intercept a.
- Write the equation of the line.
- Draw the line through the points.
Formula
Formula: Line of Best Fit Formula
This is the equation of the line. a is where it crosses the y-axis and b is its slope.
Formula: Slope Formula
This formula gives the slope b. Divide the total of the products by the total of the squared x differences.
Formula: Intercept Formula
This formula gives the intercept a. Take b times the mean of x away from the mean of y.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the straight line that fits the points \((x, y)\) best.
Step 2
Step 2 - Write the formulas.
In this problem: The line is \(\hat{y} = a + bx\). The slope b compares how x and y move together with how much x spreads out, and the intercept a makes the line pass through \((\bar{x}, \bar{y})\).
Step 3
Step 3 - Find the mean of the x values and of the y values.
In this problem: Both means are needed before the differences can be found.
Step 3a
Step 3a - Find the mean of the x values.
In this problem: The mean of the x values is \(\bar{x} = 3\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(1,\; 2,\; 3,\; 4,\; 5\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(1 + 2 + 3 + 4 + 5 = 15\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(1,\; 2,\; 3,\; 4,\; 5\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(1 + 2 + 3 + 4 + 5 = 15\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(5\) at the last value, so \(n = 5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(1,\; 2,\; 3,\; 4,\; 5\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(5\) at the last value, so \(n = 5\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(15\) and \(n\) with \(5\) gives \(\bar{x} = \frac{15}{5}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(15 \div 5 = 3\).
Final Answer
Step 3b
Step 3b - Find the mean of the y values.
In this problem: The mean of the y values is \(\bar{y} = 4\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(2,\; 4,\; 5,\; 4,\; 5\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(2 + 4 + 5 + 4 + 5 = 20\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(2,\; 4,\; 5,\; 4,\; 5\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(2 + 4 + 5 + 4 + 5 = 20\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(5\) at the last value, so \(n = 5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(2,\; 4,\; 5,\; 4,\; 5\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(5\) at the last value, so \(n = 5\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(20\) and \(n\) with \(5\) gives \(\bar{x} = \frac{20}{5}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(20 \div 5 = 4\).
Final Answer
Step 4
Step 4 - Subtract the means from each value.
In this problem: Taking \(\bar{x} = 3\) from each x value and \(\bar{y} = 4\) from each y value gives the differences.
Step 5
Step 5 - Multiply and square the differences.
In this problem: Each row's two differences are multiplied together, and each difference is squared.
Step 6
Step 6 - Add up the two new columns.
In this problem: The slope formula needs the total of the products and the total of the squared x differences.
Step 6a
Step 6a - Add the products.
In this problem: Adding the column gives \(4 + 0 + 0 + 0 + 2 = 6\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(4,\; 0,\; 0,\; 0,\; 2\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(4 + 0 + 0 + 0 + 2 = 6\).
Final Answer
Step 6b
Step 6b - Add the squared x differences.
In this problem: Adding the column gives \(4 + 1 + 0 + 1 + 4 = 10\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(4,\; 1,\; 0,\; 1,\; 4\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(4 + 1 + 0 + 1 + 4 = 10\).
Final Answer
Step 7
Step 7 - Find the slope b.
In this problem: Replacing the two totals in the slope formula and dividing gives \(b = 0.6\).
Step 8
Step 8 - Find the intercept a.
In this problem: Replacing \(\bar{y}\), \(b\) and \(\bar{x}\) in the intercept formula gives \(a = 2.2\).
Step 9
Step 9 - Write the equation of the line.
In this problem: Putting \(a\) and \(b\) into \(\hat{y} = a + bx\) gives the line of best fit.
Step 10
Step 10 - Draw the line through the points.
In this problem: The orange line is \(\hat{y} = 2.2 + 0.6x\). It passes as close as it can to every point.
Final Answer
See Example 2 Hide Example 2
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formulas.
- Find the mean of the x values and of the y values.
- Subtract the means from each value.
- Multiply and square the differences.
- Add up the two new columns.
- Find the slope b.
- Find the intercept a.
- Write the equation of the line.
- Draw the line through the points.
Formula
Formula: Line of Best Fit Formula
This is the equation of the line. a is where it crosses the y-axis and b is its slope.
Formula: Slope Formula
This formula gives the slope b. Divide the total of the products by the total of the squared x differences.
Formula: Intercept Formula
This formula gives the intercept a. Take b times the mean of x away from the mean of y.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the straight line that fits the points \((x, y)\) best.
Step 2
Step 2 - Write the formulas.
In this problem: The line is \(\hat{y} = a + bx\). The slope b compares how x and y move together with how much x spreads out, and the intercept a makes the line pass through \((\bar{x}, \bar{y})\).
Step 3
Step 3 - Find the mean of the x values and of the y values.
In this problem: Both means are needed before the differences can be found.
Step 3a
Step 3a - Find the mean of the x values.
In this problem: The mean of the x values is \(\bar{x} = 2.5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(1,\; 2,\; 3,\; 4\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(1 + 2 + 3 + 4 = 10\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(1,\; 2,\; 3,\; 4\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(1 + 2 + 3 + 4 = 10\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(4\) at the last value, so \(n = 4\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(1,\; 2,\; 3,\; 4\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(4\) at the last value, so \(n = 4\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(10\) and \(n\) with \(4\) gives \(\bar{x} = \frac{10}{4}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(10 \div 4 = 2.5\).
Final Answer
Step 3b
Step 3b - Find the mean of the y values.
In this problem: The mean of the y values is \(\bar{y} = 5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(8,\; 6,\; 5,\; 1\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(8 + 6 + 5 + 1 = 20\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(8,\; 6,\; 5,\; 1\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(8 + 6 + 5 + 1 = 20\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(4\) at the last value, so \(n = 4\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(8,\; 6,\; 5,\; 1\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(4\) at the last value, so \(n = 4\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(20\) and \(n\) with \(4\) gives \(\bar{x} = \frac{20}{4}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(20 \div 4 = 5\).
Final Answer
Step 4
Step 4 - Subtract the means from each value.
In this problem: Taking \(\bar{x} = 2.5\) from each x value and \(\bar{y} = 5\) from each y value gives the differences.
Step 5
Step 5 - Multiply and square the differences.
In this problem: Each row's two differences are multiplied together, and each difference is squared.
Step 6
Step 6 - Add up the two new columns.
In this problem: The slope formula needs the total of the products and the total of the squared x differences.
Step 6a
Step 6a - Add the products.
In this problem: Adding the column gives \(-4.5 + \left(-0.5\right) + 0 + \left(-6\right) = -11\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(-4.5,\; -0.5,\; 0,\; -6\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(-4.5 - 0.5 + 0 - 6 = -11\).
Final Answer
Step 6b
Step 6b - Add the squared x differences.
In this problem: Adding the column gives \(2.25 + 0.25 + 0.25 + 2.25 = 5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(2.25,\; 0.25,\; 0.25,\; 2.25\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(2.25 + 0.25 + 0.25 + 2.25 = 5\).
Final Answer
Step 7
Step 7 - Find the slope b.
In this problem: Replacing the two totals in the slope formula and dividing gives \(b = -2.2\).
Step 8
Step 8 - Find the intercept a.
In this problem: Replacing \(\bar{y}\), \(b\) and \(\bar{x}\) in the intercept formula gives \(a = 10.5\).
Step 9
Step 9 - Write the equation of the line.
In this problem: Putting \(a\) and \(b\) into \(\hat{y} = a + bx\) gives the line of best fit.
Step 10
Step 10 - Draw the line through the points.
In this problem: The orange line is \(\hat{y} = 10.5 - 2.2x\). It passes as close as it can to every point.
Final Answer
See Example 3 Hide Example 3
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formulas.
- Find the mean of the x values and of the y values.
- Subtract the means from each value.
- Multiply and square the differences.
- Add up the two new columns.
- Find the slope b.
- Find the intercept a.
- Write the equation of the line.
- Draw the line through the points.
Formula
Formula: Line of Best Fit Formula
This is the equation of the line. a is where it crosses the y-axis and b is its slope.
Formula: Slope Formula
This formula gives the slope b. Divide the total of the products by the total of the squared x differences.
Formula: Intercept Formula
This formula gives the intercept a. Take b times the mean of x away from the mean of y.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the straight line that fits the points \((x, y)\) best.
Step 2
Step 2 - Write the formulas.
In this problem: The line is \(\hat{y} = a + bx\). The slope b compares how x and y move together with how much x spreads out, and the intercept a makes the line pass through \((\bar{x}, \bar{y})\).
Step 3
Step 3 - Find the mean of the x values and of the y values.
In this problem: Both means are needed before the differences can be found.
Step 3a
Step 3a - Find the mean of the x values.
In this problem: The mean of the x values is \(\bar{x} = 25\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(10,\; 20,\; 30,\; 40\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(10 + 20 + 30 + 40 = 100\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(10,\; 20,\; 30,\; 40\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(10 + 20 + 30 + 40 = 100\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(4\) at the last value, so \(n = 4\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(10,\; 20,\; 30,\; 40\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(4\) at the last value, so \(n = 4\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(100\) and \(n\) with \(4\) gives \(\bar{x} = \frac{100}{4}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(100 \div 4 = 25\).
Final Answer
Step 3b
Step 3b - Find the mean of the y values.
In this problem: The mean of the y values is \(\bar{y} = 26\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(15,\; 18,\; 30,\; 41\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(15 + 18 + 30 + 41 = 104\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(15,\; 18,\; 30,\; 41\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(15 + 18 + 30 + 41 = 104\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(4\) at the last value, so \(n = 4\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(15,\; 18,\; 30,\; 41\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(4\) at the last value, so \(n = 4\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(104\) and \(n\) with \(4\) gives \(\bar{x} = \frac{104}{4}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(104 \div 4 = 26\).
Final Answer
Step 4
Step 4 - Subtract the means from each value.
In this problem: Taking \(\bar{x} = 25\) from each x value and \(\bar{y} = 26\) from each y value gives the differences.
Step 5
Step 5 - Multiply and square the differences.
In this problem: Each row's two differences are multiplied together, and each difference is squared.
Step 6
Step 6 - Add up the two new columns.
In this problem: The slope formula needs the total of the products and the total of the squared x differences.
Step 6a
Step 6a - Add the products.
In this problem: Adding the column gives \(165 + 40 + 20 + 225 = 450\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(165,\; 40,\; 20,\; 225\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(165 + 40 + 20 + 225 = 450\).
Final Answer
Step 6b
Step 6b - Add the squared x differences.
In this problem: Adding the column gives \(225 + 25 + 25 + 225 = 500\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(4\) values \(225,\; 25,\; 25,\; 225\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(225 + 25 + 25 + 225 = 500\).
Final Answer
Step 7
Step 7 - Find the slope b.
In this problem: Replacing the two totals in the slope formula and dividing gives \(b = 0.9\).
Step 8
Step 8 - Find the intercept a.
In this problem: Replacing \(\bar{y}\), \(b\) and \(\bar{x}\) in the intercept formula gives \(a = 3.5\).
Step 9
Step 9 - Write the equation of the line.
In this problem: Putting \(a\) and \(b\) into \(\hat{y} = a + bx\) gives the line of best fit.
Step 10
Step 10 - Draw the line through the points.
In this problem: The orange line is \(\hat{y} = 3.5 + 0.9x\). It passes as close as it can to every point.
Final Answer
See Example 4 Hide Example 4
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formulas.
- Find the mean of the x values and of the y values.
- Subtract the means from each value.
- Multiply and square the differences.
- Add up the two new columns.
- Find the slope b.
- Find the intercept a.
- Write the equation of the line.
- Draw the line through the points.
Formula
Formula: Line of Best Fit Formula
This is the equation of the line. a is where it crosses the y-axis and b is its slope.
Formula: Slope Formula
This formula gives the slope b. Divide the total of the products by the total of the squared x differences.
Formula: Intercept Formula
This formula gives the intercept a. Take b times the mean of x away from the mean of y.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the straight line that fits the points \((x, y)\) best.
Step 2
Step 2 - Write the formulas.
In this problem: The line is \(\hat{y} = a + bx\). The slope b compares how x and y move together with how much x spreads out, and the intercept a makes the line pass through \((\bar{x}, \bar{y})\).
Step 3
Step 3 - Find the mean of the x values and of the y values.
In this problem: Both means are needed before the differences can be found.
Step 3a
Step 3a - Find the mean of the x values.
In this problem: The mean of the x values is \(\bar{x} = 6\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(2,\; 4,\; 6,\; 8,\; 10\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(2 + 4 + 6 + 8 + 10 = 30\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(2,\; 4,\; 6,\; 8,\; 10\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(2 + 4 + 6 + 8 + 10 = 30\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(5\) at the last value, so \(n = 5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(2,\; 4,\; 6,\; 8,\; 10\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(5\) at the last value, so \(n = 5\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(30\) and \(n\) with \(5\) gives \(\bar{x} = \frac{30}{5}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(30 \div 5 = 6\).
Final Answer
Step 3b
Step 3b - Find the mean of the y values.
In this problem: The mean of the y values is \(\bar{y} = 8\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Find the total of the values and how many values there are.
- Substitute the total and the count into the formula.
- Divide to get the mean.
Step 1
Step 1 - Set up the problem.
In this problem: We are finding the mean of the values \(3,\; 7,\; 5,\; 11,\; 14\).
Step 2
Step 2 - Write the formula.
In this problem: The mean shares the total equally between the values, so the total is divided by how many there are.
Step 3
Step 3 - Find the total of the values and how many values there are.
In this problem: The formula needs the total \(\Sigma x\) of the values and their count \(n\).
Step 3a
Step 3a - Add the values together.
In this problem: Adding the values in order gives \(3 + 7 + 5 + 11 + 14 = 40\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(3,\; 7,\; 5,\; 11,\; 14\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(3 + 7 + 5 + 11 + 14 = 40\).
Final Answer
Step 3b
Step 3b - Count the values.
In this problem: Counting along the list reaches \(5\) at the last value, so \(n = 5\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Count the values in the list.
Step 1
Step 1 - Set up the problem.
In this problem: We are counting how many values are in the list \(3,\; 7,\; 5,\; 11,\; 14\).
Step 2
Step 2 - Write the formula.
In this problem: The count is simply how many values the list holds, written as n.
Step 3
Step 3 - Count the values in the list.
In this problem: Counting along the list from left to right reaches \(5\) at the last value, so \(n = 5\).
Final Answer
Step 4
Step 4 - Substitute the total and the count into the formula.
In this problem: Replacing \(\Sigma x\) with \(40\) and \(n\) with \(5\) gives \(\bar{x} = \frac{40}{5}\).
Step 5
Step 5 - Divide to get the mean.
In this problem: Dividing the total by the count gives \(40 \div 5 = 8\).
Final Answer
Step 4
Step 4 - Subtract the means from each value.
In this problem: Taking \(\bar{x} = 6\) from each x value and \(\bar{y} = 8\) from each y value gives the differences.
Step 5
Step 5 - Multiply and square the differences.
In this problem: Each row's two differences are multiplied together, and each difference is squared.
Step 6
Step 6 - Add up the two new columns.
In this problem: The slope formula needs the total of the products and the total of the squared x differences.
Step 6a
Step 6a - Add the products.
In this problem: Adding the column gives \(20 + 2 + 0 + 6 + 24 = 52\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(20,\; 2,\; 0,\; 6,\; 24\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(20 + 2 + 0 + 6 + 24 = 52\).
Final Answer
Step 6b
Step 6b - Add the squared x differences.
In this problem: Adding the column gives \(16 + 4 + 0 + 4 + 16 = 40\).
Problem
Approach
Step-by-step method
- Set up the problem.
- Write the formula.
- Add the values together to get the total.
Step 1
Step 1 - Set up the problem.
In this problem: We are adding the \(5\) values \(16,\; 4,\; 0,\; 4,\; 16\) together.
Step 2
Step 2 - Write the formula.
In this problem: The total is what every value adds up to, written as the sum of all the values.
Step 3
Step 3 - Add the values together to get the total.
In this problem: Adding them in order gives \(16 + 4 + 0 + 4 + 16 = 40\).
Final Answer
Step 7
Step 7 - Find the slope b.
In this problem: Replacing the two totals in the slope formula and dividing gives \(b = 1.3\).
Step 8
Step 8 - Find the intercept a.
In this problem: Replacing \(\bar{y}\), \(b\) and \(\bar{x}\) in the intercept formula gives \(a = 0.2\).
Step 9
Step 9 - Write the equation of the line.
In this problem: Putting \(a\) and \(b\) into \(\hat{y} = a + bx\) gives the line of best fit.
Step 10
Step 10 - Draw the line through the points.
In this problem: The orange line is \(\hat{y} = 0.2 + 1.3x\). It passes as close as it can to every point.
Final Answer
Calculator and Practice Mode
Want to check your own working? The Linear Regression Calculator solves any problem you type in and shows every step, so you can compare it line by line with your answer and find exactly where a mistake crept in. When you are ready to test yourself, Linear Regression Practice gives you a new problem at Easy, Medium or Hard level, checks your answer and shows the full working whenever you get one wrong. Practice Mode is available on the Plus and Pro plans.