Statistics Calculator
Mean, median, mode, five-number summary, IQR, outliers and SD with steps, a histogram and a box plot.
This linear regression calculator finds the line of best fit by least squares, with slope and intercept .
Best-fit linear equation
The fit explains 99.44% of the variation in y (r² = 0.9944), a very strong fit. Each increase of 1 in x changes y by about 4.048. The slope is statistically different from 0 at the 5% level (p = 5.626×10⁻⁸). At x = 10, the model predicts y ≈ 88.2619.
x = 10 is outside the range of the data (1 to 8), so this prediction is an extrapolation. The fitted pattern may not continue.
| x | y | Predicted ŷ | Residual y − ŷ |
|---|---|---|---|
| 1 | 52 | 51.83333333 | 0.1666666667 |
| 2 | 55 | 55.88095238 | −0.880952381 |
| 3 | 61 | 59.92857143 | 1.071428571 |
| 4 | 64 | 63.97619048 | 0.02380952381 |
| 5 | 68 | 68.02380952 | −0.02380952381 |
| 6 | 71 | 72.07142857 | −1.071428571 |
| 7 | 77 | 76.11904762 | 0.880952381 |
| 8 | 80 | 80.16666667 | −0.1666666667 |
Means
Sums of squares and cross-products
Slope and intercept of the line
Correlation
Standard error, t-test and confidence interval for the slope
With n − 2 = 6 degrees of freedom, the residual standard error is s = √(SSE/(n − 2)) = 0.8067178.
Equation
Paste paired x and y data to get the equation, r, r², the slope p-value, 95% confidence intervals, residuals, a scatter plot and every step. Quadratic, exponential, logarithmic, power and inverse fits are one click away.
Least-squares regression line
Plain-text formula: y^ = a + bx, b = (∑(x − x̄)(y − ȳ))/(∑(x − x̄)^2) = S_(xy)/S_(xx), a = ȳ − bx̄
The line that makes the sum of squared vertical distances from the points to the line as small as possible. The line always passes through the point of means . The calculator uses centered sums, which avoid the rounding errors of the shortcut formulas.
Correlation coefficient and r²
Plain-text formula: r = S_(xy)/√(S_(xx)S_(yy)), R^2 = 1 − (∑(y − y^)^2)/(∑(y − ȳ)^2)
r measures the strength and direction of a straight-line relationship, from −1 to 1. R² is the share of the variation in y that the model explains; for a straight line it equals r².
Slope standard error, t-test and 95% confidence interval
Plain-text formula: s = √((∑(y − y^)^2)/(n − 2)), SE(b) = s/√(S_(xx)), t = b/(SE(b)), b ± t_(n − 2)^∗ · SE(b)
The p-value is the two-sided probability, under Student’s t distribution with n − 2 degrees of freedom, of a slope at least this far from 0 if x and y were unrelated. is the 97.5th percentile of that distribution (2.447 for n = 8). The intercept uses , and a prediction at uses for the mean, with an extra under the root for one new value.
Curved models
Plain-text formula: ln y = ln a + x ln b, ln y = ln a + b ln x, y = a + b ln x, y = a + b · 1/x, y = a + bx + cx^2
Exponential, power, logarithmic and inverse models become straight lines after transforming x, y or both, and are fitted with the line formulas; for the exponential and power models, r and r² therefore refer to ln y, and R² on the original y-values is listed too. The quadratic model is fitted by multiple least squares with a Householder QR factorization of centered x-values, which stays accurate even when x is large (for example calendar years).
Read the equation first: the slope is how much y changes, on average, for each 1-unit increase in x. Then read r²: an r² of 0.95 means the line accounts for 95% of the variation in y. A high r² does not prove that x causes y, and it does not show whether a curved pattern was missed, so always look at the plot.
The p-value for the slope tests whether the true slope could be 0. A p-value below 0.05 means a slope this steep would be unlikely by chance alone; the 95% confidence interval gives the range of slopes consistent with the data. With many points, a tiny slope can be significant yet have a low r², so report both.
The residual plot shows where the line misses. Random scatter around zero is what you want; a curve suggests a different model, and a funnel suggests the spread of y changes with x. Predictions inside the range of your x-values (interpolation) are usually reliable when the fit is good. Predictions outside it (extrapolation) assume the pattern continues and can be badly wrong.
Step 1. Find the means and .
Step 2. For each pair, compute the deviations and .
Step 3. Add up the squared x deviations to get , and the products of the deviations to get .
Step 4. Divide to get the slope , then the intercept .
Step 5. For r, also add up the squared y deviations () and compute .
The worked example below follows these steps with real numbers, and the calculator shows the same steps for your own data under the result.
The p-value and confidence intervals assume four things, often remembered as LINE: a linear relationship, independent observations (no repeated measures or time trends in the errors), roughly normal residuals, and equal spread of residuals across x. The fitted line itself is still the least-squares line when these fail, but the p-value and intervals can mislead.
Check the residual plot. A U shape or arch means the relationship is curved: try the quadratic, logarithmic or exponential model and compare. A funnel shape means unequal spread, and a single point far from the rest can pull the whole line, so check it before trusting the slope.
This calculator also works as a quadratic regression calculator and an exponential, logarithmic, power or inverse regression calculator: change the model and the same data are refitted. To find which regression equation best fits the data, compare the residual plots first and R² on the original y-values second. For multiple regression with two or more x variables, use LINEST in a spreadsheet or a statistics package; this tool fits one x variable.
| Pattern in the scatter plot | Model | Restriction |
|---|---|---|
| Constant change per unit of x | Linear: y = a + bx | None |
| One bend or turning point (for example a projectile’s height) | Quadratic: y = a + bx + cx² | At least 3 different x-values |
| Constant percentage growth or decay | Exponential: y = a·bˣ | y > 0 |
| Fast growth that levels off | Logarithmic: y = a + b ln x | x > 0 |
| Scaling law (doubling x multiplies y by a fixed factor) | Power: y = a·xᵇ | x > 0 and y > 0 |
| Falls toward a floor as x grows | Inverse: y = a + b/x | x ≠ 0 |
TI-84: LinReg(a+bx) gives the same a and b as this calculator. LinReg(ax+b) swaps the letters, so its a is the slope. Turn on DiagnosticOn to see r and r². LinRegTTest gives the same t and p-value.
Casio fx-991EX and fx-991ES PLUS: in Statistics mode choose y = a + bx; a is the intercept and b the slope, matching the order here.
Excel and Google Sheets: SLOPE, INTERCEPT and RSQ match the slope, intercept and r². LINEST(y, x, TRUE, TRUE) also returns the standard errors. Excel’s exponential and power trendlines are fitted on ln y, the same as here, so compare their R² with the r² on the transformed data.
Fit a regression line to x = 1, 2, 3, 4, 5, 6, 7, 8 (hours studied) and y = 52, 55, 61, 64, 68, 71, 77, 80 (exam score), test the slope, then predict the score for 10 hours.
Answer: y ≈ 47.78571 + 4.047619x with r ≈ 0.9972 and r² ≈ 0.9944. Each extra hour adds about 4.05 points (95% CI 3.74 to 4.35, p < 0.001), and the predicted score for 10 hours is about 88.26.
Compute the means of x and y, then and . The slope is and the intercept is , giving . The calculator shows each of these steps for your data.
Yes, when "line of best fit" means the least-squares line, which is how statistics courses, graphing calculators and spreadsheets define it. A line drawn by eye through a scatter plot is only an estimate of it.
It is the probability of getting a slope at least this far from 0 if x and y were actually unrelated. Below 0.05, the relationship is usually called statistically significant. It says nothing about how large or useful the effect is, so read it together with the slope’s confidence interval and r².
It depends on the field. In controlled physics or engineering measurements r² above 0.99 is common; in social or biological data an r² of 0.5 can be meaningful. Judge the fit by the plot and the residuals as well as the number.
You probably used LinReg(ax+b), which calls the slope a and the intercept b. This calculator uses , the same as LinReg(a+bx) and Casio’s y = a + bx mode, so the numbers are the same with the letters swapped.
Both Excel and this calculator fit the exponential trendline on ln y, so the r² shown first matches Excel’s trendline. The separate R² on the original y-values measures the fit on the original scale and is usually a little different.
Exponential and power models take ln y, and logarithmic and power models take ln x, which are only defined for positive numbers. The inverse model divides by x, so x cannot be 0. The linear and quadratic models accept any numbers.
Mean, median, mode, five-number summary, IQR, outliers and SD with steps, a histogram and a box plot.
Sample or population standard deviation and variance, with grouped data and a step-by-step deviation table.
Plot functions, equations, inequalities, parametric and polar curves; find roots and intersections.
Slope from two points, an equation or rise and run, as a fraction, angle and percent grade, with steps.
Z-scores, percentiles and normal probabilities with steps, a z-table and a shaded bell curve.
Type or tap expressions with exact fractions, memory, variables, constants and complex mode.
Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?