SuperCalX

Line of Best Fit and R²: Choosing the Right Trend Line

By Dr. Ahmed Mortuza Saleque · Updated · How we check our content

The short answer

A line of best fit is the line that makes the squared vertical distances from the points as small as possible. R squared (R²) is the share of the variation in y that the line explains, from 0 to 1. In the example below, y = 4.48x + 46.9 has R² = 0.99. Pick the fit type that matches the shape of the data, not the highest R² alone.

Open the Data Plotter →
Scatter plot of study hours against test score with a linear line of best fit, equation y = 4.48x + 46.9 and R squared of 0.99
Tap the image to enlarge it. Free to share with a link to this page.

Worked example: the data

Eight students: hours of study and test score.

Hours studied (x)Test score (y)
152
255
361
464
570
672
779
883

Calculating the line of best fit

  1. Means: x̄ = 4.5 and ȳ = 67.0.
  2. Slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² = 188 ÷ 42 = 4.48 points per hour.
  3. Intercept = ȳ − slope × x̄ = 67.0 − 4.48 × 4.5 = 46.9.
  4. Line of best fit: score = 4.48 × hours + 46.9.
  5. R² = 0.992: the line explains 99.2% of the variation in scores.

Paste the two columns into the Data Plotter and choose Linear regression to get the same equation and R² drawn on the chart.

What R² does and does not tell you

  • R² does not prove cause. Ice cream sales and drownings correlate because both rise in summer.
  • A high R² can hide the wrong shape. Always look at the residual plot: a curve in the residuals means the model is wrong.
  • Adding polynomial terms always raises R², even when the extra wiggles are noise.
  • For a straight line, R² is the square of the correlation coefficient r. The correlation coefficient calculator gives r directly.

The Data Plotter labels fits with these bands.

R²LabelMeaning
Above 0.9ExcellentThe fit follows the data closely
0.7 to 0.9GoodClear trend with some scatter
0.5 to 0.7ModerateA trend, but much is unexplained
Below 0.5WeakThe model explains little

Choosing the fit type

FitEquationUse whenRequirement
Lineary = a + bxConstant rate of changeNone
Exponentialy = a·e^(bx)Growth or decay by a constant percentagey > 0
Logarithmicy = a + b·ln(x)Fast rise that levels offx > 0
Powery = a·x^bScaling laws, such as area and lengthx and y > 0
Polynomialy = a + bx + cx² …One or two bends, within the data rangeUse the lowest degree that works

Example: when linear is the wrong choice

A bacterial culture is counted every hour: 100, 135, 180, 245, 330, 445 and 600. A straight line gives R² = 0.94, which sounds good, but its residuals curve. An exponential fit, y = 99.8·e^(0.299x), gives R² above 0.999 and matches the biology: the count grows about 35% an hour and doubles every ln 2 ÷ 0.299 = 2.3 hours.

The Data Plotter's Model Comparison chart fits linear, polynomial, exponential, logarithmic and power models at once and ranks them by R², so you can see this in one click.

Common questions

How do you find the line of best fit?

Use least squares: slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², intercept = ȳ − slope × x̄. A plotting tool does this automatically.

What is a good R squared value?

It depends on the field. Physical experiments often exceed 0.95; social and biological data with R² of 0.3 to 0.6 can still be useful.

Can R squared be negative?

For a least-squares fit with an intercept, no. It can be negative when a model is forced through a point or judged on new data, meaning it predicts worse than the mean.

Should I extrapolate the line beyond my data?

Carefully. The fit is only checked within the data range; predictions far outside it, such as 20 hours of study, can be unrealistic.

Calculators for this article

More from the blog