In statistics, covariance is used widely to find the relation among the prices or data. It works jointly with two random variables. More precisely, it is used to express the relation between two variables. In probability and statistics, covariance is used on a larger scale to calculate a change in the given variables.

In this post, we will go through the definition, formulas, and calculations of covariance with some examples.

What is covariance?

To measure the relationship among two variables, we use a statistical tool known as covariance. These variables decide whether the covariance is positive or negative. A covariance is said to be a positive covariance if a rise in one variable causes a rise in the other variable.

The reduction in one variable causes a reduction in another variable is also referred to as a positive covariance. On the other hand, a rise in one variable causes a reduction in the other variable, or reducing one variable increases the other variables are known as the negative covariance.

The movements of the variables depend on the values of the covariance. The movement of both variables is the same if the covariance is positive. While the movement of both variables is opposite if the covariance is negative.

Formulas of Covariance

Covariance is measured in units and follows a statistical formula. It is usually used to measure the relationship among variances. It is denoted by Cov (x, y). The general equations to find the covariance using two variables for population covariance or sample covariance are given below.

Population covariance = Cov (x, y) = Σ (x – µ1) (y – µ2)/N

In the above formula, x and y are two variables, µ is the population mean of x and y, and N is the total number of observations.

Sample covariance = Cov (x, y) = Σ (x – x¯) (y – y¯)/n – 1

In the above equation, x and y are two variables, x¯ and y¯ are the sample mean of x and y, and n is the total number of observations.

**How to calculate Covariance?**

Covariance can be calculated by using formulas. To calculate covariance, let us use some examples of sample and population covariance.

Example 1: For population covariance

Find the population covariance of the given population data, x = 1, 7, 14, 18, 23, 26, and 30 and y = 2, 9, 17, 31, 37, 43, and 50?

Solution

Step 1: Write the given two population data.

x = 1, 7, 14, 18, 23, 26, 30

y = 2, 9, 17, 31, 37, 43, 50

Step 2: Now find the sample mean “µ1” for random variable x.

Sum of population data of x = 1 + 7 + 14 + 18 + 23 + 26 + 30

Sum of population data of x = 119

Total number of observations of x = N = 7

Sample mean of x = µ1 = Sum of sample data / Total number of observations

Sample mean = µ1 = 119/7 = 17

Step 3: Now find the sample mean “µ2” for random variable y.

Sum of population data of y = 2 + 9 + 17 + 31 + 37 + 43 + 50

Sum of population data of y = 189

Total number of observations of y = N = 7

Sample mean of y = µ2 = Sum of sample data / Total number of observations

Sample mean = µ2 = 119/7 = 27

Step 4: Now find the differences of the observations from the mean and find the product.

x y x – µ1 y – µ1 (x – µ1) (y – µ2)

1 2 1 – 17 = -16 2 – 27 = -25 (-16) (-25) = 400

7 9 7 – 17 = -10 9 – 27 = -18 (-10) (-18) = 180

14 17 14 – 17 = -3 17 – 27 = -10 (-3) (-10) = 30

18 31 18 – 17 = 1 31 – 27 = 4 (1) (4) = 4

23 37 23 – 17 = 6 37 – 27 = 10 (6) (10) = 60

26 43 26 – 17 = 9 43 – 27 = 16 (9) (16) = 144

30 50 30 – 17 = 13 50 – 27 = 23 (13) (23) = 299

Σ x = 119 Σ y = 189 Σ (x – µ1) (y – µ2) = 1117

Step 5: Now take the general population covariance formula for population data.

Population covariance = Cov (x, y) = Σ (x – µ1) (y – µ2)/N

Step 6: Put the sum of square and number of observations in the above formula.

Cov (x, y) = Σ (x – µ1) (y – µ2)/N

Cov (x, y) = 1117/7

Cov (x, y) = 159.5714

Example 2: For sample covariance

Find the sample covariance of the given sample data, x = 7, 13, 19, 33, 47, 49, and 56 and y = 12, 14, 16, 18, 23, 25, and 39?

Solution

Step 1: Write the given two sample data.

x = 7, 13, 19, 33, 47, 49, 56

y = 12, 14, 16, 18, 23, 25, 39

Step 2: Now find the mean for random variable y.

Sum of sample data of x = 7 + 13 + 19 + 33 + 47 + 49 + 56

Sum of sample data of x = 224

Total number of observations = n = 7

The sample mean = Sum of sample data / Total number of observations

Sample mean of x = 224/7 = 32

Step 3: Now find the mean for random variable y.

Sum of sample data of y = 12 + 14 + 16 + 18 + 23 + 25 + 39

Sum of sample data of y = 147

Total number of observations = n = 7

The sample mean = Sum of sample data / Total number of observations

Sample mean of y = 147/7 = 21

Step 4: Now find the differences of the observations from the mean and find the product.

x y x – x¯ y – y¯ (x – x¯) (y – y¯)

7 12 7 – 32 = -25 12 – 21 = -9 (-25) (-9) = 225

13 14 13 – 32 = -19 14 – 21 = -7 (-19) (-7) = 133

19 16 19 – 32 = -13 16 – 21 = -5 (-13) (-5) = 65

33 18 33 – 32 = 1 18 – 21 = -3 (1) (-3) = -3

47 23 47 – 32 = 15 23 – 21 = 2 (15) (2) = 30

49 25 49 – 32 = 17 25 – 21 = 4 (17) (4) = 68

56 39 56 – 32 = 24 39 – 21 = 18 (24) (18) = 432

Σ x = 221 Σ y = 143 Σ (x – x¯) (y – y¯) = 950

Step 5: Now take the general population covariance formula for population data.

sample covariance = Cov (x, y) = Σ (x – x¯) (y – y¯)/n – 1

Step 6: Put all the calculated values in the above formula.

Cov (x, y) = Σ (x – x¯) (y – y¯)/n – 1

Cov (x, y) = 950/7 – 1

Cov (x, y) = 950/6

Cov (x, y) = 158.3334

Summary

Covariance is not a difficult topic. Large calculations are needed to find covariance for the given values. Once you practice the above problems, you can solve any problem related to covariance easily.

**Read More**

**BCom ( Bachelor of Commerce ) Course Details**

**Highest Paying Government Jobs in India**