How to use the Line of Best Fit Calculator
- Paste two columns of numbers, X first and Y second. The first row can hold the column names.
- Read the equation, slope, intercept and R² in the results panel. They update as you type.
- Enter an x value to predict y, or a y value to find x.
- Open “Fitted values and residuals” to check how far each point is from the line.
What the calculator computes
It fits the straight line that minimises the sum of the squared vertical distances between your points and the line, which is the ordinary least-squares line of best fit. The slope is the sum of (x − mean x)(y − mean y) divided by the sum of (x − mean x)², and the intercept is mean y minus the slope times mean x, so the line always passes through the centre of the data.
Beyond the equation you get the standard error of the slope and intercept, with 95% confidence intervals from Student’s t distribution, the correlation r, R², and the standard error of the estimate. Those uncertainties are what turn “the slope is 4.35” into “the slope is 4.35 ± 0.12”, which is what a lab report or a paper needs.
Worked example: hours studied and exam score
The sample is ten students: hours studied from 1 to 10 and the score each earned. The calculator returns y = 4.352x + 47.27, with R² = 0.9940. In plain words, each extra hour of study goes with about 4.4 more marks, and a student who studied zero hours would be predicted to score about 47. Asking for x = 11 predicts a score of about 95.1.
That prediction carries a warning: 11 hours is outside the data (1 to 10), so it is an extrapolation. The calculator flags this, because lines rarely keep going. A score cannot pass 100, so the straight line must bend somewhere.
| Result | Value | Meaning |
|---|---|---|
| Slope | 4.352 | Marks gained per extra hour |
| Intercept | 47.27 | Predicted score at 0 hours |
| R² | 0.9940 | 99.4% of the variation in scores is explained by hours |
| Std. error of estimate | 1.08 | Typical miss of about one mark |
Reading the results correctly
A line of best fit describes a relationship; it does not prove one variable causes the other. Check the chart for curvature, and the residuals for patterns: if the residuals are all positive in the middle and negative at the ends, the data are curved and a straight line is the wrong model. A single point far from the others can also tilt the line, so look for outliers before trusting the slope.
The standard error of the estimate is in the units of y and tells you how large the typical miss is, which R² does not. The guide to line of best fit and R² explains these checks, and the scatter plot maker draws the same fit as a publication-quality figure.
Doing it by hand or in Excel
To check the calculator, compute the two means, then Sxx = Σ(x − x̄)² and Sxy = Σ(x − x̄)(y − ȳ). For the sample data x̄ = 5.5, ȳ = 71.2, Sxx = 82.5 and Sxy = 359, so the slope is 359 / 82.5 = 4.352. In Excel use =SLOPE(y_range, x_range), =INTERCEPT(y_range, x_range) and =RSQ(y_range, x_range); note that the Y range comes first. The trendline guide shows the chart method as well.
Frequently asked questions
- How do I find the line of best fit?
- Calculate the slope as Sxy / Sxx and the intercept as mean y minus slope times mean x, or paste your data into this calculator, which does it instantly and shows the uncertainties.
- What is the difference between R and R²?
- r is the correlation coefficient, from −1 to 1, and shows direction. R² is r squared, from 0 to 1, and is the fraction of variation in y explained by the line.
- How many points do I need?
- At least three for uncertainties to exist, and ideally ten or more. With two points a line always fits perfectly, which says nothing.
- Can I force the line through zero?
- This calculator fits the intercept, which is the safer default. Forcing a zero intercept changes the slope and inflates R², so only do it when the physics demands it.
- Is my data private?
- No. The calculation runs in your browser, so the numbers you enter are never sent to a server.
Guides that go with this tool
Last updated: · by Dev Patel ·Read our guides