Pearson Correlation Coefficient

Calculating Pearson Correlation Coefficient

1. What is Covariance?

Covariance measures the direction of the linear relationship between two variables—telling you whether they tend to move together (positive) or in opposite directions (negative) relative to their averages.

Because its value is tied to the original units of the data (such as "dollars times hours"), the raw number can range from negative infinity to positive infinity, making it impossible to judge the strength of the relationship on its own.

1.1 How to calculate Covariance?

The sample covariance formula is:

C o v ( x , y ) = ∑ i = 1 n ( x i − x ¯ ) ( y i − y ¯ ) n − 1

Where,

  • x i and y i : Individual data values for the i-th pair.
  • x ¯ and y ¯ : The sample means (averages) of x and y.
  • n: Total number of (x, y) data pairs.
  • ∑ i = 1 n : Summation symbol instructing you to add up the products for all pairs from 1 to n.

Note: For an entire population rather than a sample, replace n - 1 with N and use population means μ x and μ y .

2. What is correlation?

Correlation is a standardized version of covariance that measures both the direction and the strength of a linear relationship.

By dividing covariance by the spread (standard deviations) of both variables, it strips away the original units and locks the result onto a universal scale between -1 and +1, where values near ±1 mean a tight, predictable relationship and 0 means no linear link.

3. How to calculate Pearson Correlation Coefficent?

To find the Pearson correlation coefficient (r)—the standard measure of linear relationship between two variables—divide the covariance of x and y by the product of their standard deviations, which always gives a value between -1 and +1.