How to use the correlation coefficient calculator
- Type or paste the x values and the y values in the same order, separated by spaces, commas or new lines. Or choose “Pairs, one per line” and paste two columns from a spreadsheet.
- Pick a two-tailed test, or a one-tailed test if you only care about a positive or a negative relationship.
- Read Pearson’s r, Spearman’s ρ and Kendall’s τ side by side, with their p-values, the confidence interval, r², the scatter plot and the steps. Everything updates as you type.
What a correlation coefficient measures
NIST’s Dataplot reference manual puts it plainly: “The correlation coefficient is a measure of the linear relationship between two variables.” It always lies between −1 and 1, and NIST adds that “a perfect linear relationship yields a correlation coefficient of +1 (or -1 for a negative relationship) and no linear relationship yields a correlation coefficient of 0.”
The sign gives the direction. In OpenStax’s words, “a positive value of r means that when x increases, y tends to increase and when x decreases, y tends to decrease.” A negative value means that y tends to fall as x rises. The size gives the strength: the closer r is to −1 or 1, the more tightly the points hug a straight line.
Pearson’s r and its formula
Pearson’s r compares how x and y vary together with how much each varies on its own. With the sums of squares about the means, Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ), the coefficient is r = Sxy / √(Sxx × Syy). The steps above show these sums for your data. Dividing Sxy by n − 1 gives the sample covariance, which has the same sign as r but depends on the units of x and y; r has no units, so it can be compared across data sets.
Is the correlation significant?
A correlation from a sample can differ from 0 by chance. The test asks whether the population correlation ρ is different from 0. OpenStax explains that “the p-value is calculated using a t-distribution with n - 2 degrees of freedom,” with the test statistic t = r√(n − 2) / √(1 − r²). In its third-exam and final-exam example, 11 students give r = 0.6631, and the calculator finds p = 0.02615, below 0.05, so the book concludes that the correlation is significant. The linear regression calculator fits the line for the same data.
The confidence interval for ρ uses Fisher’s z transformation, z = atanh(r), whose standard error is 1/√(n − 3). The interval is worked out on the z scale and turned back with tanh, so it stays between −1 and 1 and is lopsided when r is close to either end. You can also test r against a value other than 0, such as ρ₀ = 0.5, with the same transformation.
Spearman’s rank correlation
Spearman’s ρ is Pearson’s r applied to ranks instead of the raw values. NIST recommends a rank correlation “when the relationship between the two variables is not linear (however, it should still be either monotonically increasing or monotonically decreasing)” and “when the normality assumption for the two variables is not valid.” Each variable is ranked separately, and tied values share their average rank: in NIST’s example, “if the seventh and eighth ranks are the same value, both are replaced with 7.5.” The rank table above shows each value’s rank and the differences d.
With no ties, ρ = 1 − 6Σd² / (n(n² − 1)). For up to 9 pairs without ties, the calculator finds the exact p-value by counting every possible ordering of the ranks; for larger samples it uses a t approximation with n − 2 degrees of freedom.
Kendall’s tau
Kendall’s τ looks at every pair of points. NIST calls it “a measure of concordance between two paired variables”: a pair is concordant when the point with the larger x also has the larger y, and discordant when it has the smaller y. Kendall’s τ-b subtracts the discordant pairs from the concordant ones and divides by a total that allows for ties; NIST notes that τ-b “is preferred to Kendall’s tau-a when there are ties.” The p-value is exact for up to 33 pairs without ties and uses a normal approximation with a correction for ties otherwise.
Worked example: depth and dive time
OpenStax’s Table 12.4 lists the maximum time a SCUBA diver can stay down at each depth: 80 minutes at 50 feet, 55 at 60, 45 at 70, 35 at 80, 25 at 90 and 22 at 100 feet. Every extra 10 feet of depth shortens the time, so the order is perfectly reversed: Spearman’s ρ is −1.0000 and Kendall’s τ is −1.0000. Pearson’s r is −0.9629, strong but not −1, because the drop is steep at first and then levels off, so the points curve away from a straight line. That gap between r and the rank correlations is a sign of a curved relationship.
r² and how much is explained
Squaring r gives the coefficient of determination. OpenStax describes r² as the value that, “when expressed as a percent, represents the percent of variation in the dependent (predicted) variable y that can be explained by variation in the independent (explanatory) variable x using the regression (best-fit) line.” For the exam data, r² = 0.4397, or 44%: that share of the variation in final-exam scores goes with the third-exam scores, and the rest does not.
Look at the scatter plot first
A single number can hide a lot. OpenStax warns that “it is important to view the scatterplot, however, because data that exhibit a curved or horizontal pattern may have a correlation of 0.” One outlier can raise or lower r a great deal, two separate groups can create a correlation that exists in neither group, and a correlation never shows which variable, if either, causes the other.
In Excel, Google Sheets or R
Microsoft describes CORREL simply: “The CORREL function returns the correlation coefficient of two cell ranges.” Both ranges must be the same size, because “if array1 and array2 have a different number of data points, CORREL returns a #N/A error.” RSQ gives r², and COVARIANCE.S gives the sample covariance. In R, cor.test gives r with its p-value and confidence interval, and method = "spearman" or "kendall" gives the rank correlations. R documents that its Spearman p-values “are ‘exact’ for n < 10, and use an Edgeworth series approximation for larger sample sizes,” and it computes Kendall’s exact p-value for fewer than 50 pairs without ties, so for Spearman’s ρ with 10 or more pairs, and for Kendall’s τ with 34 to 49 pairs, R’s p-values can differ slightly from the ones here, which use the same approximations as Python’s SciPy.
Your data stays on your device
Everything is worked out in your browser. Nothing you type or paste is sent anywhere or stored.
Frequently asked questions
Which correlation coefficient should I use?
Use Pearson’s r for a straight-line relationship between two measured variables. Use Spearman’s ρ or Kendall’s τ when the relationship is curved but always rising or always falling, when the data are ranks, or when outliers or a skewed spread make r unreliable. Kendall’s τ handles many tied values well.
How do I paste data from Excel or Google Sheets?
Copy the x column and paste it into the x box, then do the same for y. Or choose “Pairs, one per line” and paste both columns at once; a first row of column names is skipped. Up to 10,000 pairs are accepted.
What does a p-value for a correlation mean?
It is the chance of a correlation at least this far from 0 if there were really no relationship in the population. A small p-value, such as below 0.05, means the correlation is unlikely to be due to chance alone.
Does a strong correlation mean x causes y?
No. Correlation only measures how closely two variables move together. A third variable, or chance in a small sample, can produce a strong correlation without any cause and effect between them.
Why are Spearman’s and Kendall’s values different from Pearson’s?
They use only the order of the values, not their size. A relationship that rises steadily but bends, like the dive-time data above, can have a rank correlation of exactly −1 or 1 while Pearson’s r is smaller.
Is my data uploaded?
No. Everything is worked out in your browser and nothing you type is sent anywhere or stored.