About the Linear Regression Calculator
When two quantities move together, such as hours studied and test scores, or temperature and ice cream sales, a straight line often summarises the pattern. Linear regression finds the single line that fits the data best in a precise sense, and correlation measures how tightly the points cluster around it.
This calculator works with exact fractions wherever the data allow, so a slope of 3/5 is shown as 3/5 rather than 0.6000000001. It shows the means, the sums of squares, and how each part of the answer follows from them, which is the layout most statistics courses expect in written work.
What is least-squares regression?
For each data point, the residual is the vertical distance between the observed y and the y predicted by a line. The least-squares line is the one that makes the sum of the squared residuals as small as possible. Squaring keeps positive and negative errors from cancelling and penalises large misses more heavily.
Its slope is , where measures the spread of x and measures how x and y vary together. The line always passes through the point of means , which gives the intercept .
How to use the Linear Regression Calculator
- Type the x values, separated by spaces or commas.
- Type the y values in the same order, so each y matches its x.
- Optionally enter an x value to predict y.
- Press Fit line.
- Read the regression equation, r, r² and any prediction.
Formulas
Slope
Intercept
Correlation coefficient
Slope from r
Worked example: Five points, predict at x = 6
The worked example uses the points (1, 2), (2, 4), (3, 5), (4, 4) and (5, 5). The means are and , with , and .
The slope is and the intercept is , so . The correlation is , and , so the line explains 60% of the variation in y.
The solution below is generated by the same engine that powers the calculator above.
Final answer
How we read your problem
Fit the straight line ŷ = a + bx that minimises the sum of squared vertical distances to the data, and measure how well it fits with r and r².
Step-by-step solution
Means of x and y
Sums of squares and cross-products about the means
Slope
Intercept: the line passes through the point of means
Regression line
Correlation and coefficient of determination
Moderate positive linear association; about 60% of the variation in y is explained by the line.
Predict y at x = 6
Formulas used
Slope
Intercept
Correlation
The slope is the predicted change in y for each one-unit increase in x. Correlation measures the strength of the linear pattern, not whether x causes y.
Verification
- The residuals sum to 0, as they must for a least-squares line.
Detailed explanation
Reading r and r²
The correlation coefficient r lies between −1 and 1. Its sign matches the slope, and its size shows how closely the points follow a straight line: values near ±1 indicate a tight linear pattern, values near 0 indicate little linear association. It has no units and does not change if x or y is rescaled.
The coefficient of determination r² is the fraction of the variation in y that the line accounts for. An r² of 0.6 means 60% of the variability in y is explained by its linear relationship with x, and 40% is left in the residuals.
Interpolation and extrapolation
Predictions for x values inside the range of the data are interpolation and are usually reasonable when the fit is good. Predictions outside that range are extrapolation, and they assume the straight-line pattern continues where no data were collected. The calculator flags extrapolation so you can judge it.
A growth chart fitted to children aged 2 to 10 might predict a height of over 2.5 metres at age 30, which shows how quickly an extrapolated line can stop making sense.
Correlation is not causation
A strong correlation shows that two variables move together, not that one causes the other. Both might be driven by a third, lurking variable: ice cream sales and drowning incidents both rise in hot weather. Only a controlled experiment can establish cause and effect.
It is also worth plotting the data. A curved pattern, a few outliers or two separate clusters can produce a misleading r, so look at a scatter plot and at the residuals before trusting a single number.
Common mistakes
- Listing the y values in a different order from the x values.
- Swapping x and y; regressing y on x is not the same as regressing x on y.
- Treating a high r as proof that x causes y.
- Trusting predictions far outside the range of the data.
- Fitting a line to data that clearly follow a curve.
Tips
- Plot the points first; the graphing calculator can show the line on top.
- Interpret the slope in context: the change in y for each extra unit of x.
- Check that the residuals show no pattern.
- Remove obvious data-entry errors, but do not delete real outliers without a reason.
- Use the mean and standard deviation calculators to check intermediate values.
Frequently asked questions
How do I find the line of best fit?
Compute the slope b = Sxy / Sxx and the intercept a = ȳ − b·x̄, then write ŷ = a + bx.
What is a good r² value?
It depends on the field. In physics experiments 0.99 is common; in social science an r² of 0.3 can be meaningful. Always read it in context.
What is the difference between r and r²?
r gives the direction and strength of the linear association; r² gives the share of variation in y explained by the line.
Why must the x values not all be equal?
If every x is the same, Sxx is 0, the slope is undefined and no line of the form y = a + bx fits.
Does the regression line pass through the mean point?
Yes. The least-squares line always passes through (x̄, ȳ).
How many data points do I need?
At least two, but a meaningful fit needs many more; with two points the line passes through both and r is always ±1.
Do the residuals always add up to zero?
Yes, for a least-squares line with an intercept, the residuals sum to exactly zero. The calculator reports this as a check.
Fit a regression line
Enter your paired data above to get the line of best fit, r and r² with every step.