Everyday tool

Linear Regression and Correlation Calculator

Enter at least two numeric x,y pairs, one per line or separated by commas.

Runs in your browser. No upload.

Values are processed locally in this browser.

Result

—

About this tool

Linear Regression and Correlation Calculator made simple.

This is descriptive linear regression. Correlation does not establish causation, and the fit may be misleading for nonlinear or dependent data.

Guide

Using Linear Regression and Correlation Calculator

The Linear Regression and Correlation Calculator draws the best-fitting straight line through a list of x and y pairs. You paste your pairs, one per line, and the tool gives the equation of the least-squares line, the Pearson correlation r, R squared and the number of pairs. It describes the data you typed. It does not test whether a pattern is real, it does not predict the future, and it cannot tell you that one thing causes another.

How to use it

  1. Type or paste your data in the box, one x,y pair per line, for example 3, 7. A comma or a space can separate the two numbers.
  2. Use at least 2 pairs and at most 10,000. You can also separate pairs with a semicolon instead of a new line.
  3. Make sure the x values are not all the same number, or the tool cannot draw a line.
  4. Press Calculate. Read the line y = slope times x plus intercept, then r, R squared and the pair count.
  5. Use Copy result to keep the four lines, or Clear to empty the box.

Worked examples

Three points on a perfect line

You enter
Pairs
0, 1 1, 3 2, 5
You get
Line
y = 2x + 1
R
1
R squared
1
Pairs
3

Each step of 1 in x adds 2 to y, and the line passes through y = 1 at x = 0. Every point sits exactly on the line, so r and R squared are both 1.

Run through the tool’s own code.

Five points with some scatter

You enter
Pairs
1, 2 2, 4 3, 5 4, 4 5, 5
You get
Line
y = 0.6x + 2.2
R
0.774597
R squared
0.6
Pairs
5

The means are 3 for x and 4 for y. The sums are 6 for the cross products, 10 for x and 6 for y, so the slope is 6 / 10 = 0.6 and r is 6 divided by the square root of 60.

Run through the tool’s own code.

A line that goes down

You enter
Pairs
1, 10 2, 8 3, 7 4, 3
You get
Line
y = -2.2x + 12.5
R
-0.964764
R squared
0.930769
Pairs
4

As x rises, y falls, so the slope and r are negative. R squared has no sign. It is the square of r, here 0.930769.

Run through the tool’s own code.

All y values are the same

You enter
Pairs
1, 5 2, 5 3, 5
You get
Line
y = 0x + 5
R
0
R squared
0
Pairs
3

The line is flat at 5. The tool shows r as 0 here, although correlation is not really defined when y never changes. Treat that 0 as a missing value.

Run through the tool’s own code.

When it helps

  • Fit a trend line to a small lab or science-class data set and read the slope.
  • Check how closely two columns from a spreadsheet move together.
  • Check homework that asks for a least-squares line and a correlation.
  • Get quick numbers to describe a scatter plot in a report.
  • Compare two small data sets by their slope and r.

Limits to keep in mind

  • You need 2 to 10,000 pairs, each with exactly two numbers. A single line such as 1,2,3,4 is refused, even though the page text says commas can separate pairs.
  • If every x is the same, the tool stops with an error, because the slope would be undefined.
  • If every y is the same, the tool shows r as 0 and R squared as 0, although correlation is undefined in that case.
  • The results are rounded to six decimals. The tool gives no p-value, no confidence interval, no residual list and no chart.
  • It fits only a straight line and treats every point equally. A curve, a group effect or one far-out point can make the line misleading.

Tips

  • Plot your data in a chart first. If the points curve, a straight line is the wrong shape.
  • With only 2 points, r is 1 or -1 (or 0 if both y values match), so use more points before you read anything into it.
  • Check for one extreme point by removing it and calculating again to see how much the line moves.
  • Keep the x and y columns in the same order on every line.

Sources

Common questions

About Linear Regression and Correlation Calculator.

What formulas does this calculator use?

It finds the mean of x and of y, then sums the squared x gaps (Sxx), the squared y gaps (Syy) and the products of the gaps (Sxy). The slope is Sxy divided by Sxx, the intercept is mean y minus slope times mean x, and r is Sxy divided by the square root of Sxx times Syy.

What does the correlation r tell me?

It runs from -1 to 1. A positive r means y tends to rise with x, a negative r means y tends to fall, and a value near 0 means a straight line describes the points poorly. It measures a straight-line pattern only.

What does R squared mean?

In a fit with one x, R squared is r squared. It is the share of the ups and downs in y that the straight line accounts for in your data, between 0 and 1. It describes the fit, not the reason behind it.

Does a high R squared prove that x causes y?

No. Two things can move together because of a third factor, by chance, or because the cause runs the other way. A high R squared says the points hug a line. It does not say why. To argue for a cause you need a careful study design.

How should I type my data?

Put one pair per line, with the x value first and the y value second, separated by a comma or a space. A semicolon also separates pairs. Use plain numbers with a dot for decimals, and no units or text.

Why do two points give r of 1 or -1?

Two points always lie exactly on one straight line, so the fit is perfect whatever the numbers are. If both y values match, the tool shows 0 instead. Such a result says nothing about a real pattern, so use more points first.

Why does it say the x values must not all be identical?

If every x is the same, the points stand on a vertical line. A line of the form y = slope times x plus intercept cannot describe that, because the slope would need a division by zero.

Will the line work for curved data or outliers?

It will give numbers, but they can mislead. A curve, separate groups or one very far point can pull the line away from the rest. Look at a scatter plot, and think about your data before you rely on the fit.

Is my data uploaded?

No. The calculation runs in your browser, and the pairs you type are not uploaded.

How do I use Linear regression calculator?

Enter at least two numeric x,y pairs, one per line or separated by commas.

Is my data uploaded to a server?

No. This tool runs locally in your browser. Your input is not uploaded.