# Covariance: Definition, Formula & Examples

## What is Covariance?

In the world of statistics, the concept of covariance is a crucial tool that helps to measure the relationship between two variables. Derived from the word ‘co-‘ meaning together and ‘variance,’ covariance indicates how two variables change together, offering insights into their directional relationship.

While the term might seem intimidating, its importance in various fields, from finance to machine learning, can’t be understated. For instance, in portfolio theory, it is used to understand the correlation between the returns of different assets, enabling investors to optimize their portfolios by balancing risk and reward. Meanwhile, in machine learning, matrices are used to understand the data’s structure and inform the algorithm’s training process.

However, to interpret covariance effectively, one must understand its nuances, especially its positive and negative values, each providing unique insights about the relationship between the variables under consideration. A positive covariance signifies that the two variables increase or decrease together, while a negative one implies that as one variable increases, the other decreases, and vice versa.

##### Key Points

- Covariance is a statistical measure that quantifies the relationship between two variables.
- It measures how the variables move together and indicates the direction of their relationship (positive or negative).
- Covariance does not indicate causation and should be interpreted carefully.

## Understanding Covariance

**Positive and Negative:**Covariance can be either positive, zero, or negative. Positive covariance indicates that the two variables tend to move in the same direction—when one variable increases, so does the other, and when one decreases, the other follows suit. Negative covariance, on the other hand, shows that the two variables move inversely to each other—when one increases, the other decreases, and vice versa. A covariance of zero suggests that there is no linear relationship between the variables.**Difference between Covariance and Correlation:**While both covariance and correlation measure the relationship between two variables, they are not the same. Covariance only determines whether two variables move together or inversely. In contrast, correlation not only determines how the variables move in relation to each other but also measures the strength and direction of their relationship. Correlation values range from -1 to +1, with -1 indicating a perfect negative relationship, +1 indicating a perfect positive relationship, and 0 indicating no relationship.**Scale Dependency:**Covariance is dependent on the units of the variables involved. If the scale of the variables is changed, it will affect the covariance. This is a limitation and one reason why correlation, which is scale-independent, can sometimes be a more useful measure.**Data Analysis:**Covariance plays a significant role in data analysis and statistics. It forms the basis for more complex statistical concepts, such as the matrix used in machine learning and the calculation of variance in portfolio theory in finance.

Understanding these nuances is key to applying the concept correctly in statistical analysis and interpreting the results accurately.

## Covariance Formula

The formula for covariance is a statistical tool that helps quantify the relationship between two variables. The mathematical expression is as follows:

Cov(X,Y) = Σ[(Xi – Xmean)(Yi – Ymean)] / (n – 1)

Here’s what each component of the formula represents:

**Cov(X,Y):**This represents the covariance between the two variables X and Y.**Σ:**This is the summation symbol, indicating that the following expression is to be summed over all observations in the dataset.**Xi and Yi:**These represent specific observations of variables X and Y, respectively.**Xmean and Ymean:**These represent the mean (or average) of all observations of variables X and Y, respectively.**(n – 1):**This is the denominator of the formula, where ‘n’ represents the number of data pairs. The ‘-1’ is applied when calculating a sample = to provide an unbiased estimate of the population covariance.

The formula can be interpreted as summing the product of the differences of X and Y from their respective means, then dividing by one less than the number of data pairs. It’s the mean value of the product of the differences of each observation from their respective means.

It’s crucial to remember that while this formula gives us the covariance, it does not give us a normalized measure of the strength of the relationship between X and Y. This limitation is addressed by the correlation coefficient.

## Calculating Covariance

Computing covariance may appear complex initially, but it’s straightforward when the steps are followed systematically. Here’s a step-by-step guide to calculating it:

**Identify Your Variables:**First, identify the two variables for which you want to calculate covariance. Let’s denote them as X and Y.**Calculate the Means:**Calculate the mean (average) of each variable. This is achieved by summing all observations for each variable and dividing by the number of observations.**Compute Differences from the Mean:**Subtract the mean of each variable from each observation of that variable. This gives you the deviations of individual observations from the mean for both X and Y.**Multiply the Differences:**Multiply the difference from the mean of X for each observation by the difference from the mean of Y for the same observation.**Sum Up:**Add up all the values you computed in step 4. This gives you the sum of the product of the differences.**Divide:**Finally, divide the result from step 5 by (n-1), where ‘n’ is the number of observations. This yields the covariance.

Please note that the final value will depend on the units of the variables used. Because of this, the magnitude of covariance can sometimes be hard to interpret, which is one of the reasons why statisticians often use the correlation coefficient (which is standardized) to examine the relationship between variables.

Keep in mind that covariance is a measure of linear dependence. If your data isn’t linear, the covariance may be close to zero even if there’s a strong relationship between variables.

## Limitations of Covariance

While covariance is a useful measure in statistics to ascertain the directional relationship between two variables, it does come with its limitations:

**Unit Dependent:**Covariance is not standardized and is unit dependent. That means the magnitude of the covariance depends on the units of measurement of variables X and Y. This can make it difficult to interpret the strength of the relationship between the variables.**Interpretation Difficulty:**Covariance values can range from negative infinity to positive infinity. As such, understanding whether the covariance value indicates a strong or weak relationship can be challenging. For example, it’s hard to discern if a covariance of 500 is high or not without context.**Linear Relationships Only:**Covariance measures only linear relationships between variables. If the relationship is curvilinear, the covariance might be near zero even if there is a strong relationship between the variables.**No Information on Slope:**While covariance can give an indication of the direction of a relationship between two variables (positive or negative), it provides no information about the slope of that relationship. In other words, you can’t infer how much Y will change if X changes by a certain amount, just from the covariance.**Impact of Outliers:**Covariance is sensitive to extreme values or outliers. A single outlier can significantly impact the covariance, leading to potentially misleading conclusions.

Because of these limitations, covariance is often used in conjunction with other statistical measures, such as the correlation coefficient, which provides a normalized measure of the strength and direction of the relationship between two variables.

## Examples of Covariance

Understanding covariance is made easier by looking at some real-world examples. Let’s consider two instances:

### Example 1: Stock Returns

Suppose we have a portfolio of two stocks, and we want to understand how these stocks move in relation to each other. If the covariance between the stocks’ returns is positive, they tend to move in the same direction. When one stock performs well, the other typically does too, and vice versa. A negative result, on the other hand, indicates that the stocks tend to move in opposite directions. When one performs well, the other usually underperforms, and vice versa.

### Example 2: Weather and Ice Cream Sales

Let’s consider the relationship between daily temperature and ice cream sales in a city. We’d generally expect that as the temperature increases (say, during summer), more people would buy ice cream, leading to higher sales. This expectation suggests a positive covariance: as the temperature (Variable X) increases, so do ice cream sales (Variable Y), and vice versa.

## FAQs

**What is covariance?**

Covariance is a statistical measure that quantifies the relationship between two variables and how they vary together.

**How is covariance calculated?**

Covariance is calculated by taking the average of the products of the deviations of each variable from their respective means.

**What does a positive covariance mean?**

A positive covariance indicates that when one variable increases, the other variable tends to increase as well.

**What does a negative covariance mean?**

A negative covariance indicates that when one variable increases, the other variable tends to decrease.

### About Paul

Paul Boyce is an economics editor with over 10 years experience in the industry. Currently working as a consultant within the financial services sector, Paul is the CEO and chief editor of BoyceWire. He has written publications for FEE, the Mises Institute, and many others.