Skip to main content
v2026.11,858 entries · CC-BY 4.0

Formula for Correlation Analysis: Pearson r Step by Step

The formula for correlation analysis (Pearson r) with every symbol explained, a worked negative-correlation example, APA reporting and Excel, R, Python code.

Written and maintained by CASRAI Editorial Board

Last updated

The formula for correlation analysis most people mean is Pearson’s correlation coefficient, r: the covariance of two variables divided by the product of their standard deviations. It returns a number between −1 and +1 that summarises how closely two quantitative variables follow a straight line together. This guide gives the formula with every symbol explained, a fully worked negative-correlation example you can check by hand, and the Excel, R and Python calls that reproduce it. For choosing between Pearson and other coefficients, see the correlation coefficient guide.

Definition in one paragraph

Correlation analysis measures the strength and direction of the association between two variables. A positive correlation means the variables tend to rise together; a negative correlation means one tends to fall as the other rises; a value near zero means no linear pattern. Pearson’s r measures only linear association between two quantitative variables. SciPy’s documentation states that correlations of −1 or +1 imply an exact linear relationship, and values near 0 indicate no correlation.

Formula for correlation analysis (Pearson r) with every symbol explained

Definitional form, as given in the SciPy documentation for scipy.stats.pearsonr:

r = Σ(xi − mx)(yi − my) / √[ Σ(xi − mx)2 · Σ(yi − my)2 ]

  • xi, yi: the paired observations for case i.
  • mx, my: the means of the x values and of the y values.
  • Σ: sum over all n pairs.
  • Numerator: the sum of cross-products of deviations. It is positive when the two variables sit on the same side of their means and negative when they sit on opposite sides. Divided by n−1 it is the sample covariance (see the covariance formula).
  • Denominator: the product of the two sums of squared deviations, square-rooted. It rescales the covariance so that r cannot leave the −1 to +1 range and does not depend on the units of measurement.

Computational form (algebraically equivalent, convenient on a calculator): r = [nΣxy − ΣxΣy] / √{[nΣx2 − (Σx)2][nΣy2 − (Σy)2]}. The worked example below uses both forms and they agree.

Worked example of a negative correlation, with the arithmetic shown

Take seven paired values: x = 1, 2, 3, 4, 5, 6, 7 and y = 10, 9, 2.5, 6, 4, 3, 2 (the same series used in SciPy’s pearsonr example). Here n = 7, Σx = 28, Σy = 36.5, so mx = 4 and my = 36.5/7 = 5.2143.

x y x − 4 y − 5.2143 Product (x − 4)2 (y − 5.2143)2
1 10 −3 4.7857 −14.3571 9 22.9031
2 9 −2 3.7857 −7.5714 4 14.3316
3 2.5 −1 −2.7143 2.7143 1 7.3673
4 6 0 0.7857 0.0000 0 0.6173
5 4 1 −1.2143 −1.2143 1 1.4745
6 3 2 −2.2143 −4.4286 4 4.9031
7 2 3 −3.2143 −9.6429 9 10.3316
Sums −34.5000 28 61.9286
  1. Denominator: √(28 × 61.9286) = √1734.0 = 41.64.
  2. r = −34.5 / 41.64 = −0.8285.
  3. Check with the computational form: Σxy = 111.5, Σx2 = 140, Σy2 = 252.25. Numerator = 7(111.5) − 28(36.5) = 780.5 − 1022 = −241.5. Denominator = √[(7×140 − 784)(7×252.25 − 1332.25)] = √(196 × 433.5) = √84,966 = 291.49. r = −241.5 / 291.49 = −0.8285. Same answer.
  4. Shared variance: r2 = 0.6864, so about 69% of the variance in y is linearly associated with x in this sample.
  5. Significance test: t = r√(n−2) / √(1−r2) = −0.8285 × √5 / √0.3136 = −3.308 with 5 degrees of freedom, giving a two-sided p = .021 (matching SciPy’s published value, 0.02128).

Interpretation: what the result means

What is a negative correlation, and what does a negative correlation mean?

A negative correlation is a coefficient below zero: higher values of one variable go with lower values of the other. In the example above, y falls as x rises, and r = −0.83. The sign gives direction only; it says nothing about whether the relationship is good, bad or causal. The same logic applies to any example of a negative correlation: as the price of an item rises, the quantity bought tends to fall; as altitude rises, air pressure falls. These are illustrations of direction, not computed results. A relationship can be negative without being a straight line (volume against pressure for a gas at constant temperature is an inverse curve), in which case Pearson’s r understates how tightly the variables are linked.

What is a strong correlation?

The most-quoted benchmarks come from Jacob Cohen’s Statistical Power Analysis for the Behavioral Sciences (2nd ed., 1988): |r| of about .10 is small, .30 medium and .50 large. Cohen advised avoiding these conventions where possible in favour of exact values drawn from theory or experience in the field, so what counts as strong is field-dependent.

Value of r Reading
−1 or +1 Exact linear relationship (SciPy documentation)
|r| ≥ .50 Large by Cohen’s conventions
|r| about .30 Medium by Cohen’s conventions
|r| about .10 Small by Cohen’s conventions
Near 0 No linear correlation (SciPy; Microsoft Support describes values closer to 0 as no or weak correlation)
Negative sign Variables move in opposite directions

In the worked example |r| = .83 is large by these conventions. See how to read a correlation matrix for reading many coefficients at once.

Correlation vs cause and effect

A correlation, even r = −.99, does not show that one variable causes the other; a third variable, reverse direction or chance can produce it. See correlation vs causation.

Correlation vs identity: a perfect correlation is not equal values

If y = 2x + 10 for every case, r = +1, yet y never equals x. Correlation measures how well one variable’s deviations track the other’s, not whether the values match. Because r is unaffected by adding a constant to a variable or multiplying it by a positive constant, it cannot detect a systematic offset between two measurements.

What test to use for correlation: Pearson or a rank correlation test

Use Pearson’s r for two quantitative variables with a roughly linear relationship and no extreme outliers. When the relationship is monotonic but not linear, the data are ordinal, or outliers dominate, use a rank correlation test: Spearman’s ρ applies the same formula to the ranks of the data. For the example above, Spearman’s ρ is −0.786 (p = .036). Step-by-step software guides: Pearson correlation in SPSS and Spearman rank correlation in SPSS.

Assumptions and common mistakes

  • Linearity. Plot the data first; r describes a straight-line pattern only.
  • Quantitative, paired data. Each case needs a value on both variables.
  • Outliers. One extreme pair can change r substantially, especially with a small n.
  • Significance test assumption. SciPy notes the default p-value assumes the data come from independent normal distributions, and that zero correlation implies independence only if the variables are jointly normal.
  • Zero spread. If either variable is constant, the denominator is zero and r is undefined; Excel returns #DIV/0! in that case (Microsoft Support).
  • Reading r as causation or as a percentage. r = .5 is not 50% agreement; r2 = .25 is the shared variance.

How to report it (APA example)

APA Style’s Numbers and Statistics Guide says to drop the leading zero for statistics that cannot exceed 1, such as correlations and p values, and to report correlations to two decimal places. For a Pearson correlation the degrees of freedom are n − 2. For the worked example: “There was a large negative correlation between x and y, r(5) = −.83, p = .021.” Details: APA Style Numbers and Statistics Guide (see Sources); see also the correlation coefficient guide.

How to calculate it in Excel, R or Python

Excel. With x in A2:A8 and y in B2:B8: =CORREL(A2:A8,B2:B8) returns −0.8285. Per Microsoft Support, text, logical values and empty cells are ignored while zeros are included; arrays with different numbers of points return #N/A; an empty array or zero standard deviation returns #DIV/0!.

R.

x <- 1:7
y <- c(10, 9, 2.5, 6, 4, 3, 2)
cor(x, y)                          # -0.8285
cor.test(x, y)                     # t = -3.308, df = 5, p = 0.0213
cor(x, y, method = "spearman")     # -0.786

Python.

from scipy import stats
x = [1, 2, 3, 4, 5, 6, 7]
y = [10, 9, 2.5, 6, 4, 3, 2]
r, p = stats.pearsonr(x, y)        # r = -0.8285, p = 0.0213
rho, p_s = stats.spearmanr(x, y)   # rho = -0.786, p = 0.0362

Frequently asked questions

What is the formula for correlation analysis?

Pearson’s r = Σ(x − mx)(y − my) divided by the square root of Σ(x − mx)2 times Σ(y − my)2.

What does a negative correlation mean?

As one variable increases, the other tends to decrease. In the worked example r = −.83.

What is a strong correlation?

By Cohen’s conventions, |r| of .50 or more is large; fields differ on what they treat as strong.

What test should I use for correlation?

Pearson for linear relationships between quantitative variables; Spearman’s rank correlation when the relationship is monotonic, the data are ordinal or outliers matter.

Sources

  • SciPy documentation, scipy.stats.pearsonr: docs.scipy.org (checked 2026-10-29).
  • Microsoft Support, CORREL function: support.microsoft.com (checked 2026-10-29).
  • Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences (2nd ed.). Lawrence Erlbaum Associates.
  • American Psychological Association, 7th Edition Numbers and Statistics Guide: apastyle.apa.org (checked 2026-10-29).
  • American Psychological Association (2020). Publication Manual of the American Psychological Association (7th ed.).

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Formula for Correlation Analysis: Pearson r Step by Step

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.