[Home](https://learningfolio.de5.net/) / [Math](https://learningfolio.de5.net/math/) / [Math glossary](https://learningfolio.de5.net/math/glossary/) / Correlation Coefficient Formula: Calculate and Interpret Pearson r

[Math glossary](https://learningfolio.de5.net/math/glossary/)

# Correlation Coefficient Formula: Calculate and Interpret Pearson r

Calculate Pearson’s correlation coefficient from paired values, check the role of covariance, and interpret six worked examples.

Written by **Learningfolio Team**

We’re subject-matter experts in math, science, parent support, and education, with 100 years of combined experience. We believe in learning, experimenting, and growing, and we review one another’s work.

## On this page

* [TL;DR](https://learningfolio.de5.net/math/correlation-coefficient-formula/#tldr)
* [Key Points](https://learningfolio.de5.net/math/correlation-coefficient-formula/#key-points)
* [What is the Pearson correlation coefficient formula?](https://learningfolio.de5.net/math/correlation-coefficient-formula/#what-is-the-pearson-correlation-coefficient-formula)
* [How do you calculate r from a table or covariance?](https://learningfolio.de5.net/math/correlation-coefficient-formula/#how-do-you-calculate-r-from-a-table-or-covariance)
* [What do positive, negative, and zero correlation mean?](https://learningfolio.de5.net/math/correlation-coefficient-formula/#what-do-positive-negative-and-zero-correlation-mean)
* [When would you use a rank correlation instead?](https://learningfolio.de5.net/math/correlation-coefficient-formula/#when-would-you-use-a-rank-correlation-instead)
* [Worked Correlation Coefficient Examples](https://learningfolio.de5.net/math/correlation-coefficient-formula/#worked-correlation-coefficient-examples)
* [Mistakes That Change the Result](https://learningfolio.de5.net/math/correlation-coefficient-formula/#mistakes-that-change-the-result)
* [Try It Yourself](https://learningfolio.de5.net/math/correlation-coefficient-formula/#try-it-yourself)
* [Answers and Reasoning](https://learningfolio.de5.net/math/correlation-coefficient-formula/#answers-and-reasoning)
* [Frequently Asked Questions](https://learningfolio.de5.net/math/correlation-coefficient-formula/#frequently-asked-questions)
* [Conclusion](https://learningfolio.de5.net/math/correlation-coefficient-formula/#conclusion)
* [Read More](https://learningfolio.de5.net/math/correlation-coefficient-formula/#read-more)
* [Research Behind This Article](https://learningfolio.de5.net/math/correlation-coefficient-formula/#research-behind-this-article)

## TL;DR

**Pearson’s correlation coefficient measures the direction and strength of a linear relationship between paired values.** Divide the sum of paired deviation products by the geometric mean of the two sums of squared deviations.

## Key Points

* Pearson’s $r$ ranges from $-1$ to 1 and has no units.
* Pair the observations before subtracting each variable’s mean.
* A constant variable makes the denominator zero, so the coefficient is undefined.
* An $r$ near zero can coexist with a strong curved relationship.
* Read the scatter plot alongside the coefficient to check shape and influential points.

## What is the Pearson correlation coefficient formula?

For matched pairs $(x_i,y_i)$, let $\bar x$ and $\bar y$ be the arithmetic means. Write $d_{xi}=x_i-\bar x$ and $d_{yi}=y_i-\bar y$. Then

$$
r=\frac{\sum_i d_{xi}d_{yi}}{\sqrt{\sum_i d_{xi}^2}\sqrt{\sum_i d_{yi}^2}}.
$$

If deviations generally have the same sign, their products tend to be positive. If one variable is usually above its mean when the other is below, their products tend to be negative. The denominator scales for the variability of both variables. This gives a unitless quantity. [OpenStax, The Correlation Coefficient r](https://openstax.org/books/introductory-business-statistics/pages/13-1-the-correlation-coefficient-r)

![Four paired observations plot along an upward trend, with one point below the general pattern](https://learningfolio.de5.net/assets/versioned/correlation-paired-deviations-scatter.a9f7615a6667.webp)


The four points in Example 1 trend upward. They do not fall exactly on a line, so the correlation is below 1.

## How do you calculate r from a table or covariance?

1. Keep each observation paired with its corresponding value.
2. Find both means.
3. Calculate the two deviations, their product, and their individual squares for each pair.
4. Sum the three derived columns and put them into the formula.

If you already have the sample covariance $s_{xy}$ and the standard deviations $s_x,s_y$ calculated with the same sample convention, the equivalent expression is $r=s_{xy}/(s_xs_y)$. The factors of $n-1$ cancel. The [covariance matrix guide](https://learningfolio.de5.net/math/covariance-matrix/) shows how to compute those quantities from aligned measurements. [OpenStax, Correlation Analysis](https://openstax.org/books/principles-finance/pages/14-1-correlation-analysis)

## What do positive, negative, and zero correlation mean?

| Observed $r$ | Linear interpretation |
| --- | --- |
| Near 1 | The observed points tend to follow an increasing line |
| Near $-1$ | The observed points tend to follow a decreasing line |
| Near 0 | The coefficient shows little net linear association |
| Exactly 1 or $-1$ | All the points lie on one nonhorizontal line, with positive or negative slope |

A point far from the rest can move the coefficient substantially. A U-shaped relationship can give zero despite being predictable. The [scatter plot guide](https://learningfolio.de5.net/math/scatter-plot/) shows how to identify those patterns visually. A correlation alone cannot establish which variable influences another. Existing context and study design matter. [NIST, Scatter Plot](https://www.itl.nist.gov/div898/handbook/eda/section3/eda33q.htm)

There is no universal numerical boundary between “weak” and “strong.” The acceptable magnitude depends on the measurement context, sample, and use. Statistical significance is a separate calculation from the size of $r$.

## When would you use a rank correlation instead?

Use Pearson’s $r$ to describe a linear relationship between quantitative variables. **Spearman’s rank correlation** applies a correlation calculation to the ranks, so it can capture an increasing or decreasing pattern that follows a curve. **Kendall’s tau** uses the agreement or disagreement in pair ordering. Select the measure based on the question and how the values were measured. [CASRAI, Formula for Correlation Analysis](https://casrai.org/guides/formula-for-correlation-analysis)

Pearson’s coefficient is unchanged by adding a fixed amount to one variable or multiplying it by a positive constant. Multiplying one variable by a negative constant flips the sign. Replacing values with their ranks or transforming them nonlinearly can change more than the sign.

## Worked Correlation Coefficient Examples

### Example 1

Find $r$ for $x=(1,2,3,4)$ and $y=(2,4,3,7)$.

1. The means are 2.5 and 4.
2. The deviation products sum to $3+0-0.5+4.5=7$.
3. The sums of squared deviations are 5 and 14, giving $r=7/\sqrt{70}\approx0.837$.

### Example 2

Find the correlation between $(1,2,3)$ and $(7,5,3)$.

1. The points lie exactly on $y=9-2x$.
2. The line slopes downward, with no scatter around it.
3. The Pearson coefficient is $-1$.

### Example 3

What happens for $x=(-2,-1,0,1,2)$ and $y=x^2$?

1. The mean of $x$ is zero and the $y$ values are symmetric.
2. Equal and opposite $x$ values give opposite paired deviation products of equal magnitude.
3. Their sum is zero, so $r=0$. The two variables still follow an exact quadratic relationship.

### Example 4

Suppose a pair of measurements has correlation $r=0.65$. What happens if the first variable changes from metres to centimetres?

1. Every deviation of that variable is multiplied by 100.
2. The numerator and its square-root sum in the denominator both gain a factor of 100.
3. The ratio stays 0.65.

### Example 5

Find $r$ when $x=(4,4,4)$ and $y=(2,3,8)$.

1. Every $x$ deviation is zero.
2. The denominator therefore equals zero.
3. The coefficient is undefined. Zero correlation and undefined correlation are different results.

### Example 6

In a least-squares fit of one predictor with an intercept, $r=-0.7$. Find $R^2$.

1. In this setting, $R^2=r^2$ when the same data are used.
2. Squaring gives $0.49$.
3. The fit accounts for 49% of the observed variation about the mean under this calculation. Squaring removes the direction. The [least squares guide](https://learningfolio.de5.net/math/least-square-method/) explains the fitted line.

## Mistakes That Change the Result

### Mistake 1: Sorting the variables separately before calculating

The formula uses matched observations. Keep the pairings intact even if you reorder rows.

### Mistake 2: Treating zero correlation as proof of no relationship

A curved relationship can produce offsetting products. Check the scatter plot before concluding there is little association.

### Mistake 3: Confusing correlation with slope

Slope has units and changes when you rescale an axis. Pearson correlation is unitless. A slope of 2 does not imply an $r$ of 2.

## Try It Yourself

1. What is the correlation for exact pairs on the line $y=3x+2$, provided $x$ varies?
2. If $r=-0.4$ and all $y$ values are multiplied by $-1$, what is the new correlation?
3. Can you compute $r$ if all $y$ values are identical?

## Answers and Reasoning

1. The coefficient is 1 because the points lie on an increasing straight line.
2. The sign reverses, so $r=0.4$.
3. No. A constant $y$ makes the denominator zero.

## Frequently Asked Questions

### Can Pearson r exceed 1?

No. The magnitude of a dot product cannot exceed the product of the two vector lengths. An output outside the allowed range indicates a calculation error.

### Is r the same after switching x and y?

Yes. The product in the numerator and the product in the denominator are symmetric in the two variables.

### What is the difference between sample r and population correlation?

The sample coefficient $r$ describes sample data. Population correlation, often written $\rho$, describes the relationship in the population or probability model.

## Conclusion

* Use aligned pairs and subtract each variable’s own mean.
* Treat undefined values and zero correlations separately.
* Check the plot and the purpose of the analysis before interpreting the number.

## Read More

* [Understand the role of standard deviation in scaling](https://learningfolio.de5.net/math/standard-deviation-formula/)
* [Identify explanatory and response variables](https://learningfolio.de5.net/math/dependent-and-independent-variable/)

## Research Behind This Article

1. OpenStax, *Introductory Business Statistics: The Correlation Coefficient r*. [OpenStax](https://openstax.org/books/introductory-business-statistics/pages/13-1-the-correlation-coefficient-r)
2. OpenStax, *Principles of Finance: Correlation Analysis*. [OpenStax](https://openstax.org/books/principles-finance/pages/14-1-correlation-analysis)
3. NIST, *Engineering Statistics Handbook: Scatter Plot*. [NIST](https://www.itl.nist.gov/div898/handbook/eda/section3/eda33q.htm)
4. CASRAI, *Formula for Correlation Analysis: Pearson r Step by Step*. [CASRAI](https://casrai.org/guides/formula-for-correlation-analysis)
