Linear Regression Calculator: Line of Best Fit, Correlation Coefficient and R Squared
Fit a straight line through your data and see how well it fits.
Engineering student calculators
Free textbook calculators with every step shown, so you can check your own working. Pick one, type in your numbers and see the formulas worked out. Or switch to Ask a question for an explained answer. No account needed.
Calculated from standard textbook formulas, with every step shown. The formulas are fixed, so the working does not need checking: what matters is the numbers you type in. Use these calculators only if you are competent to choose the inputs (loads, material strength, dimensions, supports) and check your units and assumptions. For learning and checking your own working: design and sign-off are for a qualified engineer. Drafting Central does not store the numbers you type.
How this calculator works
Set how many pairs of data you have and enter the x and y values.
Enter an x value to predict a y for.
The calculator gives the slope, the intercept, the correlation coefficient, R squared, the standard error of the estimate and the prediction, and draws the graph.
Formulas used
- m = \frac{\sum(x - \bar{x})(y - \bar{y})}{\sum(x - \bar{x})^2}
- c = \bar{y} - m\bar{x}
- r = \frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}
Worked example
With the default numbers in the calculator above:
- Means of x and y: 5.50 and 12.03 (10 points)
- Slope of the line of best fit: 2.00
- Intercept: 1.02
- The least squares line: y = 2.00 x + 1.02
- Correlation coefficient: 1.00
- R squared: the share of the variation in y explained by the line: 1.00 (99.95 percent)
- Standard error of the estimate: 0.14
- Prediction at the x you gave: 23.04 (outside the range of your data: this is extrapolation, which is less reliable)
Change the numbers in the calculator to see the full working, every step, for your own case.
Common questions
What is the line of best fit?
The straight line that makes the sum of the squares of the vertical distances from the points as small as possible.
What does R squared mean?
The share of the variation in y that is explained by the line. 1 is a perfect fit and 0 means no linear relation.
Does a high correlation prove cause?
No. Two things can move together without one causing the other.
Is predicting outside the data safe?
It is less reliable, because the pattern may not continue.
Related calculators
Got a question about this? Ask an engineering question and get a plain-language answer with references.
Further reading: Any first-year statistics text (simple linear regression).
Need a calculator we do not have?
Embed this calculator on your own page
Copy this code into your page. The calculator runs inside the frame and links back to Drafting Central.
Need this drawn, designed or checked?
Drafting Central is a mechanical engineering and drafting business working with customers across Australia and around the world. A calculator gives you the numbers; we can turn them into drawings and designs.
Need help with a real project?
Talk to Drafting Central →