Linear Regression Calculator

Data Visualization

Linear Regression Calculator

What is Linear Regression?

Linear regression is a statistical method used to model the relationship between two variables by fitting a linear equation to observed data. One variable is considered to be an explanatory variable (X), and the other is considered to be a dependent variable (Y).

Formulas and Their Meanings

1. Slope (B): \[B = \frac{n\sum xy - \sum x \sum y}{n\sum x^2 - (\sum x)^2}\] Where n is the number of data points, x and y are the variables.

2. Intercept (A): \[A = \bar{y} - B\bar{x}\] Where \(\bar{x}\) and \(\bar{y}\) are the means of x and y respectively.

3. Regression Equation: \[Y = BX + A\] This is the final equation that describes the linear relationship between X and Y.

Calculation Steps

  1. Calculate the sums: \(\sum x\), \(\sum y\), \(\sum xy\), and \(\sum x^2\)
  2. Calculate the means: \(\bar{x}\) and \(\bar{y}\)
  3. Use the formula to calculate the slope (B)
  4. Use the formula to calculate the intercept (A)
  5. Form the regression equation: Y = BX + A

Example Calculation

Let's calculate for the dataset: X = (1, 2, 3, 4, 5), Y = (2, 4, 5, 4, 5)

  1. Calculate sums:
    • \(\sum x = 1 + 2 + 3 + 4 + 5 = 15\)
    • \(\sum y = 2 + 4 + 5 + 4 + 5 = 20\)
    • \(\sum xy = 1(2) + 2(4) + 3(5) + 4(4) + 5(5) = 70\)
    • \(\sum x^2 = 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55\)
  2. Calculate means:
    • \(\bar{x} = 15 / 5 = 3\)
    • \(\bar{y} = 20 / 5 = 4\)
  3. Calculate slope: \[B = \frac{5(70) - 15(20)}{5(55) - 15^2} = 0.7\]
  4. Calculate intercept: \[A = 4 - 0.7(3) = 1.9\]
  5. Regression equation: \[Y = 0.7X + 1.9\]

Visual Representation

Y = 0.7X + 1.9

This scatter plot represents the example dataset. The red line indicates the regression line Y = 0.7X + 1.9, showing the best fit for the data points.