Linear Regression Calculator

Calculate slope, intercept, correlation coefficient, and R-squared with step-by-step solutions

Data Input

Results

What is Linear Regression?

Linear regression is a statistical method used to model the relationship between a dependent variable (y) and one or more independent variables (x). It finds the best-fitting straight line through a set of data points and can be used for prediction and understanding relationships between variables.

Linear Regression Equation

The equation for simple linear regression is:

y = mx + b

Where:

  • y = Dependent variable (predicted value)
  • m = Slope (regression coefficient)
  • x = Independent variable
  • b = Y-intercept

Key Statistics

Slope (m):

m = (nΣxy - ΣxΣy) / (nΣx² - (Σx)²)

Measures the rate of change of y with respect to x

Intercept (b):

b = (Σy - mΣx) / n

The y-value when x = 0

Correlation (r):

r = (nΣxy - ΣxΣy) / √[(nΣx²-(Σx)²)(nΣy²-(Σy)²)]

Measures the strength and direction of the relationship

R-squared (R²):

R² = r²

Proportion of variance explained by the model

How to Use the Calculator

  1. Enter your x and y data points
  2. Click "Calculate" to get the regression equation
  3. View the slope, intercept, correlation, and R-squared
  4. Use the equation to make predictions
  5. View the step-by-step solution

Interpreting Results

  • Slope (m): Positive = positive relationship, Negative = negative relationship
  • Correlation (r): -1 to +1, where |r| > 0.7 indicates strong correlation
  • R-squared (R²): 0 to 1, higher values indicate better fit
  • Intercept (b): The predicted y-value when x = 0

Example Calculation

Sample Data:

x: [1, 2, 3, 4, 5]

y: [2, 4, 5, 4, 6]

Calculations:

  • Σx = 15, Σy = 21, Σxy = 73, Σx² = 55, Σy² = 97
  • n = 5
  • Slope = (5×73 - 15×21) / (5×55 - 15²) = 0.8
  • Intercept = (21 - 0.8×15) / 5 = 1.8
  • Equation: y = 0.8x + 1.8

Assumptions for Linear Regression

  • Linear relationship between variables
  • Independent observations
  • Normally distributed residuals
  • Homoscedasticity (constant variance)
  • No multicollinearity (for multiple regression)

Applications

  • Prediction: Forecasting future values
  • Trend Analysis: Understanding relationships between variables
  • Quality Control: Monitoring process performance
  • Market Research: Analyzing customer behavior
  • Scientific Research: Testing hypotheses about relationships