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.

Paste each variable as a column from Excel, or type numbers separated by spaces or commas. The first X pairs with the first Y, and so on.

Confidence level

Gives the predicted value with a confidence interval for the mean and a prediction interval for one new observation.

Load a worked example

Regression equation

ŷ = 84.39 + 0.8986x

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.

12013014015040506070Age (years)Systolic BP (mmHg)
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
Regression coefficients
EstimateSEtp95% CI
Intercept84.393.84121.969< 0.000175.53 to 93.25
Age (years)0.89860.0670113.409< 0.00010.7440 to 1.053
Analysis of variance for the regression
SourceSSdfMSFp
Regression1119.811119.8179.79< 0.0001
Residual49.82686.2283
Total1169.69
Fitted values and residuals
Observed, fitted and residual values
#xyŷResidual
135118115.842.159
242121122.13−1.130
348129127.521.478
451126130.22−4.217
555135133.811.188
658138136.511.493
762136140.10−4.101
866145143.701.304
970148147.290.7101
1074152150.881.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

  1. 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.
  2. 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.
  3. 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.
  4. 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