How to use the linear regression calculator
- Copy your two columns from Excel or Google Sheets and paste them into the X box: they split into X and Y automatically. You can also type the values, one pair per position.
- Optionally enter an x value to predict y at, and name the variables so the chart and explanation use them.
- Click Calculate regression.
- Read the equation of the line, R² and the slope test, then check the chart and the residuals for curves or outliers.
- Download the chart as a PNG, or copy a link to these results to share them.
Linear regression formula
Simple linear regression fits the straight line that makes the squared vertical distances from the points to the line as small as possible (least squares):
y = b0 + b1x , b1 = SxySxx , b0 = y − b1x
How well the line fits, and whether the slope could really be zero:
R2 = 1 − SSESyy , s = SSEn − 2 , t = b1s / Sxx
- y
- The predicted value of y for a given x
- b1
- The slope: how much y changes, on average, for each one-unit increase in x
- b0
- The intercept: the predicted y when x = 0
- Sxy, Sxx, Syy
- Sums of cross-products and squared deviations: Σ(x − x)(y − y), Σ(x − x)2 and Σ(y − y)2
- SSE
- The sum of squared errors (residuals): Σ(y − y)2
- R2
- The coefficient of determination: the share of the variation in y the line explains
- s
- The standard error of the regression: the typical distance of a point from the line, in y units
- t
- The test statistic for the slope, with n − 2 degrees of freedom
Worked example
Five students report hours of sleep (x) and a quiz score out of 5 (y): (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). Find the regression line.
-
Find the means
x = 3, y = 4
-
Sum the cross-products and squared deviations of x
Sxy = 6, Sxx = 10, Syy = 6
-
Slope and intercept
b1 = 610 = 0.6, b0 = 4 − 0.6 × 3 = 2.2
-
The line
y = 2.2 + 0.6x
-
Fit: SSE = 6 − 0.6 × 6 = 2.4
R2 = 1 − 2.46 = 0.60, s = 2.43 = 0.8944
-
Test the slope with 5 − 2 = 3 degrees of freedom
t = 0.60.8944 / 10 = 2.1213, p = 0.1240
What it means: each extra hour of sleep goes with a quiz score about 0.6 points higher, and the line explains 60% of the variation in scores. With only five students, though, p = 0.124 is above 0.05, so the slope isn't statistically significant: a sample this small can't rule out that the true slope is zero.
How to interpret the results
- The equation is your model. Plug in an x value to predict y, but only within the range of x you measured.
- The slope is the practical result: the change in y per unit of x. Its confidence interval shows how precisely you've pinned it down.
- R² is the share of the variation in y the line explains. It says nothing about whether a straight line is the right shape.
- The p-value for the slope tests whether there's any linear relationship at all. A tiny p-value with a small R² means a real but weak relationship.
- The residuals (actual minus predicted) should look like random scatter. A curve or a funnel shape means a straight line isn't the whole story.
Working with lab standards? The standard curve calculator fits the same line and reads the concentration of your unknown samples off it. For just the strength of the relationship, use the correlation coefficient calculator.