A scatter diagram shows the direction of a relation, but one wants a single number that says how strong it is. Karl Pearson's coefficient of correlation provides this number and is the most widely used measure.

Definition and Formula

The Karl Pearson coefficient of correlation, denoted r, is the ratio of the covariance of x and y to the product of their standard deviations. It can be calculated from the deviations of the values from their means as r = sum of (dx × dy) divided by the square root of (sum of dx squared × sum of dy squared), where dx = x - mean of x and dy = y - mean of y.

Definition: Karl Pearson's coefficient of correlation. A measure of the strength and direction of the linear relationship between two quantitative variables, given by r = Cov(x, y) / (sx × sy), whose value lies between -1 and +1.

Properties of r

The value of r always lies between -1 and +1. A value of +1 means perfect positive correlation, and -1 means perfect negative correlation. A value near 0 means little linear relation. The coefficient is unchanged if a constant is added to every value or if every value is multiplied by a positive constant, which means it does not depend on the origin or scale. It is a pure number without units. Table 2.2 gives a rough guide to interpretation.

Table 2.2: Guide to interpreting r

Value of r Strength Direction
0.7 to 1 Strong Positive
0.3 to 0.7 Moderate Positive
-0.3 to 0.3 Weak or none None
-1 to -0.3 Moderate to strong Negative

Calculation

For the data of the last topic the calculation is laid out as in Table 2.3. The means are 6 and 65, and the sums are used in the formula.

Table 2.3: Calculation of r for hours of study (x) and marks (y)

x y dx dy dx x dy dx squared
2 50 -4 -15 60 16
4 55 -2 -10 20 4
6 65 0 0 0 0
8 70 2 5 10 4
10 85 4 20 80 16

Example 2.2: Calculating the coefficient of correlation

Problem: Find r for the hours of study and the marks given in the table. The sum of dy squared is 750.

Solution:

  1. The sum of dx × dy is 60 + 20 + 0 + 10 + 80 = 170.
  2. The sum of dx squared is 16 + 4 + 0 + 4 + 16 = 40.
  3. r = 170 / square root of (40 × 750) = 170 / 173.2.

Result: r = 0.98, a very strong positive correlation.

x = [2, 4, 6, 8, 10]
y = [50, 55, 65, 70, 85]
mx, my = sum(x) / 5, sum(y) / 5
sxy = sum((a - mx) * (b - my) for a, b in zip(x, y))
sxx = sum((a - mx) ** 2 for a in x)
syy = sum((b - my) ** 2 for b in y)
print(sxy, sxx, syy, round(sxy / (sxx * syy) ** 0.5, 4))

Output

170.0 40.0 750.0 0.9815

Common mistakes

  • Believing that r = 0.8 is twice as strong as r = 0.4. The scale is not proportional.
  • Using r for data in which the relationship is clearly curved.
  • Forgetting that r can be negative, and reporting only its size.

Key takeaways

  • r lies between -1 and +1.
  • r does not depend on the origin or scale of the variables.
  • r = sum of dx dy / square root of (sum dx squared x sum dy squared).
  • r measures only linear relationship.

Practice questions

  1. Between what values does r lie?
  2. What does r = -1 mean?
  3. Does r change if every value of x is increased by 10?

Answers to the practice questions

  1. Between -1 and +1.
  2. A perfect negative linear relationship.
  3. No, r does not depend on the origin.

Sources

  • Official BCA syllabus Probability and Statistics, course code 26BCA403DS01, Unit II