Linear regression calculator
Fit a straight line through paired data and see how well it fits. Students, scientists and analysts use it for lab data, trends and quick forecasts.
- Runs in your browser
- Free, no account needed
- Copy or download the result
Result
Example
1, 2.1 2, 3.9 3, 6.2 4, 7.8 5, 10.1
Equation: y = 1.99x + 0.05 Slope: 1.99 Intercept: 0.05 Correlation r: 0.998652 R squared: 0.997305 Points: 5, mean x 3, mean y 6.02 Predicted y at x = 6: 11.99
How to use the linear regression calculator
- Type x,y pairs in the box, one pair per line, such as 3, 6.2.
- Optionally fill in Predict y at x (optional).
- Press Run to see the equation, slope, intercept, r and r squared.
- Press Copy result or Download to keep the results.
How it works
The line is the ordinary least squares fit: slope = sum of (x - mean x)(y - mean y) / sum of (x - mean x)², and intercept = mean y - slope x mean x.
r is the Pearson correlation coefficient, and r squared is the share of the variation in y that the line explains.
Each line needs exactly two numbers separated by a comma, semicolon, tab or space. At least two different x values are required, and up to 5,000 pairs are allowed.
If every y value is the same, r and r squared are reported as not defined. Results are rounded to 12 significant digits.
Everything runs in your browser. Your input is not uploaded or stored.
Questions and answers
What is a line of best fit?
It is the straight line that makes the sum of squared vertical distances from the points to the line as small as possible.
What is the difference between r and r squared?
r shows the direction and strength of a straight line relationship, from -1 to 1. r squared is r times r and tells you the share of variation explained.
Can I use it to predict values?
Yes. Enter an x in Predict y at x (optional). Predictions far outside your data range are less reliable.