Correlation Coefficient Calculator: Pearson r & Spearman

Four different data sets can share the same correlation coefficient, r = 0.816. In one the points sit around a straight line. In another they follow a smooth curve, a third is a perfect line spoiled by one stray point, and in the fourth a single far-off point produces almost all of the correlation. The statistician Francis Anscombe built these four sets in 1973 to show that a correlation coefficient means little until you look at the plot.

This calculator gives you both. Type two lists of paired values, and it works out Pearson’s r or Spearman’s ρ, r², the p-value, a 95% confidence interval and the best-fit line. It draws the scatter plot, shows every step, and flags any single point that is moving the result. It is set to the worked example below.

Correlation Coefficient Calculator

Separate values with commas, spaces or new lines (type 1200, not 1,200). To paste two columns from a spreadsheet, paste both into the X box and leave Y empty.

Correlation –
Scatter plot
Step by step

    What r Tells You, From −1 to +1

    The correlation coefficient measures how closely two variables follow a straight line together.

    • The sign gives the direction. A positive r means that as X goes up, Y tends to go up. A negative r means Y tends to go down.
    • The size gives the strength. r = +1 or −1 means every point lies exactly on a straight line. r = 0 means no straight-line pattern at all.

    There is no single official scale for “weak” or “strong”, and fields judge it differently: a correlation of 0.3 can be useful in social research but poor for two instruments measuring the same thing. As a rough guide, the calculator labels an r below 0.1 in size as little or no relationship, 0.1 to 0.3 as weak, 0.3 to 0.5 as moderate, 0.5 to 0.7 as fairly strong, 0.7 to 0.9 as strong and 0.9 or more as very strong. The labels describe the number; they are not a judgment about your study.

    r has no units. It comes out the same whether you measure in centimeters or inches, and swapping X and Y doesn’t change it.

    Working Out r by Hand: Eight Weeks of Ads and Sales

    A shop records its weekly advertising spend X (in hundreds of dollars) and the units it sells Y over eight weeks:

    WeekXYdx = X − x̄dy = Y − ȳdx × dydx²dy²
    1255−5.5−16.12588.687530.25260.0156
    2462−3.5−9.12531.937512.2583.2656
    3560−2.5−11.12527.81256.25123.7656
    4771−0.5−0.1250.06250.250.0156
    58700.5−1.125−0.56250.251.2656
    610792.57.87519.68756.2562.0156
    711843.512.87545.062512.25165.7656
    813885.516.87592.812530.25284.7656
    Sum00305.598980.875

    1. Find the means: x̄ = 60 ÷ 8 = 7.5 and ȳ = 569 ÷ 8 = 71.125.
    2. For each week, subtract the means to get dx and dy, then multiply them and square them.
    3. Add the columns: Sxy = 305.5, Sxx = 98 and Syy = 980.875.
    4. Divide: r = Sxy ÷ √(Sxx × Syy) = 305.5 ÷ √(98 × 980.875) = 0.9854.

    The products column shows why the formula works. When a week is above average on both X and Y, or below average on both, dx × dy is positive. Here nearly every week does that, so the sum is large and r lands close to +1. Week 5 is the only negative product, a week with slightly above-average spend and slightly below-average sales.

    The calculator shows this table for up to 25 pairs. For longer lists it shows the sums only.

    The pairing matters as much as the numbers. Each X must sit in the same position as its own Y. Sorting one list and not the other, or dropping a value from only one list, gives a meaningless r. The calculator refuses lists of different lengths for that reason.

    r² Is the Easier Number to Explain

    Squaring r gives the coefficient of determination, r². It is the share of the variation in Y that moves in step with X along the best-fit line.

    For the shop, r² = 0.9854² = 0.9709, so about 97% of the week-to-week variation in sales lines up with the spend. The best-fit line is ŷ = 47.7449 + 3.1173x: each extra $100 of advertising goes with about 3.1 more units sold.

    r² also shows how fast the strength drops. r = 0.7 sounds strong, but r² = 0.49 means less than half the variation is accounted for. At r = 0.3, it is only 9%.

    Don’t confuse r with the slope. The slope, 3.1173 here, is in the units of the data (units sold per $100) and changes if you measure in different units. r stays at 0.9854. The two are linked by slope = r × (SD of Y ÷ SD of X): a steep line can have a weak correlation if the points scatter widely around it, and a shallow line can have a strong one.

    Is the Correlation Real? The p-Value and the Confidence Interval

    A sample can show some correlation even when the two variables are unrelated in the wider population. The p-value tests that. The calculator converts r into t = r√(n − 2) ÷ √(1 − r²) with n − 2 degrees of freedom. For the shop, t = 14.153 with 6 degrees of freedom, and the two-tailed p-value is 7.771 × 10⁻⁶. A correlation this strong from 8 unrelated pairs would be extremely rare.

    The confidence interval says how precisely r is known. The calculator uses Fisher’s z transformation, and for the shop the 95% interval runs from 0.9183 to 0.9974.

    With small samples the interval is the more honest summary. Take r = 0.6:

    PairsTwo-tailed p95% confidence interval for r
    80.1158−0.181 to 0.917
    500.0000040.386 to 0.753

    With 8 pairs, an r of 0.6 is not significant, and the true correlation could be anything from slightly negative to very strong. With 50 pairs, the same r is clearly above zero and the range is far narrower. The p-value calculator does the same test if you already have r and n but not the raw data.

    One Point Can Make or Break r

    Pearson’s r is built from squared distances to the mean, so a single extreme point can dominate it. Take ten pairs:

    X: 1, 2, 3, 4, 5, 6, 7, 8, 9, 30 Y: 3, 1, 4, 2, 5, 3, 4, 2, 5, 30

    r = 0.958, which looks very strong. Remove the last pair, (30, 30), and r drops to 0.3928. The first nine points barely show a pattern; one far-off point drew the line.

    The calculator checks this for you. With 5 or more pairs, for each pair it works out what r would be without that pair. If removing one point changes r by 0.1 or more, it marks that point on the plot and says so. The point may be a real and important observation, but it could also be a typing error, and either way it shouldn’t go unnoticed.

    Pearson or Spearman?

    Pearson’s r measures a straight-line relationship using the values themselves. Spearman’s ρ (rho) replaces each value with its rank, 1 for the smallest, 2 for the next and so on, then runs the same formula on the ranks. Tied values share the average of their ranks: in the Y list above, the two 2s take ranks 2 and 3, so both get 2.5.

    Spearman fits two situations better:

    • Steady but curved relationships. For X = 1 to 8 and Y = 1, 2, 4, 8, 16, 32, 64, 128 (doubling each time), Pearson’s r is 0.8504 because the points curve away from a straight line. Spearman’s ρ is exactly 1, because every increase in X goes with an increase in Y.
    • Data with outliers or ranks. In the ten-pair example, Spearman’s ρ is 0.5522 against Pearson’s 0.958. The far-off point counts only as the largest rank, not as a value 25 units out.

    The calculator shows both numbers whichever one you pick. A large gap between them is worth a look at the plot.

    When r Is Near Zero but the Pattern Is Strong

    r = 0 means no straight-line relationship. It doesn’t mean no relationship. For X = −3, −2, −1, 0, 1, 2, 3 and Y = X² (9, 4, 1, 0, 1, 4, 9), Y is completely determined by X, yet r is exactly 0. The left half falls and the right half rises, and the two cancel out. Spearman’s ρ is 0 here too, because the pattern doesn’t keep going in one direction.

    This is the same lesson as Anscombe’s four data sets: always look at the scatter plot before reporting r. The calculator draws it next to every result, and it adds a reminder whenever r is close to zero.

    A Strong Correlation Doesn’t Show Cause

    Ice cream sales and drowning numbers rise and fall together over a year, but ice cream doesn’t cause drowning. Hot weather drives both. A correlation shows that two variables move together. It can’t tell you which affects which, or whether a third factor sits behind both.

    In the shop example, more advertising may well drive more sales. But the shop might also advertise more in weeks it already expects to be busy, such as before a holiday. The correlation alone can’t separate the two. Only a controlled comparison, such as changing the spend on a fixed schedule, can.

    Correlations are also sensitive to the range of the data. Over a narrow slice of X the same relationship can look much weaker, so compare correlations only across similar ranges.

    Getting the Same r in Excel or Google Sheets

    With X in A2:A9 and Y in B2:B9:

    What you wantFormulaResult for the shop
    Pearson’s r=CORREL(A2:A9, B2:B9) or =PEARSON(A2:A9, B2:B9)0.9854
    r²=RSQ(B2:B9, A2:A9)0.9709
    Slope of the best-fit line=SLOPE(B2:B9, A2:A9)3.1173
    Intercept=INTERCEPT(B2:B9, A2:A9)47.7449

    RSQ, SLOPE and INTERCEPT take Y first, then X. CORREL and PEARSON give the same r either way round.

    There is no built-in Spearman function. Rank each column first with =RANK.AVG(A2, $A$2:$A$9, 1), which gives ties their average rank, then apply CORREL to the two rank columns. For the shop data this gives ρ = 0.9524.

    To paste spreadsheet data into the calculator, copy both columns at once and paste them into the X box, leaving Y empty. It splits the pairs for you.