Linear Regression Calculator
Least-squares slope, intercept, R², and predictions for any paired (x, y) data.
ŷ = 1.1333 + 0.9758 · x (n = 10)
Scatter with OLS line
Ordinary least-squares regression finds the line ŷ = a + b·x that minimises the sum of squared vertical residuals. This calculator returns the slope, intercept, R², residual standard error, a t-test on the slope, a 95% CI on the slope, and a prediction for any new x.
What the regression line is
Choose a and b to minimise Σ(yᵢ − a − bxᵢ)². Closed-form solutions: b = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)², a = ȳ − b·x̄.
Interpretation: a 1-unit increase in x is associated with a b-unit change in the average of y. The intercept a is the predicted y when x = 0 — meaningful only if x = 0 is inside or near your data.
R² = 1 − SS_res / SS_tot is the proportion of y's variance explained by x. Equals r² for simple regression.
What the standard error and t-test tell you
Residual standard error s = √(SS_res / (n − 2)). The typical vertical distance from the line — y is predicted with roughly ±2s accuracy for new observations.
SE of the slope: s / √Σ(xᵢ − x̄)². Determines how precisely we know b.
t = b / SE(b), df = n − 2. Tests H₀: true slope = 0 (i.e. x has no linear effect on y).
95% CI on slope: b ± t* · SE(b). If this interval excludes 0, the slope is significant at α = 0.05.
Assumptions (LINE mnemonic)
Linearity — the true relationship between mean y and x is a straight line.
Independence — residuals don't form patterns over time or grouping.
Normality — residuals are approximately normal (matters for small-sample p-values; the CLT helps for large n).
Equal variance (homoscedasticity) — residual spread is roughly constant across x.
Diagnostic: residual-vs-fitted and QQ plots reveal violations far better than R² alone.
Worked example
Same data as the correlation calculator: x = 1..10, y = (2,4,5,4,5,7,8,8,10,12).
b = 73.5 / 82.5 ≈ 0.891. a = 6.5 − 0.891·5.5 ≈ 1.6.
Residuals: yᵢ − (1.6 + 0.891·xᵢ). SS_res ≈ 9.45. s ≈ √(9.45/8) ≈ 1.087.
SE(slope) ≈ 1.087/√82.5 ≈ 0.120. t = 0.891/0.120 ≈ 7.44, df = 8, p < 0.001. Slope is highly significant.
Prediction at x = 11: ŷ = 1.6 + 0.891·11 ≈ 11.4 (with a wider prediction interval than confidence interval because individual variability adds on top).
Common pitfalls
Extrapolation: predicting at x far outside the observed range, where the assumed linear shape may break.
Influential points: a single high-leverage outlier can pull the slope dramatically. Inspect leverage and Cook's distance, not just R².
Omitted variable bias: a strong relationship between x and y might really be driven by a third variable z. Simple regression can't detect this.
Reporting R² without checking residual patterns. A curved relationship can give R² = 0.95 and yet the line is the wrong model.
Confusing prediction interval (for one new y) with confidence interval (for the mean y at that x). Prediction intervals are always wider.
Frequently asked questions
How does this differ from the correlation calculator?
Same math underneath, but regression gives slope, intercept, residual SE, slope SE, and predictions — useful when y depends on x asymmetrically.
What if my relationship is curved?
Try log/sqrt transformations, polynomial terms, or a non-linear model. Don't force a line on visibly curved data.
Can I do multiple regression here?
This page handles simple (one x) regression. Multiple regression needs a dedicated multivariate tool — coming later in this suite.
Is R² the same as r²?
For simple linear regression with an intercept, yes. Multiple regression R² generalises differently.
More in Statistics & Probability
From z-scores and confidence intervals to t-tests, chi-square, correlation, regression, and the binomial/Poisson distributions — textbook-grade tools with worked examples.
- Z-Score Calculator
Convert a value to a z-score, percentile, and tail probabilities using the standard normal distribution.
- Normal Distribution Calculator
Find P(X<x), P(X>x), and between-range probabilities for any normal distribution with mean μ and SD σ.
- Binomial Distribution Calculator
Compute P(X=k), cumulative probabilities, mean, and variance for n trials with success probability p.
- Poisson Distribution Calculator
Model rare events with rate λ — get P(X=k), cumulative probability, mean, and variance.
- Permutations & Combinations Calculator
Compute nPr (order matters) and nCr (order doesn't) with full counting-principle explanation.
- Bayes' Theorem Calculator
Update prior beliefs with new evidence using Bayes' rule — posterior probability with tree diagram.
Related calculators
Browse all Education →Area of a Circle Calculator
Find the area of a circle from its radius, diameter, or circumference with the exact formula A = π × r².
Cylinder Volume Calculator
Volume and surface area of any cylinder from its radius and height using V = π × r² × h.
Slope & Grade Calculator
Convert rise and run into decimal slope, percent grade, angle, and 1:N ratio — for ramps, roofs, roads, stairs.
Chi-Square Calculator
Goodness-of-fit and independence tests with expected counts, chi-square statistic, and p-value.
Correlation Calculator
Pearson correlation coefficient r with scatter plot, regression line, and interpretation guide.
Fraction Calculator
Add, subtract, multiply, and divide fractions and mixed numbers — results returned simplified, as a mixed number, and as a decimal.
Standard Deviation Calculator
Mean, median, mode, range, sample/population standard deviation, variance, quartiles, IQR, and SEM for any list of numbers.
Course Grade Calculator
Weighted course grade from assignments, quizzes, and exams. Shows current grade plus the score needed on remaining work.