Simple linear regression finds the straight line that best describes how a response changes with an explanatory variable : exam score against hours of study, fuel used against distance, sales against advertising spend. "Best" has a precise meaning here: the least-squares line is the one that makes the sum of the squared vertical distances between the points and the line as small as possible.
Type or paste your pairs, one row per observation, and the calculator returns:
- the regression equation , with the slope and the intercept ;
- the correlation coefficient and the coefficient of determination ;
- the standard error of estimate , the typical size of a prediction error;
- the standard error of the slope and the p-value for "no linear relationship";
- a prediction at any you choose;
- a table of fitted values and residuals, and a chart of the data with the fitted line.
Each step of the calculation is shown with your numbers, so you can follow the method or check homework done by hand.
How to use this calculator
- Enter one pair per row. Put the variable you want to predict in the y column. Add rows as needed (up to 200); blank rows are ignored.
- Optionally enter an value in Predict y at x = to get the predicted .
- Read the equation at the top, then , and the standard error. Open the steps to see , and how and were obtained.
- Scan the residual column: large residuals point to outliers, and a curved pattern means a straight line is the wrong model.
Swapping the columns gives a different line: regressing on is not the same as regressing on , because the errors are measured vertically.
The formula
With and the means, define the sums of squares and cross-products
The least-squares slope and intercept are
so the line always passes through the point of means . The correlation and the standard error of estimate are
The slope's standard error is , and follows a Student distribution with degrees of freedom when the true slope is zero.
Worked example
Eight students report their hours of study and their exam score : (2, 54), (3, 61), (5, 62), (6, 68), (8, 70), (9, 77), (11, 79), (12, 86) — the calculator's default data.
The means are and , with and . Hence
The regression line is ŷ = 49.538 + 2.8696x: each extra hour of study is associated with about 2.8696 more points. The correlation is , so : about 95.9 % of the variation in scores is explained by study time. The standard error of estimate is points.
For a student who studies 10 hours, the predicted score is , give or take roughly 2.32 points.
Reading r, r² and the standard error
The slope is the change in for a one-unit increase in , in the units of per unit of . The intercept is the predicted at , which is only meaningful when 0 lies inside the range of your data.
r measures the strength and direction of the linear relationship, from −1 to +1; it has the same sign as the slope. r² is the share of the variance of accounted for by the line: means 81 % of the spread in is explained by and 19 % is left in the residuals. The standard error of estimate is in the units of : roughly two-thirds of the points lie within of the line when the residuals are about normal. For correlation alone, including Spearman's rank coefficient, use the correlation calculator.
Residuals, outliers and extrapolation
A residual is the vertical gap between a point and the line. Residuals always add up to zero. Plotted against , they should look like a random cloud; a U-shape means the relationship is curved, and a funnel means the spread grows with . A single point far from the others can tilt the whole line, so check large residuals before drawing conclusions.
Predictions are reliable only within the range of the observed values. Outside it (extrapolation) nothing guarantees that the straight-line pattern continues, and the calculator warns you. Finally, a strong regression shows association, not causation: a third variable can drive both and .
Frequently asked questions
How do I find the line of best fit?
Compute the means of x and y, then Sxx and Sxy. The slope is b = Sxy / Sxx and the intercept is a = ȳ − b·x̄. The calculator does this exactly and shows each intermediate value in the steps.
What is the difference between r and r²?
r is the correlation coefficient, between −1 and 1, and tells you the direction and strength of the linear relationship. r² is its square, between 0 and 1, and tells you the share of the variation in y explained by the line.
How many data points do I need?
Two points define a line but tell you nothing about the error. You need at least three for the standard error and the p-value, and in practice ten or more to judge whether a straight line is a reasonable model.
What does the p-value of the slope mean?
It tests the hypothesis that the true slope is zero, i.e. that y has no linear relationship with x. A small p-value (below 0.05, say) indicates that the observed slope would be unlikely if there were no relationship at all.
Can I use this for a nonlinear relationship?
Not directly. If the residuals show a curve, transform a variable first (for example take the logarithm of y for exponential growth) and run the regression on the transformed data, or use a polynomial model.
Sources
- OpenStax, Introductory Statistics 2e, §12.3 The Regression Equation
- NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression
- NIST/SEMATECH e-Handbook of Statistical Methods, §4.4.3.1 Least Squares
Last updated: