Linear Regression Calculator - Best Fit Line & Prediction
Calculate linear regression slope, intercept, R-squared, correlation coefficient, and residual analysis. Statistics calculator for data science, research, trend analysis, and predictive modeling. Includes scatter plot data and confidence intervals.
Simple Linear Regression Formula
y = a + bxVariables:
- yDependent variable (response)Dependent variable (response)(e.g.: Exam score)
- xIndependent variable (predictor)Independent variable (predictor)(e.g.: Study hours)
- aIntercept (y value when x=0)Intercept (y value when x=0)(e.g.: 10)
- bSlope (change in y per unit x)Slope (change in y per unit x)(e.g.: 5)
- R²Coefficient of determination (0-1)Coefficient of determination (0-1)(e.g.: 0.85 = 85% of variance explained)
How to Use the KalkuLab Linear Regression Calculator
- 1
Enter Data
Input paired data points (x, y) — at least 3 points.
- 2
Calculate Regression
The system computes the best-fit line using least squares.
- 3
View Results
The line equation, R², and visualization are displayed.
- 4
Make Predictions
Enter a new x value to predict y.
Examples
Study Hours vs Test Score
Problem:
Data: (1,50), (2,55), (3,65), (4,70), (5,80). Find the regression equation.
Solution:
- 1.n = 5, Σx = 15, Σy = 320, Σxy = 1045, Σx² = 55
- 2.b = [n(Σxy) - (Σx)(Σy)] / [n(Σx²) - (Σx)²]
- 3.b = [5(1045) - 15(320)] / [5(55) - 225] = 7.5
- 4.a = (Σy - b×Σx) / n = (320 - 7.5×15) / 5 = 41.5
Result:y = 41.5 + 7.5x
Each additional hour of study increases the score by an average of 7.5 points.
Prediction
Problem:
With y = 41.5 + 7.5x, what score is predicted for 6 hours of study?
Solution:
- 1.y = 41.5 + 7.5(6)
- 2.y = 41.5 + 45
Result:y = 86.5
A score of approximately 86–87 is predicted with 6 hours of study.
Frequently Asked Questions
What does R² (R-squared) mean?
R² shows the proportion of variance in y explained by x. R² = 0.85 means 85% of the variation in test scores is explained by study hours. The remaining 15% is due to other factors.
What is the difference between correlation and regression?
Correlation (r) measures the strength and direction of a linear relationship (-1 to +1). Regression gives an equation to predict y from x. For simple regression, R² = r².
When is linear regression not appropriate?
When the relationship is non-linear (curved), there are extreme outliers, or assumptions (normal residuals, homoscedasticity) are violated. Check with a residual plot.
What is least squares?
Least squares finds the line that minimizes the sum of squared vertical distances between data points and the line (residuals). It is the most common method for fitting regression.