Linear Regression Calculator
Paste paired data and fit the least-squares line ŷ = a + bx. You get the slope and intercept with standard errors, t-tests and 95% confidence intervals, r and R², the ANOVA table, every residual, a scatter plot with the fitted line, and a prediction with its intervals for any new x.
0 values
0 values
Enter at least three (x, y) pairs, with at least two different x values.
How to Use the Linear Regression Calculator
- 1. Enter x and y. x is the predictor (the variable you use to predict) and y the response. Type two lists in matching order, or one "x, y" pair per line.
- 2. Read the equation and fit. The line ŷ = a + bx, the slope and intercept, r, R² and the standard error of the estimate appear at once.
- 3. Look at the plot. The scatter plot shows whether a straight line is a sensible summary before you rely on any number.
- 4. Predict. Enter a new x to get ŷ with a 95% confidence interval for the mean response and a 95% prediction interval for a single new observation.
- 5. Report the inference. The coefficients table, ANOVA table, residuals and step-by-step working sit below.
The Least-Squares Line
Ordinary least squares picks the line that makes the sum of squared residuals — the vertical gaps between each point and the line — as small as possible. That line has a closed form:
Slope
b = Sxy ÷ Sxx = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
Intercept
a = ȳ − b × x̄
Line
ŷ = a + bx
The slope is the predicted change in y for a one-unit increase in x. The intercept is the predicted y when x = 0, which is only meaningful if x = 0 lies within, or close to, the range of your data.
Worked Example
A campus café records the day's high temperature (x, in °C) and iced drinks sold (y) on ten days: temperatures from 18 to 32 °C, sales from 52 to 85. The means are x̄ = 25 and ȳ = 68.2, with Sxx = 190 and Sxy = 450. So b = 450 ÷ 190 = 2.3684 and a = 68.2 − 2.3684 × 25 = 8.9895, giving ŷ = 8.9895 + 2.3684x: each extra degree brings about 2.4 more iced drinks.
- Fit: r = 0.9792 and R² = 0.9588, so temperature accounts for 95.9% of the day-to-day variation in sales. The standard error of the estimate is 2.39 drinks.
- Slope test: SE(b) = 0.1736, t = 13.64 with 8 degrees of freedom, p < 0.0001; the 95% confidence interval for the slope is 1.97 to 2.77 drinks per degree. The ANOVA F of 186.12 is exactly t², as it always is in simple regression.
- Prediction at 28 °C: ŷ = 75.31 drinks. The 95% confidence interval for the average sales on 28 °C days is 73.19 to 77.42; the 95% prediction interval for one such day is wider, 69.39 to 81.22.
Check Before You Trust It
- Linearity. If the points curve, the residuals will run in a pattern — positive at both ends and negative in the middle, say. A straight line is then the wrong model, however high R² is.
- Constant spread and independence. The p-values and intervals assume residuals with roughly the same spread at every x, independent of one another and close to normal. A funnel shape, or data collected over time with trends in the errors, undermines them.
- Outliers and leverage. One point far from the others in x can pull the whole line towards itself. Check the residuals table and the plot.
- Extrapolation. The model describes 18–32 °C. It predicts 103.73 drinks at 40 °C, but nothing in the data shows the trend continuing there. The intercept is the same problem: "8.99 drinks at 0 °C" is a far extrapolation, which is also why its p-value of 0.0756 does not matter here.
Frequently Asked Questions
- How do you calculate a regression line by hand?
- Find the means of x and y. Compute Sxx = Σ(x − x̄)² and Sxy = Σ(x − x̄)(y − ȳ). The slope is b = Sxy ÷ Sxx and the intercept is a = ȳ − b × x̄. The working panel in the calculator shows each of these with your own numbers.
- What does R-squared tell you?
- R² is the proportion of the variance in y that the line accounts for, from 0 to 1. An R² of 0.96 means 96% of the variation in y is explained by its linear relationship with x. In simple regression R² is the square of the correlation r, and a high value does not prove the relationship is causal or that a straight line is the right shape.
- What is the difference between a confidence interval and a prediction interval?
- A confidence interval estimates the average y for all cases with a given x; a prediction interval covers a single new observation at that x. The prediction interval is always wider, because it adds the scatter of individual points around the line to the uncertainty in the line itself.
- What does the p-value for the slope mean?
- It tests the null hypothesis that the true slope is zero — that x has no linear relationship with y. A small p-value (conventionally below 0.05) is evidence of a non-zero slope. It says nothing about whether the relationship is large, causal or correctly modelled as a straight line.
- Is linear regression the same as correlation?
- They are closely linked but answer different questions. Correlation gives a single symmetric measure of how strongly x and y move together; regression gives an equation for predicting y from x, and swapping x and y changes the line. In simple regression the slope equals r multiplied by the ratio of the standard deviations of y and x, and R² equals r².
- What is the standard error of the estimate?
- It is the typical size of a residual: s = √(SSE ÷ (n − 2)), in the units of y. For the café data it is 2.39 drinks, meaning sales typically land a little over two drinks above or below the line. It feeds every other standard error and interval in the output.