Home / Tools / Linear Regression Calculator
Linear Regression Calculator
A linear regression calculator fits the straight line y = intercept + slope · x that best predicts one variable from another. Paste your two columns of numbers below and read the fitted equation, the slope and intercept with standard errors, t and p, the R-squared, and a scatter with the fitted line, all matching R's lm().
I want to fit a straight line to my data
-
| Term | Estimate | Std. error | t | p | 95% CI |
|---|
How this regression is computed
✓ No data leaves your browser
✓ Verified against R's lm()
✓ Free, no sign-up
How to read the output
Simple linear regression fits one straight line, y = b0 + b1·x, by least squares: it picks the intercept b0 and slope b1 that make the sum of squared vertical gaps (the residuals) as small as possible. Here is what each number the tool prints means.
| Output | What it is | How to read it |
|---|---|---|
| Intercept (b0) | Predicted y when x = 0 | The height of the line at x = 0. Often not meaningful if x = 0 is outside your data. |
| Slope (b1) | Change in y per one-unit rise in x | The whole point of the model. Positive slope tilts up, negative tilts down. |
| Std. error | Uncertainty in a coefficient | Smaller is sharper. The coefficient plus or minus about two standard errors is its 95% interval. |
| t and p | Test that the coefficient is zero | t = estimate / std. error. A slope p below 0.05 means x is a useful linear predictor. |
| R-squared | Fraction of variance in y explained | 0 = no better than the mean of y, 1 = points fall exactly on the line. |
| Residual std. error | Typical size of a prediction miss | The spread of points around the line, in the units of y. |
| F-statistic | Overall test of the model | In a one-predictor model it equals the slope t squared and shares its p-value. |
Two cautions sit behind every fit. First, a line is only as good as its residuals: switch the plot to the residual view and look for a funnel shape (non-constant spread), a curve (the relationship is not straight) or a lone point far from the rest (high leverage). Second, correlation is not causation: a significant slope says x and y move together, not that changing x will change y.
Confidence vs prediction intervals
| Interval | Answers | Width | In R |
|---|---|---|---|
| Confidence interval (for the mean) | Where is the average y for all cases at this x? | Narrower; shrinks as n grows | predict(fit, newdata, interval = "confidence") |
| Prediction interval (for a new case) | Where will one new y at this x fall? | Wider; includes point scatter | predict(fit, newdata, interval = "prediction") |
| Coefficient interval | What is the plausible range for the slope or intercept? | Estimate plus or minus t times its std. error | confint(fit) |
Switch to Predict a new value above, type an x, and the tool draws both bands and reports the predicted y with its confidence and prediction intervals. Both widen as you move away from the centre of your x values, because the line is least certain out at the edges.
Frequently asked questions
How do I calculate a linear regression from x and y data?
Paste your two columns into the box, one pair per row, separated by a tab, comma or space. The calculator lines the columns up, drops any row where either value is missing, fits y = intercept + slope times x by ordinary least squares, and reports the equation, the slope and intercept with standard errors, t and p, the R-squared, a scatter with the fitted line and a residual plot, all updating as you type. If you paste more than two columns you can pick which one is x and which is y.
What is the difference between R-squared and adjusted R-squared?
R-squared is the fraction of the variance in y explained by the model, from 0 (no better than the mean of y) to 1 (points on the line). Adjusted R-squared penalises R-squared for the number of predictors, so it can fall when you add a variable that does not help. For a one-predictor regression the two are close; adjusted R-squared is the fairer number when comparing models with different numbers of predictors.
What does the p-value on the slope mean?
The slope p-value tests the null hypothesis that the true slope is zero, meaning x has no linear relationship with y. A small p-value (typically below 0.05) is evidence that the slope is not zero, so x is a statistically useful linear predictor of y. In a simple regression the slope t-test, the overall F-test and the correlation test all give the same p-value. A significant slope does not by itself mean the effect is large or that x causes y.
What is the difference between a confidence interval and a prediction interval?
A confidence interval for the mean response at a given x is the range likely to contain the average y across all cases with that x. A prediction interval is the range likely to contain a single new observation at that x, and is always wider because it adds the scatter of individual points to the uncertainty in the line. Use the confidence interval to describe the trend and the prediction interval to bracket one future measurement.
Does a significant regression mean x causes y?
No. Regression measures how y changes with x on average, not why. A significant slope can come from a real cause, a hidden third variable that drives both, reverse causation or coincidence. Establishing cause needs an experiment or a careful causal design, not just a small p-value. A regression can also miss a curved relationship or be distorted by one high-leverage point, so always read the residual plot.
Does this linear regression calculator match R?
Yes. The coefficients, standard errors, t statistics, p-values, R-squared, adjusted R-squared, residual standard error, F-statistic, confidence intervals and prediction intervals are checked against R's lm(), summary.lm(), confint() and predict.lm() across several datasets including mtcars, negative slopes and the minimum of three points, matching R to at least six significant figures.