Linear Regression Calculator
Paste paired x and y values to fit a least-squares line. The calculator gives the regression equation, the slope and intercept with standard errors, confidence intervals and p-values, R² and adjusted R², the ANOVA F test, a scatter plot with the fitted line, the residuals, and the predicted y at any x with its confidence and prediction intervals.
Regression equation
Each 1-unit increase in age changes the predicted systolic BP by 0.8986 (95% CI 0.7440 to 1.053). R² = 0.9574, p < .001.
- Slope (b₁)
- 0.8986
- SE 0.06701
- Intercept (b₀)
- 84.39
- SE 3.841
- R²
- 0.9574
- adjusted 0.9521
- Correlation (r)
- 0.9785
- Residual standard error
- 2.496
- df = 8
- F(1, 8)
- 179.79
- p = 9.16 × 10−7
Prediction at x = 60
- Predicted y (ŷ)
- 138.30
- 95% CI for the mean
- 136.39 to 140.22
- 95% prediction interval
- 132.24 to 144.37
- for one new observation
Coefficients and ANOVA table
| Estimate | SE | t | p | 95% CI | |
|---|---|---|---|---|---|
| Intercept | 84.39 | 3.841 | 21.969 | < 0.0001 | 75.53 to 93.25 |
| Age (years) | 0.8986 | 0.06701 | 13.409 | < 0.0001 | 0.7440 to 1.053 |
| Source | SS | df | MS | F | p |
|---|---|---|---|---|---|
| Regression | 1119.8 | 1 | 1119.8 | 179.79 | < 0.0001 |
| Residual | 49.826 | 8 | 6.2283 | ||
| Total | 1169.6 | 9 |
Fitted values and residuals
| # | x | y | ŷ | Residual |
|---|---|---|---|---|
| 1 | 35 | 118 | 115.84 | 2.159 |
| 2 | 42 | 121 | 122.13 | −1.130 |
| 3 | 48 | 129 | 127.52 | 1.478 |
| 4 | 51 | 126 | 130.22 | −4.217 |
| 5 | 55 | 135 | 133.81 | 1.188 |
| 6 | 58 | 138 | 136.51 | 1.493 |
| 7 | 62 | 136 | 140.10 | −4.101 |
| 8 | 66 | 145 | 143.70 | 1.304 |
| 9 | 70 | 148 | 147.29 | 0.7101 |
| 10 | 74 | 152 | 150.88 | 1.116 |
Report it like this
A simple linear regression showed that age significantly predicted systolic BP, b = 0.899, 95% CI [0.744, 1.05], t(8) = 13.41, p < .001. The model explained 95.7% of the variance in systolic BP, R² = .96, F(1, 8) = 179.79, p < .001.
How to use the calculator
- Paste the predictor into X and the outcome into Y, one value per pair in the same order. Columns copied from Excel work as they are. Rename the variables above the boxes.
- Read the equation and the coefficients. The slope is the change in the predicted y for each one-unit increase in x; the intercept is the predicted y when x is 0.
- Enter an x value to predict (optional). You get the predicted y, the confidence interval for the mean y at that x and the wider prediction interval for one new observation.
- Check the plot and the residuals, then copy the report sentence.
Linear regression formulas
b1 = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² b0 = ȳ − b1x̄
Least squares picks the line that makes the sum of the squared vertical distances from the points to the line (the residuals) as small as possible. The slope is the covariance of x and y divided by the variance of x, and the line always passes through the point (x̄, ȳ).
The residual standard error is s = √[SSE / (n − 2)]. The slope’s standard error is s / √Σ(x − x̄)², and its t test with n − 2 degrees of freedom has the same p-value as the test of Pearson’s r and as the F test, F = t². R² = SSR / SST is the share of the variance in y explained by x. Results match SciPy’s linregress and statsmodels OLS.
For a predicted value at x₀, the confidence interval for the mean uses the standard error s√[1/n + (x₀ − x̄)² / Σ(x − x̄)²]; the prediction interval for a single new observation adds 1 inside the square root, so it is always wider.
Worked examples
- Blood pressure by age (the default): for 10 adults the fitted line is ŷ = 84.39 + 0.899 × age. Systolic pressure rises by 0.90 mmHg per year of age (95% CI 0.74 to 1.05), t(8) = 13.41, p < .001, R² = 0.957. At age 60 the predicted pressure is 138.3 mmHg, with a 95% CI for the mean of 136.4 to 140.2 and a prediction interval for one person of 132.2 to 144.4.
- Calibration curve: absorbance against concentration gives ŷ = 0.0037 + 0.0789x with R² = 0.9998; at 5 µg/mL the predicted absorbance is 0.398.
- Exam score by hours studied: each extra hour adds 2.61 points on average (R² = 0.935), and 7 hours predicts a score of 70.4.
Assumptions and how to check them
- Linearity: the scatter plot should look like a straight band, not a curve. Residuals that bend from negative to positive and back suggest a curved relationship.
- Independence: each pair should come from a different subject or time point that does not influence the others.
- Constant spread: the residuals should be about as spread out at low and high x. A funnel shape means the standard errors are unreliable.
- Normal residuals: needed for the p-values and intervals in small samples, less so in large ones.
Do not predict far outside the range of x you observed; the calculator warns when you do. A high R² does not prove the model is right, and a single influential point can change the slope a lot, so look at the plot. To describe the strength of the relationship without choosing which variable is the outcome, use the correlation coefficient calculator; for two or more predictors, a multiple regression in R, SPSS or Stata is needed.
How to report a linear regression
Report the slope with its confidence interval and test, the variance explained and the overall F test:
A simple linear regression showed that age significantly predicted systolic blood pressure, b = 0.899, 95% CI [0.744, 1.05], t(8) = 13.41, p < .001. The model explained 95.7% of the variance, R² = .96, F(1, 8) = 179.79, p < .001.
Give the units of the slope (here mmHg per year), the number of observations and how you checked the assumptions. In a table, list the intercept and slope with their standard errors and confidence intervals. If you only have a reported correlation or t value, the p-value calculator gives the exact p-value.
Questions
- How do you calculate a linear regression line?
- The slope is the sum of the products of the x and y deviations from their means divided by the sum of the squared x deviations. The intercept is the mean of y minus the slope times the mean of x. The equation is then ŷ = intercept + slope × x.
- What does R² mean in regression?
- R² is the proportion of the variance in y that the regression line explains, from 0 to 1. R² = 0.957 means 95.7% of the variation in y is accounted for by its linear relationship with x. In simple linear regression R² is the square of Pearson’s r.
- What is the difference between correlation and regression?
- Correlation measures how strongly two variables are linearly related, and it treats them symmetrically. Regression picks one variable as the outcome and gives the equation to predict it from the other, with the slope in the outcome’s units.
- What is the difference between a confidence interval and a prediction interval?
- The confidence interval is for the average y of all subjects with a given x. The prediction interval is for the y of one new subject at that x, so it also includes the scatter of individuals around the line and is always wider.
- How do I interpret the slope?
- The slope is the average change in y for each one-unit increase in x. A slope of 0.90 for blood pressure on age means systolic pressure is about 0.9 mmHg higher for each additional year of age, on average.
- How many data points do I need for linear regression?
- At least 3 pairs are needed to estimate a slope with a standard error, but estimates from fewer than about 10 to 20 pairs are imprecise and the assumptions are hard to check. A power analysis gives the sample size needed to detect a given slope or correlation.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, section 4.1.4.1: Linear least squares regression
- Schneider A, Hommel G, Blettner M. Linear regression analysis: part 14 of a series on evaluation of scientific publications. Dtsch Arztebl Int 2010;107(44):776–782. doi:10.3238/arztebl.2010.0776
- American Psychological Association. Numbers and statistics guide (APA Style, 7th edition)
Calculations run in your browser; nothing you enter is sent or stored. Results are checked against SciPy and statsmodels in our test suite. Last updated 29 November 2026.