Statistics Tool

Linear Regression Calculator - Line of Best Fit Calculator & Least Squares Calculator

Free linear regression calculator & line of best fit calculator. Calculate the regression line using least squares method. Get slope, intercept, correlation coefficient (r), R-squared (R²), and step-by-step solutions with statistical analysis.

Last updated: October 30, 2025

Calculate y = mx + b using least squares method
Correlation coefficient (r) and R-squared (R²)
Step-by-step solutions with complete calculations

Need a custom statistics calculator for your educational platform? Get a Quote

Linear Regression Calculator
Calculate the line of best fit using least squares method. Enter x and y values to get the regression equation y = mx + b.

Enter x values separated by commas

Enter y values separated by commas (must match number of x values)

Regression Equation

y = 0.6000x + 2.2000

Slope (m)

0.6000

Y-Intercept (b)

2.2000

Correlation (r)

0.7746

R² (R-squared)

0.6000

Interpretation:

The linear regression equation is y = 0.6000x + 2.2000. The slope is 0.6000, meaning for each unit increase in x, y changes by 0.6000. The correlation coefficient is 0.7746, indicating a strong positive relationship. R² = 0.6000 means that 60.0% of the variance in y can be explained by x.

Step-by-Step Solution

  1. Step 1: Given 5 data points
  2. X values: 1, 2, 3, 4, 5
  3. Y values: 2, 4, 5, 4, 5
  4. Step 2: Calculate sums
  5. Σx = 15.0000
  6. Σy = 20.0000
  7. Σxy = 66.0000
  8. Σx² = 55.0000
  9. Σy² = 86.0000
  10. Step 3: Calculate means
  11. x̄ = Σx / n = 15.0000 / 5 = 3.0000
  12. ȳ = Σy / n = 20.0000 / 5 = 4.0000
  13. Step 4: Calculate slope (m)
  14. m = (n·Σxy - Σx·Σy) / (n·Σx² - (Σx)²)
  15. m = (5·66.0000 - 15.0000·20.0000) / (5·55.0000 - 225.0000)
  16. m = 30.0000 / 50.0000
  17. m = 0.6000
  18. Step 5: Calculate y-intercept (b)
  19. b = ȳ - m·x̄
  20. b = 4.0000 - 0.6000·3.0000
  21. b = 2.2000
  22. Step 6: Calculate correlation coefficient (r)
  23. r = Σ((x - x̄)(y - ȳ)) / √(Σ(x - x̄)² · Σ(y - ȳ)²)
  24. r = 0.7746
  25. Step 7: Calculate R² (coefficient of determination)
  26. R² = 1 - (SS_residual / SS_total)
  27. R² = 1 - (2.4000 / 6.0000)
  28. R² = 0.6000

Linear Regression Calculator Features

Least Squares Method
Find the best-fitting line by minimizing squared residuals

Method

Minimizes Σ(yᵢ - ŷᵢ)²

Standard method for regression analysis

Slope & Y-Intercept
Calculate m and b in equation y = mx + b

Formula

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

Complete calculation with all steps

Correlation Coefficient
Calculate r to measure relationship strength

Range

r ∈ [-1, 1]

Measures linear relationship strength

R-Squared (R²)
Calculate coefficient of determination

Interpretation

% variance explained

Goodness of fit measure

Step-by-Step Solutions
Detailed explanations for each calculation step

Includes

All intermediate calculations

Learn the regression process

Statistical Analysis
Complete regression analysis and interpretation

Provides

Full statistical summary

Interpretation of results

Quick Example Result

X: 1, 2, 3, 4, 5 | Y: 2, 4, 5, 4, 5

Equation

y = 0.6x + 2.2

0.85

How the Linear Regression Calculator Works

Our linear regression calculator uses the least squares method to find the best-fitting straight line through your data points. The method minimizes the sum of squared vertical distances (residuals) between observed values and the regression line. This provides optimal slope and intercept that best describe the linear relationship in your data.

Least Squares Formulas

Slope (m):
m = (n·Σxy - Σx·Σy) / (n·Σx² - (Σx)²)
Y-Intercept (b):
b = ȳ - m·x̄
Correlation (r):
r = Σ((x - x̄)(y - ȳ)) / √(Σ(x - x̄)² · Σ(y - ȳ)²)
R-Squared (R²):
R² = 1 - (SS_residual / SS_total)

Where n is the number of data points, Σ represents summation, x̄ and ȳ are means, and SS represents sum of squares.

Mathematical Foundation

Linear regression is based on minimizing the sum of squared residuals (errors). The residuals are the vertical distances between each data point and the regression line. By finding the line that minimizes Σ(yᵢ - ŷᵢ)², we get the best linear approximation of the relationship between x and y. This method is optimal under the assumptions of normally distributed errors.

  • Least squares minimizes the sum of squared vertical distances (residuals)
  • The regression line always passes through the point (x̄, ȳ)
  • Slope and intercept are calculated to minimize prediction errors
  • R² = r² (coefficient of determination equals correlation squared)
  • The method assumes a linear relationship exists in the data
  • Residuals should be normally distributed and independent for best results

Interpreting Results

  • Slope (m): Rate of change - for each 1-unit increase in x, y changes by m units
  • Intercept (b): Predicted y-value when x = 0 (if meaningful)
  • Correlation (r): |r| > 0.7 = strong, 0.5-0.7 = moderate, < 0.5 = weak
  • R²: R² > 0.7 = good fit, 0.5-0.7 = moderate, < 0.5 = poor fit
  • Positive r: As x increases, y tends to increase
  • Negative r: As x increases, y tends to decrease

Applications of Linear Regression

Linear regression is one of the most widely used statistical methods:

  • Economics: Demand forecasting, price modeling, economic trends
  • Science: Experimental data analysis, calibration curves, dose-response relationships
  • Business: Sales prediction, marketing ROI, performance metrics
  • Healthcare: Treatment effectiveness, risk factors, clinical studies
  • Engineering: Performance modeling, quality control, process optimization
  • Social Sciences: Behavior analysis, survey research, policy evaluation

Sources & References

  • Introduction to Statistical Learning - James, Witten, Hastie, Tibshirani (2nd Edition)Comprehensive coverage of linear regression and statistical learning methods
  • Applied Linear Statistical Models - Kutner, Nachtsheim, Neter, Li (5th Edition)In-depth treatment of regression analysis and modeling techniques
  • Khan Academy - Linear Regression and CorrelationInteractive lessons on regression analysis and correlation

Linear Regression Calculator Examples

Example: Calculate Linear Regression
Find the line of best fit for data points: (1,2), (2,4), (3,5), (4,4), (5,5)

Given Data:

  • X values: 1, 2, 3, 4, 5
  • Y values: 2, 4, 5, 4, 5
  • n = 5 data points

Step-by-Step Solution:

  1. Calculate sums: Σx, Σy, Σxy, Σx²
  2. Calculate means: x̄ = 3, ȳ = 4
  3. Calculate slope: m = 0.6
  4. Calculate intercept: b = 2.2
  5. Equation: y = 0.6x + 2.2
  6. Calculate r and R²

Result: y = 0.6x + 2.2

The line of best fit with R² ≈ 0.85, indicating a strong linear relationship between x and y.

Perfect Correlation

If all points lie on a line:

r = ±1, R² = 1

Perfect linear relationship

No Correlation

If points are randomly scattered:

r ≈ 0, R² ≈ 0

No linear relationship

Frequently Asked Questions

Found This Calculator Helpful?

Share it with others who need help with linear regression analysis

Share This Calculator
Help others discover this useful tool

Suggested hashtags: #Statistics #LinearRegression #Regression #Calculator #DataAnalysis

Related Calculators

Regression Equation Calculator
Calculate linear and quadratic regression equations with correlation analysis and R-squared values.
Use Calculator
Line of Best Fit Calculator
Calculate linear regression with slope, y-intercept, R-squared, and correlation coefficient analysis.
Use Calculator
Coefficient of Determination Calculator
Calculate R² (R-squared) for regression analysis with SST, SSR, SSE and goodness of fit assessment.
Use Calculator
Covariance Calculator
Calculate covariance between two variables with correlation analysis.
Use Calculator
Mean, Median, Mode Calculator
Calculate mean, median, mode, and other statistical measures with step-by-step solutions.
Use Calculator
Exponential Regression Calculator
Fit exponential model y = a × e^(bx) to data with growth/decay analysis and R² goodness of fit.
Use Calculator
Linear Regression Calculator - Calculate Line of Best Fit Online