Linear Regression Calculator
Everyday
Linear regression answers the everyday question, 'when x goes up by one, how much does y move?' Paste one (x, y) pair per line — separated by a comma, tab, space, or semicolon — and this tool fits the ordinary least-squares line y = mx + b, returning the slope, the intercept, the Pearson correlation coefficient r, the coefficient of determination R², the standard error of the slope, and a scatter plot with the fit overlaid so you can eyeball how well the line tracks the data. Type any x into the prediction box and the calculator returns the corresponding ŷ instantly. The math uses Welford-stable sums-of-squared-deviations rather than the naive Σxy − (Σx)(Σy)/n formula, so the results stay numerically accurate even when both axes have large means relative to their variance. Everything runs locally in your browser; no data is uploaded.
Best-fit line
y = 1.9988 x + 0.0179
Best-fit line
Slope (m)
1.9988
Intercept (b)
0.0179
Std. error of slope
0.0274
Strength of fit
Pearson r
0.9994
R² (coef. of det.)
0.9989
Pearson r
+ very strong
Summary
Pairs (n)
8
Mean x
4.5
Mean y
9.0125
Predict
20.006
Stay close to the range of your data — extrapolation gets unreliable fast.
Scatter plot with best-fit line
Pearson r measures only linear association. A curved relationship can show r near 0 even when x and y are clearly related — always look at the scatter plot, not just the number.
How to use
- Paste pairs of numbers, one pair per line — the first number on each line is x, the second is y. Comma, tab, space, and semicolon all work as separators.
- Read the headline equation y = mx + b for the best-fit line, then check R² to see how much of the variation in y the line explains.
- Look at the Pearson r sign — positive means y rises with x, negative means y falls. The magnitude (0 to 1) describes how tightly the points hug the line.
- Type any x into the prediction box to get a forecast ŷ — useful for extrapolating one step beyond your data (don't extrapolate too far).
Frequently asked questions
- What's the difference between r and R²?
- Pearson r ranges from −1 to +1 and tells you the direction and strength of the linear relationship. R² is just r squared and is always between 0 and 1 — it's the share of the variation in y that the regression line explains. An r of −0.9 and an r of +0.9 give the same R² of 0.81 (the line explains 81% of the variance), but the relationships go in opposite directions.
- Is correlation causation?
- No. A strong fit means y moves with x in your sample, not that x causes y. Classic example: ice-cream sales correlate with shark attacks (both rise in summer); ice cream doesn't cause attacks. Use regression to describe a relationship, not to prove one variable drives the other.
- When does linear regression NOT work?
- When the relationship is curved (use polynomial fit instead), when a few extreme points pull the line off (look at the scatter plot — outliers wildly change m and b), when variance grows with x (heteroscedasticity), or when the y values aren't independent of each other. A high R² with an obviously curved scatter is a sign you need a different model.
- What does the standard error of the slope tell me?
- It's the typical uncertainty in m given the scatter around the line. A rough 95% confidence interval for the slope is m ± 2 × SE(m). If that interval crosses zero, you can't confidently say x and y are related — the data is consistent with no relationship.
- What sample size do I need?
- Two points give an exact line with R² = 1 but tell you nothing about reliability. Three is the minimum for a meaningful R² and a standard error. For trustworthy slope estimates, aim for at least 10 — and for inference (p-values, confidence intervals), 20–30 is a comfortable floor.
Related tools
Loan / Mortgage Calculator
Calculate the monthly payment, total interest, and full amortization schedule for any fixed-rate loan.
Compound Interest Calculator
Project how a starting balance grows with regular contributions, your interest rate, and your compounding frequency.
Age Calculator
Calculate exact age in years, months, days — and find your next birthday.
BMI Calculator
Calculate Body Mass Index from height and weight, with a healthy range.
Tip Calculator
Calculate the tip and split the total bill between people.
Percentage Calculator
Work out percentages, what-percent, and percent change in one place.