Linear Regression Calculator
Linear Regression Calculator calculates the equation of the line that is the best fit for the given data points. Linear regression models a linear relationship between the input variable x and the output variable y.
What is Linear Regression Calculator?
Linear Regression Calculator is an online tool that helps to determine the equation of the best-fitted line for the given data set using the least-squares method. To use this linear regression calculator, enter values inside the brackets, separated by commas in the given input boxes.
Linear Regression Calculator
How to Use Linear Regression Calculator?
Please follow the steps below to find the equation of the regression line using the online linear regression calculator:
- Step 1: Go to Cuemath’s online linear regression calculator.
- Step 2: Enter the numbers, separated by commas, within brackets in the given input boxes of the linear regression calculator.
- Step 3: Click on the "Solve" button to calculate the equation of the best-fitted line for the given data points.
- Step 4: Click on the "Reset" button to clear the fields and enter new values.
How Does Linear Regression Calculator Work?
We use the least-squares method to determine the equation of the best-fitted line for the given data points. Such a line is known as the regression line. The main purpose of the least-squares method is to reduce the sum of the squares of the errors. This implies that we are trying to reduce the difference between the observed response and the response that is predicted by the regression line. Thus, a good model will be one that has the least residual or error. The equation of the linear regression line is of the form y = mx + b. Here, m is the slope and b is the y-intercept. The steps to perform linear regression are given below:
- Determine the value of the slope "m".
- Determine the value of the y-intercept "b".
- Substitute these values in the equation y = mx + b. This will be the equation of the regression line.
The formulas to calculate "m" and "b" are given as follows:
m = \(\frac{n\sum xy - \sum x\sum y}{n\sum (x^{2}) - (\sum x)^{2}}\)
b = \(\frac{\sum y - m\sum x}{n}\)
n = sample size.
∑x = sum of all the values in data set x.
∑y = sum of all the values in data set y.
∑xy = sum of products of the corresponding values in data sets x and y,
∑x2 = sum of squares of values in data set x.
Solved Examples on Linear Regression Calculator
Example 1:
Calculate the equation of the regression line for data sets x = {1, 5, 7, 9} and y = {2, 5, 7, 9}. Verify it using the linear regression calculator.
Solution:
Given: x = {1, 5, 7, 9} and y = {2, 5, 7, 9}
n = 4
Σx = 1 + 5 + 7 + 9 = 22
Σy = 2 + 5 + 7 + 9 = 23
Σxy = 2 + 25 + 49 + 81 = 157
Σx2 = 1 + 25 + 49 + 81 = 156
m = [n(Σxy) - (Σx)(Σy)] / [n(Σx2) - (Σx)2]
= [4(157) - (22)(23) / [4(156) - (22)2]
= 0.8714
b = [(Σy) - m(Σx)] / n
= [23 - 0.8714 (22)] / 4
= 0.957
y = mx + b
y = 0.8714x + 0.957
Example 2:
Calculate the equation of the regression line for data sets x = {-1, -2.5, 0, 3.5, 4} and y = {-8, 10, 12.7, -3.5, 1}. Verify it using the linear regression calculator.
Solution:
Given: x = {-1, -2.5, 0, 3.5, 4} and y = {-8, 10, 12.7, -3.5, 1}
n = 5
Σx = -1 + (-2.5) + 0 + 3.5 + 4 = 4
Σy = -8 + 10 + 12.7 - 3.5 + 1 = 12.2
Σxy = 8 - 25 + 0 - 12.25 + 4 = -25.25
Σx2 = 1 + 6.25 + 0 + 12.25 + 16 = 35.5
m = [n(Σxy) - (Σx)(Σy)] / [n(Σx2) - (Σx)2]
= [5(-25.25) - (4)(12.2) / [5(35.5) - (4)2]
= -1.839
b = [(Σy) - m(Σx)] / n
= [12.2 - (-1.839)(4)] / 5
= 3.3071
y = mx + b
y = -1.0839x + 3.3071
Now, try the linear regression calculator and find the regression line equation for:
- x = {5.2, -1.7, -3.2, 6, 2.7, 2} and y = {-10.3, 7.2, -6.3, 12.4, 5, 13}
- x = {1, -2, 4, -7, 9} and y = {6.2, -7.5, -5, -2.2, 14}
☛ Related Articles:
☛ Math Calculators:
visual curriculum