Fitting line...
Your regression result appears here
Submit paired data to get the fitted line, R-squared, correlation strength, residuals, prediction, and scatterplot.
How the Linear Regression Calculator Works
This least-squares linear regression calculator fits a straight line to paired x,y data. The line has the form y = mx + b, where m is the slope and b is the intercept. The calculator accepts one data pair per line, computes the fitted equation, and shows how well the line explains the variation in your y-values.
Linear regression is useful when the relationship between two numeric variables is approximately straight. Common examples include study time and test score, advertising spend and sales, temperature and energy use, or age and measured performance. A high R-squared value can be helpful, but it does not prove causation, and it does not guarantee that a straight line is the right model outside your observed data range.
Regression Diagram
The points are the observations. The fitted line is chosen so the squared vertical residuals are as small as possible.
Least-Squares Formula
For n paired observations, first calculate the means:
y-bar = sum(y) / n
Then calculate the centered sums:
Sxy = sum((x - x-bar)(y - y-bar))
The regression coefficients are:
intercept = y-bar - slope * x-bar
The calculator also computes residuals, sum of squared error, RMSE, correlation r, and R-squared. These values help you judge whether the line is a useful summary of the data.
Worked Example
| x | y | Predicted y | Residual |
|---|---|---|---|
| 1 | 2 | 2.2 | -0.2 |
| 2 | 3 | 3.1 | -0.1 |
| 3 | 5 | 4.0 | 1.0 |
| 4 | 4 | 4.9 | -0.9 |
| 5 | 6 | 5.8 | 0.2 |
For points (1,2), (2,3), (3,5), (4,4), and (5,6), the means are x-bar = 3 and y-bar = 4.
The centered sums are Sxx = 10 and Sxy = 9, so the slope is 9 / 10 = 0.9.
The intercept is 4 - 0.9 * 3 = 1.3, giving the fitted equation y = 0.9x + 1.3.
If x = 6, the predicted y-value is 0.9 * 6 + 1.3 = 6.7.
How to Interpret R-Squared and r
R-squared is the fraction of observed y variation explained by the fitted line. An R-squared of 0.82 means about 82% of the variation in y is explained by the linear model for the submitted dataset.
Correlation r describes direction and strength. Positive r means y tends to increase as x increases. Negative r means y tends to decrease as x increases. Values near -1 or +1 indicate a stronger linear association.
Both values can be misleading when the data are curved, contain influential outliers, combine unrelated groups, or use a prediction x-value far outside the observed range.
When Not to Use a Straight Line
- Use caution when a scatterplot visibly curves instead of following a roughly straight trend.
- Do not rely on regression for causal claims without study design, domain evidence, and confounder control.
- Avoid extrapolating far beyond the observed x-values unless you have outside evidence that the trend remains linear.
- Inspect residuals. Large patterns in residuals often mean the straight-line model is missing structure.
Related Calculators and References
Related tools
- Slope Calculator for a line through two points.
- Mean, Median, Mode Calculator for summary statistics.
- Standard Deviation Calculator for spread and variance.
- Z-Score Calculator for standardized values.
Linear Regression FAQ
What input format does the calculator accept?
Enter one point per line. Both comma-separated pairs such as 2, 5 and space-separated pairs such as 2 5 are accepted.
What does the slope mean?
The slope is the fitted change in y for a one-unit increase in x. A slope of 3 means the line increases by 3 y-units for every 1 x-unit.
Is R-squared always better when it is high?
Not always. A high R-squared can still come from outliers, grouped data, or a relationship that is not useful for prediction. Always inspect the scatterplot and residuals.
Can this calculator prove causation?
No. Linear regression measures association in the submitted data. Causation requires study design and domain evidence beyond the fitted equation.