How this instrument works
Linear regression finds the one straight line, y = intercept + slope·x, that best fits a set of paired (x, y) data points, in the specific sense of minimizing the sum of squared vertical distances between each real point and the line — the 'least squares' criterion. It's the most widely used tool in statistics for describing how one numeric variable tends to change as another one changes, and for predicting a y value at any x, including x values you haven't directly observed.
The slope is calculated as Sxy / Sxx, where Sxy is the sum of the products of each point's deviation from the mean x and mean y, and Sxx is the sum of squared deviations from the mean x alone — the same cross-product machinery this site's correlation and covariance calculators use. The intercept follows directly from the slope: intercept = ȳ − slope·x̄, which guarantees the fitted line passes through the point (x̄, ȳ), the 'center of mass' of the data. R-squared then measures how much of the variation in y this line actually explains, from 0 (no explanatory power) to 1 (every point sits exactly on the line).
A strong R-squared doesn't automatically mean x causes y, and a fitted line shouldn't be trusted far outside the range of x values you actually entered — extrapolation beyond your data assumes the same straight-line relationship keeps holding, which is an assumption, not a guarantee. Within the range of your data, though, this is the standard, well-understood method for summarizing a linear relationship and making predictions from it.
- Enter your input values into x values.
- Enter the matching output values into y values, in the same order as the x values.
- Read Slope (b) and Intercept (a) for the fitted line's equation, y = intercept + slope·x.
- Read Correlation coefficient (r) and R-squared to judge how well the line actually fits your data.
- Use the fitted equation to predict y at any x within (or close to) the range of x values you entered.
Worked example — hours slept vs quiz score
Five students report hours of sleep the night before a 5-question quiz and their scores: 1 hour → 2 correct, 2 hours → 4 correct, 3 hours → 5 correct, 4 hours → 4 correct, 5 hours → 5 correct. Enter 1, 2, 3, 4, 5 into x values and 2, 4, 5, 4, 5 into y values. The means are x̄ = 3 and ȳ = 4; Sxy = 6 and Sxx = 10, giving Slope (b) = 6/10 = 0.6 and Intercept (a) = 4 − 0.6×3 = 2.2.
The fitted line is score = 2.2 + 0.6×hours. R-squared reads 0.6 exactly, meaning this straight-line relationship between sleep and score accounts for 60% of the variation in quiz scores across these five students — a moderate fit, with the remaining 40% coming from other factors the line doesn't capture. Correlation coefficient (r) reads about 0.7746, the square root of 0.6, confirming a fairly strong positive relationship between more sleep and a higher score.
Questions
What does R-squared actually tell me?
R-squared is the fraction of the total variation in y that the fitted line explains, ranging from 0 (the line explains none of the variation — you'd do just as well predicting the mean of y every time) to 1 (every point sits exactly on the line, no scatter at all). An R-squared of 0.6, as in the worked example, means 60% of the spread in y values lines up with the fitted relationship to x, and 40% is left unexplained by this particular straight-line model.
How is this different from this site's correlation and covariance calculators?
All three are built from the same underlying Sxy and Sxx cross-product calculations on paired x/y data, but they answer different questions. Correlation reports r, a single number from -1 to 1 describing the strength and direction of a linear relationship. Covariance reports the raw (unstandardized) joint variability between x and y. Linear regression goes further than either — it fits an actual predictive equation, y = intercept + slope·x, that you can use to estimate y at any given x, not just describe the relationship's strength.
Can I trust the fitted line to predict y far outside my x range?
Not with much confidence. The fitted line is only guaranteed to describe the relationship within the span of x values you actually observed — extrapolating well beyond that range assumes the same linear pattern keeps holding indefinitely, which real-world relationships very often don't. Predictions close to your observed x range are generally more trustworthy than predictions far beyond it.
Does a strong linear fit prove x causes y?
No — a high R-squared or a strong correlation only shows that x and y tend to move together in a straight-line pattern; it says nothing on its own about whether changes in x actually cause the changes in y. Both variables could be driven by some third factor, or the relationship could run in the opposite direction, or it could simply be coincidental. Establishing causation requires evidence beyond a regression fit alone, such as a controlled experiment.
What's the minimum number of data points I need?
At least 2 pairs of x and y values are required to fit any line at all — with exactly 2 points, the 'best fit' line passes through both of them exactly, with an R-squared of 1.0 by definition, since two points always determine a unique line. Meaningful R-squared and correlation figures that actually say something about fit quality generally need more than 2 points, since with only 2 there's no genuine scatter to measure.