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
Need a custom statistics calculator for your educational platform? Get a Quote
Regression Equation
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
- Step 1: Given 5 data points
- X values: 1, 2, 3, 4, 5
- Y values: 2, 4, 5, 4, 5
- Step 2: Calculate sums
- Σx = 15.0000
- Σy = 20.0000
- Σxy = 66.0000
- Σx² = 55.0000
- Σy² = 86.0000
- Step 3: Calculate means
- x̄ = Σx / n = 15.0000 / 5 = 3.0000
- ȳ = Σy / n = 20.0000 / 5 = 4.0000
- Step 4: Calculate slope (m)
- m = (n·Σxy - Σx·Σy) / (n·Σx² - (Σx)²)
- m = (5·66.0000 - 15.0000·20.0000) / (5·55.0000 - 225.0000)
- m = 30.0000 / 50.0000
- m = 0.6000
- Step 5: Calculate y-intercept (b)
- b = ȳ - m·x̄
- b = 4.0000 - 0.6000·3.0000
- b = 2.2000
- Step 6: Calculate correlation coefficient (r)
- r = Σ((x - x̄)(y - ȳ)) / √(Σ(x - x̄)² · Σ(y - ȳ)²)
- r = 0.7746
- Step 7: Calculate R² (coefficient of determination)
- R² = 1 - (SS_residual / SS_total)
- R² = 1 - (2.4000 / 6.0000)
- R² = 0.6000
Linear Regression Calculator Features
Method
Minimizes Σ(yᵢ - ŷᵢ)²
Standard method for regression analysis
Formula
m = (n·Σxy - Σx·Σy) / (n·Σx² - (Σx)²)
Complete calculation with all steps
Range
r ∈ [-1, 1]
Measures linear relationship strength
Interpretation
% variance explained
Goodness of fit measure
Includes
All intermediate calculations
Learn the regression process
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
R²
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
m = (n·Σxy - Σx·Σy) / (n·Σx² - (Σx)²)b = ȳ - m·x̄r = Σ((x - x̄)(y - ȳ)) / √(Σ(x - x̄)² · Σ(y - ȳ)²)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
Need help with other statistical methods? Try our regression equation calculator or coefficient of determination calculator.
Get Custom Calculator for Your PlatformLinear Regression Calculator Examples
Given Data:
- X values: 1, 2, 3, 4, 5
- Y values: 2, 4, 5, 4, 5
- n = 5 data points
Step-by-Step Solution:
- Calculate sums: Σx, Σy, Σxy, Σx²
- Calculate means: x̄ = 3, ȳ = 4
- Calculate slope: m = 0.6
- Calculate intercept: b = 2.2
- Equation: y = 0.6x + 2.2
- 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
Suggested hashtags: #Statistics #LinearRegression #Regression #Calculator #DataAnalysis