Skip to content
PercentPoint

Linear Regression Calculator

Paste paired x and y values to get the least-squares line of best fit, ŷ = a + bx, the correlation coefficient r, the coefficient of determination r², a test of whether the correlation is significant, and a prediction for any x, with a scatter plot of the data and the line.

For planning only. Your school, syllabus or accountant has the final word. First published · Last reviewed by PercentPoint.

How to use the linear regression calculator

  1. Enter the x values, the explanatory variable, separated by commas or spaces.
  2. Enter the y values, the response variable, in the same order, so the first x pairs with the first y. You need at least three pairs.
  3. Optionally, enter an x to predict. The “Predicted ŷ” card shows the line’s value there and warns when x is outside the range of your data.

The calculator opens on the textbook data from OpenStax’s Introductory Statistics 2e, section 12.3: third-exam scores (out of 80) and final-exam scores (out of 200) for 11 students. The line is ŷ = −173.51 + 4.83x with r = 0.6631.

The least-squares line

For each data point, the residual is the vertical distance between the observed y and the line’s prediction ŷ. The least-squares line is the one that makes the sum of the squared residuals (SSE) as small as possible. The textbook gives its slope and intercept:

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²    a = ȳ − b·x̄

Two consequences are worth knowing. The line passes through the point of means, (x̄, ȳ), which the “Means” card shows. And the slope can be written b = r × (sy ÷ sx), so it has the same sign as the correlation.

For the exam data, x̄ = 69.18 and ȳ = 160.45, and the slope is about 4.83. Interpreted in context, each extra point on the third exam goes with about 4.83 more points on the final, on average.

The intercept, −173.51, is the predicted final score for a third-exam score of 0. That value is far outside the data and makes no sense as a score; the intercept is often just a number that positions the line, without a real-world meaning of its own.

The correlation coefficient r

r measures how closely the points follow a straight line, on a scale from −1 to 1:

  • Close to 1: a strong positive linear relationship; y tends to rise with x.
  • Close to −1: a strong negative relationship; y tends to fall as x rises.
  • Close to 0: little or no linear relationship. There may still be a curved pattern, which r doesn’t detect.

The labels “strong”, “moderate” and “weak” in the result are rough guides, not formal cut-offs. Try the “Negative trend” and “No pattern” examples to see how r and the scatter plot change.

The textbook notes that strong correlation does not suggest that x causes y or y causes x: “correlation does not imply causation.” Ice-cream sales and drowning rates rise together in summer, but both follow the weather, not each other.

r² and what it explains

The coefficient of determination, r², is the square of r, usually stated as a percentage. It is the share of the variation in y that the line explains through x. For the exam data, r² = 0.6631² ≈ 0.4397: about 44% of the variation in final-exam scores is explained by third-exam scores using the line, and the other 56% is not, which shows up as the scatter of points around the line.

Is the correlation significant?

Even unrelated data give a nonzero r by chance, especially with few points. Section 12.4 tests whether r is far enough from 0 to conclude a linear relationship exists in the population. With a 5% significance level, compare r with the critical value for n − 2 degrees of freedom:

  • For the exam data, n = 11, so df = 9 and the critical values are ±0.602. Since 0.6631 > 0.602, r is significant, and the textbook concludes the line can be used for prediction.
  • In Example 12.7, r = 0.801 with 10 data points: df = 8, critical value 0.632, so r is significant.

The “Is r significant?” card does this comparison and also shows the equivalent p-value from the t test, t = r√(n − 2) ÷ √(1 − r²). A p-value below 0.05 matches |r| above the critical value.

Predicting, and when not to

To predict, substitute x into the equation. For a third-exam score of 73: ŷ = −173.51 + 4.83 × 73 ≈ 179 points on the final.

The textbook adds a warning: the third-exam scores in the data run from 65 to 75, so using the line for a score of 50 would be extrapolation, outside the range where the relationship was observed. The calculator labels such predictions “use with care”.

The standard error s = √(SSE ÷ (n − 2)) is the typical size of a residual, in y’s units. For the exam data it is about 16 points, a reminder that individual students land well above or below the line.

Check the scatter plot first

A single r can hide very different pictures: a clean line, a curve, two separate clusters, or one extreme point pulling the line toward it. Look at the scatter plot before trusting the numbers, and check that the points were entered in matching order. If the pattern bends, a straight line is the wrong model. If one point sits far from the rest, check it for an error, and compare the line with and without it. The textbook makes the same point about r: data with a curved pattern may have a correlation near 0, so view the scatter plot as well as the number.

Computing it by hand

  1. Find the means x̄ and ȳ.
  2. For each pair, compute x − x̄ and y − ȳ, their product, and (x − x̄)².
  3. Add the products to get Σ(x − x̄)(y − ȳ), and add the squares to get Σ(x − x̄)².
  4. Divide to get the slope b, then compute a = ȳ − b·x̄.
  5. For r, also add (y − ȳ)² and use r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² × Σ(y − ȳ)²).

A table with one row per pair keeps the arithmetic organized, and rounding only at the end avoids small errors in the slope and intercept. Graphing calculators do the same thing with their linear regression command; the textbook’s TI-83/84 output for the exam data shows a = −173.513, b = 4.8273, r² = 0.43969 and r = 0.663, matching the results here.

Sources & assumptions

How this calculator gets its numbers. Full method: our methodology.

  • Least squares: b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², a = ȳ − b·x̄; r is the Pearson correlation coefficient.
  • Significance: |r| is compared with the 95% critical value for df = n − 2 (two-tailed, α = 0.05).
  • Predictions outside the range of the x data are extrapolation and are flagged.

Sources

  1. OpenStax (Rice University), Introductory Statistics 2e, 12.3 The Regression Equation. Least-squares line ŷ = a + bx, r and r²; third exam vs final exam data (ŷ = −173.51 + 4.83x, r = 0.6631).
  2. OpenStax (Rice University), Introductory Statistics 2e, 12.4 Testing the Significance of the Correlation Coefficient. Testing r with df = n − 2 at α = 0.05; critical values ±0.602 for df 9 and ±0.632 for df 8.

Last reviewed . A strong correlation alone does not show that x causes y.

Frequently asked questions

How do I find the line of best fit?

Compute the slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and the intercept a = ȳ − b·x̄, then write ŷ = a + bx. The calculator does this for any list of pairs.

What is a good r value?

It depends on the field. Values near ±1 mean a tight linear pattern; whether a value is significant depends on the sample size, which the significance card checks.

What is the difference between r and r²?

r gives the direction and strength of a linear relationship. r² gives the share of the variation in y explained by the line, such as 44% for r = 0.6631.

Can I use the line to predict any value?

Only within the range of x values in your data. Predictions outside that range are extrapolation and may be badly wrong.

Does a strong correlation mean x causes y?

No. Both may be driven by a third factor, or the relationship may run the other way.

How many data points do I need?

At least three to fit a line and test r, but small samples need a large |r| to be significant: with 5 points the critical value is about 0.878.