Line of Best Fit Calculator: Slope, Intercept, r and r² with the Working Table and Graph
Paste your x and y values and get the least-squares line of best fit y = a + bx, with the full Σx, Σy, Σxy and Σx² working table, the correlation r, r², a prediction for any x and a scatter plot. Ideal for matric, FSc, CBSE and first-year university statistics. Nothing is saved.
- PriceFree, no login or sign-up needed
- Your dataCalculated in your browser; nothing is saved
- Works onPhone, tablet or computer, any modern browser
- Made byDr. Muhammad Aammar Tufail, Codanics
- Published24 November 2026
- Last updated24 November 2026
📚 How to cite this tool
This tool is free. If it helped your thesis, paper, report or assignment, please cite it. It keeps the tools free and helps other students find them.
Tufail, M. A. (2026). Line of best fit calculator [Online tool]. Codanics. Retrieved 24 November 2026, from https://codanics.com/tools/line-of-best-fit-calculator/
In-text citation: (Tufail, 2026) · Narrative: Tufail (2026)
The access date is today’s date, filled in automatically. Author: Muhammad Aammar Tufail. Published 24 November 2026.
How to use the line of best fit calculator
- Paste your data with one x, y pair per line (for example hours studied and marks). Two columns copied from Excel work too.
- The slope, intercept, equation, r and r² appear instantly, with the Σx, Σy, Σxy and Σx² working table below.
- Type an x value to predict y from the line.
- Check the scatter plot: the points should follow a straight-line pattern for the line to make sense.
What is the line of best fit?
The line of best fit (least-squares regression line) is the straight line y = a + bx that makes the sum of the squared vertical distances from the points to the line as small as possible. The slope b tells you how much y changes for each 1-unit increase in x. The intercept a is the predicted y when x = 0.
Formulas for slope, intercept and r
These are the “by hand” formulas taught in Pakistani FSc/ICS and Indian Class 11–12 statistics. The calculator builds the same table you would draw on paper.
Worked example: hours studied vs marks
Eight students: hours = 1 to 8; marks = 52, 55, 61, 64, 68, 71, 77, 80.
| n | Σx | Σy | Σxy | Σx² | Σy² |
|---|---|---|---|---|---|
| 8 | 36 | 528 | 2,546 | 204 | 35,540 |
- b = (8 × 2,546 − 36 × 528) ÷ (8 × 204 − 36²) = 1,360 ÷ 336 = 4.0476
- a = 66 − 4.0476 × 4.5 = 47.7857
- Line: ŷ = 47.79 + 4.05x. Each extra hour adds about 4 marks.
- r = 0.9972 and r² = 0.9944: a very strong positive relationship; the line explains 99.4% of the variation.
- Prediction for 10 hours: 47.79 + 4.05 × 10 ≈ 88.3 marks (an extrapolation, so treat it with care).
How to interpret r
| |r| | Strength (rule of thumb) |
|---|---|
| 0.9 to 1.0 | Very strong |
| 0.7 to 0.9 | Strong |
| 0.5 to 0.7 | Moderate |
| 0.3 to 0.5 | Weak |
| below 0.3 | Very weak or none |
Common mistakes
- Correlation is not causation. A strong r does not prove x causes y.
- Extrapolation. Predictions far outside your x range can be badly wrong.
- Curved patterns. If the scatter plot bends, a straight line is the wrong model.
- Outliers. One extreme point can pull the line a long way. Look at the plot.
Frequently asked questions
How do you find the line of best fit?
Work out n, Σx, Σy, Σxy and Σx². Then slope b = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²) and intercept a = ȳ − b·x̄. The line is y = a + bx.
What does the slope of the line of best fit mean?
The slope is the average change in y for each 1-unit increase in x. A slope of 4.05 marks per hour means each extra hour of study goes with about 4 more marks.
What is the difference between r and r²?
r (from −1 to 1) shows the direction and strength of a straight-line relationship. r² (from 0 to 1) is the share of the variation in y explained by the line. r = 0.9 gives r² = 0.81, or 81%.
Is the line of best fit the same as linear regression?
Yes. The least-squares line of best fit is the simple linear regression of y on x.
How many data points do I need?
At least three, but more is better. With two points the line passes through both and r is always ±1, which tells you nothing.
Is my data saved or uploaded?
No. The calculation runs in your browser and nothing is saved or uploaded.
Do I need to log in or create an account to use the line of best fit calculator?
No. There is no login, no sign-up and no email required. Open the page and start using it straight away, for free, on any device.
How do I cite this tool in my thesis or paper?
Use the citation box on this page. In APA 7th edition: Tufail, M. A. (2026). Line of best fit calculator [Online tool]. Codanics. Retrieved [date you used it], from https://codanics.com/tools/line-of-best-fit-calculator/. BibTeX, RIS (EndNote, Mendeley, Zotero), MLA, Harvard, Chicago and Vancouver formats are also available.
Free guides and courses from Codanics
More free tools
See all free Codanics tools → · Codanics on YouTube · WhatsApp channel