CalcOpenly

Correlation coefficient calculator (Pearson and Spearman)

Correlation coefficient calculator: Pearson's r or Spearman's rank correlation for paired data, with r², a t statistic and a two-sided p-value.

Updated Checked against 4 worked examples

Hours studied (default example).
Exam score for the same students, in the same order.
Try
Correlation coefficient
Correlation coefficient: 0.981638
Shown to up to 6 decimal places, half-up
Strength
Strong positive
Coefficient of determination r²
0.963613
t statistic
14.555426
Degrees of freedom
8
p-value (two-sided)
4.865 × 10⁻⁷
Pairs n
10

r = 0.9816 is a strong positive linear association; r² = 0.9636, so a straight line accounts for 96.36% of the variation in y. p = 4.86 × 10⁻⁷: if there were no correlation in the population, a sample of 10 pairs would show one at least this strong with that probability. Correlation alone does not show that one variable causes the other.

y against x

6070802468xy
PairsLeast-squares line
How it's calculated S
  1. Means

    xˉ=4.3,yˉ=66.8\bar x = 4.3,\quad \bar y = 66.8
  2. Sums of squares and cross-products

    Sxx=48.1,Syy=993.6,Sxy=214.6S_{xx} = 48.1,\quad S_{yy} = 993.6,\quad S_{xy} = 214.6
  3. Correlation

    r=SxySxxSyy=214.648.1×993.6=0.981638r = \frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}} = \frac{214.6}{\sqrt{48.1 \times 993.6}} = 0.981638
  4. Test statistic

    t=rn−21−r2=0.98163881−0.963613=14.555426t = r\sqrt{\frac{n-2}{1-r^2}} = 0.981638\sqrt{\frac{8}{1-0.963613}} = 14.555426
  5. Two-sided p-value

    p=2 P(T8>∣t∣)=4.86464×10−7p = 2\,P(T_{8} > |t|) = 4.86464 \times 10^{-7}

    Assumes the pairs are independent and roughly bivariate normal.

About the correlation coefficient calculator

Pearson's r measures how closely paired values follow a straight line: r = Sxy/√(Sxx·Syy), the sum of cross-products of deviations from the two means divided by the square root of the product of the two sums of squares. It runs from −1, a perfect falling line, through 0 to +1, a perfect rising line. Spearman's ρ is Pearson's r computed on the ranks, so it measures any steadily rising or falling trend and is less affected by outliers. The p-value comes from t = r√((n − 2)/(1 − r²)) with n − 2 degrees of freedom.

The default pairs hours studied with exam scores for 10 students: r = 0.9816, r² = 0.9636 and p = 4.9 × 10⁻⁷, a strong positive association.

A correlation near 0 rules out only a straight-line relationship: y = x² for x from −3 to 3 has r = 0 exactly.

Worked examples

Hours studied vs score (default)

x values
1, 2, 2, 3, 4, 5, 5, 6, 7, 8
y values
52, 55, 61, 58, 66, 70, 68, 75, 79, 84
Coefficient
Pearson r
Correlation coefficient
0.981638
Coefficient of determination r²
0.963613
t statistic
14.555426
Degrees of freedom
8
p-value (two-sided)
4.865 × 10⁻⁷
Strength
Strong positive

Checked against: Python fractions for Sxx, Syy, Sxy with a decimal square root; p from the closed-form Student t CDF for integer df (Abramowitz & Stegun 26.7.4)

Negative association

x values
10, 20, 30, 40, 50, 60
y values
8.1, 7.4, 7.9, 6.2, 5.8, 6.0
Coefficient
Pearson r
Correlation coefficient
-0.891042
t statistic
-3.925982
p-value (two-sided)
0.017161
Strength
Strong negative

Checked against: Python fractions with decimal square roots; p = 2·(1 − F_t(|t|; 4)) from the A&S 26.7.4 closed form

Spearman with tied ranks

x values
1, 2, 2, 3, 4, 5, 5, 6
y values
3, 1, 4, 4, 5, 9, 2, 6
Coefficient
Spearman ρ
Correlation coefficient
0.575768
t statistic
1.724946
p-value (two-sided)
0.135297
Degrees of freedom
6
Strength
Strong positive

Checked against: Python: ties averaged by hand (x ranks 1, 2.5, 2.5, 4, 5, 6.5, 6.5, 8), Pearson r of the ranks with fractions (Sxy = 95/4, Sxx = 41, Syy = 83/2), p from the A&S 26.7.4 t CDF

Perfect straight line

x values
1, 2, 3, 4
y values
3, 5, 7, 9
Coefficient
Pearson r
Correlation coefficient
1
Coefficient of determination r²
1
p-value (two-sided)
0
Strength
Strong positive

Checked against: y = 2x + 1 exactly, so r = 1 by definition and no sample could be more extreme

Questions

What does a correlation coefficient of 0.7 mean?

A fairly strong positive linear association: as x rises, y tends to rise, and r² = 0.49 says a straight line accounts for 49% of the variation in y. Cohen (1988) called r = 0.1 small, 0.3 medium and 0.5 large, and the Strength output uses those cut-offs. They are rough conventions from the behavioural sciences, so what counts as strong still depends on the field.

What is the difference between Pearson and Spearman correlation?

Pearson's r measures linear association using the values themselves; Spearman's ρ applies the same formula to their ranks, so it measures any monotonic trend. For y = x³ with x from 1 to 10, Spearman gives exactly 1 but Pearson gives 0.928. Spearman also resists outliers and suits ordinal data such as ratings, while Pearson's r is the one that matches a least-squares line.

Does correlation imply causation?

No. A correlation shows that two variables move together, not why. A third variable can drive both, as hot weather raises both ice-cream sales and drownings. The cause can also run the other way, or the pattern can be chance: test 20 unrelated pairs at α = 0.05 and about one will look significant. Showing cause takes a randomized experiment or a careful causal design.

How do you test whether a correlation is significant?

Convert r to t = r√((n − 2)/(1 − r²)) and compare it with a t distribution with n − 2 degrees of freedom. The default data give r = 0.9816 with n = 10, so t = 14.56 on 8 df and p = 4.9 × 10⁻⁷. Significance depends heavily on n: with 1,000 pairs, r = 0.07 already gives p = 0.027, although it explains under 0.5% of the variation.

How accurate is the correlation coefficient calculator?

Accuracy depends on your inputs and the method's assumptions. Decimal arithmetic uses 50 significant digits, but estimates, numerical methods and source data can be less precise; the displayed rounding does not remove those limits. It is checked against 4 worked examples whose answers come from independent sources; for example, “Hours studied vs score (default)” is checked against Python fractions for Sxx, Syy, Sxy with a decimal square root; p from the closed-form Student t CDF for integer df (Abramowitz & Stegun 26.7.4).

Where does the method come from?

NIST/SEMATECH e-Handbook of Statistical Methods, §7.1.3 / Dataplot CORRELATION (Pearson and rank correlation); Spearman (1904), The proof and measurement of association between two things, American Journal of Psychology 15; Cohen (1988), Statistical Power Analysis for the Behavioral Sciences, 2nd ed., §3.2 (r = 0.1, 0.3, 0.5).

About this calculator

r=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2∑(yi−yˉ)2,t=rn−21−r2r = \frac{\sum (x_i-\bar x)(y_i-\bar y)}{\sqrt{\sum (x_i-\bar x)^2 \sum (y_i-\bar y)^2}},\qquad t = r\sqrt{\frac{n-2}{1-r^2}}

Sources

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §7.1.3 / Dataplot CORRELATION (Pearson and rank correlation)
  2. Spearman (1904), The proof and measurement of association between two things, American Journal of Psychology 15
  3. Cohen (1988), Statistical Power Analysis for the Behavioral Sciences, 2nd ed., §3.2 (r = 0.1, 0.3, 0.5)

Checked against references

4 worked examples with independently sourced answers ship with this calculator. They run in the test suite; you can run them here too.

Related calculators

Allow optional Google Analytics to measure page visits? Calculators work either way. Privacy and choices

Optional analytics: off.