Which straight line fits your data, and how far can you trust it? Get the least-squares equation, a test of the slope, R squared and a forecast with intervals from two lists or pasted columns.
Linear Regression Calculator - Best Fit Line and Prediction
Which straight line fits your data, and how far can you trust it? Get the least-squares equation, a test of the slope, R squared and a forecast with intervals from two lists or pasted columns.
Parameters
Enter data for calculations
💡 Fill in all required fields to unlock the calculate button
Linear regression equation, predictions and the pair that moves the line
Four famous data sets by the statistician Frank Anscombe all produce the same fitted line, y = 3.00 + 0.500x, the same R squared of 0.67 and the same p-value of 0.0022. One of them is a clean straight cloud, one is a curve, one has a single outlier and one has a slope set by a single point. This calculator fits the least-squares line to your pairs and then tells you which of those four situations you are in. Paste X and Y as two lists, or two columns straight from a spreadsheet, and you get the equation, the slope with its standard error, t, p and confidence interval, R squared and adjusted R squared, Pearson's r, the F statistic, a prediction for any X with both kinds of interval, and a residual table that flags the pairs worth a second look.
Four boxes, filled in this order
- X values - the variable you know or control: hours studied, temperature, miles driven, the month number. Separate them with spaces, commas or new lines. To paste two spreadsheet columns at once, put them here, one pair per line, and leave the Y box empty; a header row such as "hours score" becomes the axis names.
- Y values - the variable you want to predict, in the same order, so the fourth Y belongs to the fourth X. Use a dot for decimals and no thousands separators: 1000, not 1,000, which the calculator refuses rather than guessing.
- X to predict for - optional. One X value; the result gives the predicted Y, a prediction interval for a single new observation and a narrower confidence interval for the average Y. Values outside your data range get an extrapolation warning.
- Confidence level - 95% is the usual choice, 99% gives wider intervals and a stricter test of the slope, 90% suits a first look. Nothing is preselected, so the level in the report is always the one you picked.
- Read the result - the equation and the verdict on the slope first, then the five summary tiles, the prediction, the coefficient table and the residuals. A yellow note appears only when something needs your attention: one pair steering the slope, a slope resting on a single X value, extrapolation or a very small sample.
The least-squares line, done by hand on five pairs
Every number in the result comes from four sums. Take X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5. The means are 3 and 4.
Sxy = sum of (x - mean x)(y - mean y) = 6
slope b = Sxy / Sxx = 0.6
intercept a = mean y - b × mean x = 4 - 0.6 × 3 = 2.2
SSE = sum of squared residuals = 2.4, SST = sum of (y - mean y)^2 = 6
R squared = 1 - SSE / SST = 0.6
s = square root of SSE / (n - 2) = 0.8944
SE of slope = s / square root of Sxx = 0.2828, t = 0.6 / 0.2828 = 2.121
With 3 degrees of freedom a t of 2.121 gives a two-sided p of 0.1240, so this slope is not significant at 0.05 even though R squared is 0.60. Five points are simply too few to rule out chance. The calculator prints exactly these figures, plus adjusted R squared (0.4667), and it also notices that dropping pair 1 alone would cut the slope from 0.6000 to 0.2000.
The same fit comes out of Excel's SLOPE, INTERCEPT, RSQ, STEYX and LINEST functions and from lm(y ~ x) in R, so you can use the calculator to check a spreadsheet, or the other way round.
Regression line or correlation coefficient: which question each one answers
Both come from the same sums, and r is simply the signed square root of R squared in a one-predictor model. The difference is the question. The table sets them side by side.
| Question | Regression (this tool) | Correlation | Who should pick it |
|---|---|---|---|
| How much does Y change per unit of X? | yes, the slope with its units | no, r has no units | anyone budgeting, pricing or dosing |
| What Y should I expect at X = 27? | yes, with a prediction interval | no | forecasting and planning |
| Does it matter which variable is X? | yes, Y on X and X on Y are different lines | no, r is symmetric | regression when one variable is the outcome |
| Is the relationship there at all? | t test of the slope | t test of r, same p-value | either |
| Robust version when an outlier dominates | influence check on each pair | Spearman's rank correlation | run both and compare |
| Verdict | Use regression when you want a number out (a slope, a forecast); use correlation when you only need the strength of the association, for which the Pearson correlation calculator adds Spearman's rho and a Fisher interval. | ||
Anscombe's quartet: one equation, four stories
All four sets have eleven pairs. Paste any of them and the headline numbers barely move. What changes is the residual table and the notes under it, and that is the part a plain line-fitting tool leaves out.
| Set | Equation | R squared | What the calculator adds |
|---|---|---|---|
| I, straight cloud | 3.000 + 0.5001x | 0.6665 | nothing, no note: this is the case the line was made for |
| II, a curve | 3.001 + 0.5000x | 0.6662 | residuals run negative, positive, negative along X; the ends at X = 4 and 14 both sit 1.86 standard errors below the line |
| III, one outlier | 3.002 + 0.4997x | 0.6663 | pair 3 (13, 12.74) in red with a standardized residual of 3.00, Cook's distance 1.39, and the slope without it: 0.3454 |
| IV, one lever | 3.002 + 0.4999x | 0.6667 | ten X values are all 8, so the note says the slope rests on pair 8 (x = 19) alone; its residual is exactly 0, which is why no residual check could ever catch it |
All four report p = 0.0022 for the slope. A p-value only measures how far the slope is from zero relative to the scatter; it cannot tell a straight relationship from a curve or from a line held up by one point.
Five everyday data sets through the calculator
Result: y = -31.86 + 10.71x, R squared 0.9983; at 27 degrees the forecast is 257.4 cones, with a 95% prediction interval of 249.8 to 265.0.
Result: y = 47.87 + 4.086x, p = 0.0002; each extra hour is worth about 4.1 points, with a 95% interval for the slope of 3.226 to 4.945.
Result: y = 2.122 + 0.09057x, so about 9.1 cents a mile on top of a fixed 2.12; a 100-mile trip is predicted at 11.18 dollars.
Result: slope 0.04762, p = 0.8536, R squared 0.0061 and adjusted R squared -0.1595: negative, because the line explains less than it costs in degrees of freedom.
Result: 343.1 cones, prediction interval 329.3 to 356.9, and a warning that 35 lies outside the measured range of 14 to 31.
Mistakes that make a regression line misleading
Regression questions, answered with the numbers
Related tools
R Squared Calculator
Adjusted R squared, the overall F test and the Excel RSQ gap for any model - See calculator
Z-Score Calculator
Standardized residuals are z-scores; score each value and flag outliers with the modified z - See calculator
Pearson Correlation Calculator
Strength of the association with a p-value, Fisher interval and Spearman's rho - See calculator
Coefficient of Variation Calculator
Spread of a list as a share of its mean - See calculator
Interquartile Range Calculator
Quartiles and outlier fences to screen each variable before fitting a line - See calculator
Skewness Calculator
Checks whether a variable is lopsided enough to need a log transform - See calculator
Standard Deviation Calculator
Spread of one list, sample or population - See calculator
Linear Function Calculator
Zero, intercepts and direction of a line once you know its coefficients - See calculator