Education
Linear Regression Calculator
Add paired x and y values and the calculator returns the best-fit line y = mx + b, the slope and intercept, the Pearson r and r squared, and an optional predicted y for a chosen x.
Leave blank to skip the prediction. · e.g. 6
Need at least two distinct x values. The slope is undefined if every x is the same (zero variance in x).
5 pairs · r² = 0.9971
y = 1.47x + 0.53
At x = 0, predicted y = 0.53
Examples
Pairs (1,2), (2,3.5), (3,5), (4,6.2), (5,8)
y ≈ 1.46x + 0.58, r² ≈ 0.991
Pairs (10,20), (20,30), (30,40), (40,50)
y = x + 10 exactly, r = 1
Pairs (1,5), (2,4), (3,6), (4,5), (5,7)
y = 0.5x + 4.1, r² ≈ 0.625
How it works
Find the means of x and y. Compute the deviations from each mean for every pair. The slope is the sum of cross-products divided by the sum of squared x-deviations. The intercept comes from the means.
Slope (m) · Σ((x − x̄)(y − ȳ)) ÷ Σ(x − x̄)²
Intercept (b) · ȳ − m × x̄
Prediction · ŷ = mx + b
r² is the proportion of variance in y explained by the line.
Related statistics calculators
- Correlation coefficient calculator for r alone without fitting a line.
- Mean, median, mode calculator for basic descriptive statistics on x or y individually.
- Variance calculator for variance on each variable.
- Standard deviation calculator for the spread underlying the slope and r.
- Scientific calculator for general arithmetic and prediction follow-ups.
- All education calculators.
Frequently asked questions
Simple linear regression fits a straight line y = mx + b to a set of paired observations of x and y. The line is chosen to minimize the sum of squared vertical distances from each point to the line (the 'least squares' criterion). The slope m says how much y changes for each one-unit increase in x. The intercept b is the y value when x equals zero.
Compute the mean of x and mean of y. For each pair, compute the deviations from those means. The slope is the sum of the products of those deviations divided by the sum of squared x-deviations. The intercept is the mean of y minus the slope times the mean of x. The formula is m = Σ((x − x̄)(y − ȳ)) ÷ Σ(x − x̄)² and b = ȳ − m × x̄.
r squared is the proportion of variance in y that is explained by a linear fit to x. r squared = 0.85 means the line captures 85 percent of the variation in y. The rest is unexplained noise or non-linear structure. Higher r squared means a tighter fit but does not guarantee the line is the right model for predictions outside the data range.
Plug the x into the regression equation: y = mx + b. The calculator does this automatically when you fill the optional prediction field. Be careful predicting outside the range of x values in the data (extrapolation); the relationship may not hold beyond what you observed.
The slope is undefined when every x value is the same (zero variance in x). The fitting formula divides by Σ(x − x̄)², which is zero in that case. Add some variation in the x column and try again. A vertical line cannot be expressed as y = mx + b.
Use it for educational, planning, and quick-check work. It does not return standard errors of the coefficients, confidence intervals, residual plots, or diagnostic tests for the regression assumptions (linearity, independence, normality of residuals, equal variance). For formal research, use R, Python, SPSS, Stata, or another tool that reports those diagnostics.
Related calculators
Education
Final Grade Calculator
Calculate your final course grade from your current grade and your final exam score.
Education
Weighted Grade Calculator
Combine assignments, quizzes, and exams by weight to get a precise weighted course average.
Education
Final Exam Calculator
Find out exactly what you need to score on your final exam to hit your target course grade.