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.

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 rr ranges from −1-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 rr 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 (xi,yi)(x_i,y_i), let x¯\bar x and y¯\bar y be the arithmetic means. Write dxi=xi−x¯d_{xi}=x_i-\bar x and dyi=yi−y¯d_{yi}=y_i-\bar y. Then

r=∑idxidyi∑idxi2∑idyi2.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

Four paired observations plot along an upward trend, with one point below the general pattern
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 sxys_{xy} and the standard deviations sx,sys_x,s_y calculated with the same sample convention, the equivalent expression is r=sxy/(sxsy)r=s_{xy}/(s_xs_y). The factors of n−1n-1 cancel. The covariance matrix guide shows how to compute those quantities from aligned measurements. OpenStax, Correlation Analysis

What do positive, negative, and zero correlation mean?

Observed rr Linear interpretation
Near 1 The observed points tend to follow an increasing line
Near −1-1 The observed points tend to follow a decreasing line
Near 0 The coefficient shows little net linear association
Exactly 1 or −1-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 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

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 rr.

When would you use a rank correlation instead?

Use Pearson’s rr 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

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 rr for x=(1,2,3,4)x=(1,2,3,4) and y=(2,4,3,7)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=73+0-0.5+4.5=7.
  3. The sums of squared deviations are 5 and 14, giving r=7/70≈0.837r=7/\sqrt{70}\approx0.837.

Example 2

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

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

Example 3

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

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

Example 4

Suppose a pair of measurements has correlation r=0.65r=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 rr when x=(4,4,4)x=(4,4,4) and y=(2,3,8)y=(2,3,8).

  1. Every xx 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.7r=-0.7. Find R2R^2.

  1. In this setting, R2=r2R^2=r^2 when the same data are used.
  2. Squaring gives 0.490.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 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 rr of 2.

Try It Yourself

  1. What is the correlation for exact pairs on the line y=3x+2y=3x+2, provided xx varies?
  2. If r=−0.4r=-0.4 and all yy values are multiplied by −1-1, what is the new correlation?
  3. Can you compute rr if all yy 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.4r=0.4.
  3. No. A constant yy 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 rr 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

Research Behind This Article

  1. OpenStax, Introductory Business Statistics: The Correlation Coefficient r. OpenStax
  2. OpenStax, Principles of Finance: Correlation Analysis. OpenStax
  3. NIST, Engineering Statistics Handbook: Scatter Plot. NIST
  4. CASRAI, Formula for Correlation Analysis: Pearson r Step by Step. CASRAI