Covariance Calculator

Covariance Calculator

Our covariance calculator measures the relation between the two sets of variables often referred X and Y. It is an online statistics calculator for covariance, which involves two random variables X and Y and calculates variation between these two variables. It assists us in comprehending the relationship between two data sets.

It gives us an overview of each step of the calculation. This tool calculates the covariance as well as mean values for the given set of data. These sample values can be useful to solve problems and applications further. It is completely free of cost, very easy to use, and everyone can use it without any limitations. We have made this sample covariance calculator to make the process of covariance calculation simple for you. We will explain the formula and method to calculate covariance using two random variables in detail. We have also provided real-life examples and applications of covariance for you. If you don’t want to waste your time in solving the hefty statistics equation, use our sample covariance calculator to find the amount of variation between two data sets.

How to use covariance calculator?

The covariance calculator is very easy to use. The interface of this tool is kept simple for our users’ sake. All you need is two random variables or two data sets for calculating covariance. First, collect or identify the data set for both variables X and Y. Enter all values for X in the first input box named “Data Set X” and all values for variable Y in the next input box named “Data Set Y.” Note that a comma should separate all values. After entering the values for both variables, click the “Calculate” button to see the results. The specialty of our covariance tool is its speed. It doesn’t take long to calculate the covariance and give you the results instantly.

The result for the given data set is published in the result tab. It will calculate the mean value for both variables X and Y separately. You can use these mean values for X and Y for other calculations as well. It will give you the covariance and size of the sample as well. Our calculator also provides the formula for the calculation, and the complete process of the substitution of values in the formula is also shown in the result. It means you will get not only the answer for the covariance but also the complete procedure of the calculation.

This calculator can be used by students to complete their assignments, project, and to prepare for exams. Researchers and statisticians can also use this calculator for their research purposes.

What is covariance?

Covariance tests how much in one population, two random variables (X, Y) vary. If the population has higher dimensions or random variables, the relation between different dimensions is represented by a matrix. The covariance matrix can be easier to understand by defining the relationship as the relationships between every two random variables in the whole dimensions. The smaller and bigger X & Y values provide the covariance score in a positive number, whereas the bigger X values and the smaller Y values provide the covariance result in a negative number. The covariance will be zero or non-linear if the two random variables are not statistically dependent.

The variance is a special covariance in which the two data sets are the same. Thus, if X= Y, covariance will become variance. The covariance and correlation indicate the positive or negative relation between non-identical variables. The correlation indicates to what extent the variables that are being tested tend to move in the same direction together. Covariance can be used for calculating factors that do not have the same measurement units. We can assess whether units increase or decrease by using covariance. We cannot consolidate the extent to which the variables move together. The reason is the use of multiple measuring units by covariance.

Sample covariance formula

The formula for covariance is different for sample and population. Both samples x and y, respectively, consist of n random values X and Y. The first sample elements are represented by x1, x2,..., xn, and xmean represents the average of values while the second sample elements are represented by are y1, y2, ..., yn, with an average of ymean.

The following covariance equation is the formula for sample covariance if two equal-sized samples are available.

Covsam (x, y) = sum (xi - xmean) (yi - ymean) / n

The summation will go on till the last value of n. It is not instantly clear how important the covariance element is by looking at it. Let’s understand this formula step by step.

In this equation, n is the size of the sample of each of the two samples. The terms xi - xmean and yi - ymean measure the difference between the average of the sample and sample elements for each i=1, 2,..., n.

These two terms are multiplied in the sample covariance formula, summed up over every single sample element, and finally divided by n (size of sample) to get average.

There is nothing to worry about if you find this formula somehow complicated. The theory behind the formula of covariance is actually quite simple. It is used to calculate the variation between data from two samples. We will give an example to calculate covariance so that you can understand the concept with full closure.

How to calculate covariance?

We will see how the covariance formula works in a real-life situation by using a real-life example.

Garret is an investor who recently bought his first few shares in "Home for all," which is a real estate company. Yet Garret had to diversify his investments, as every businessman knows, and therefore decided to buy certain shares in both the “Stars Estates” and “Your Property,” which are both real estate companies. The problem for Garret is which companies he should invest in. That is where covariance comes in handy to decide for Garret.

For stocks of the “Home for all” and “Star Estates,” denoted respectively by xi and yi, Garret randomly selects five closing rates.





x diff

y diff

x diff × y diff




































Mean value





If you are wondering about how to find covariance from here, follow these steps, or you can use our covariance tool to find covariance quickly.

  1. First of all, we will calculate the mean value of the closing prices for the “Home For All” stocks, which you can find in the column named xi. Add all of the five values of these closing prices and divide them by the size of the sample, which is 5. We will get the average value for this company as xmean = 11.364
  2. Now, calculate the mean value for the second company, “Star Estates.” Add all closing prices for the stock of this company and divide them by the sample size, which is the same as in the previous step. The mean value of the closing prices of the second company will be ymean = 8.252.
  3. We will calculate the x diff and y diff for all values. Subtract each value of xi from its mean value, which we have calculated in the previous steps. Use xdiff = xi - xmean for x and ydiff = yi - ymean for y. For example, 11.24 – 11.364 = -0.124. It is the first value for the x diff, and the same process will calculate the remaining values. Repeat this step for the y diff and write all values in the relevant columns.
  4. Calculate the product of xmean and ymean by multiplying the values from both columns and write it in the next column.
  5. Add all the values of the last column, which is the product of both differences. After adding the values, divide it by the size of the sample, which is 5. You will get the sample covariance, which is 0.561, in this case.

We can say that the closing price for both companies varies to around this calculated value of covariance (0.561).

Making decision on covariance value

Note that the covariance value alone has no particular importance, although we can still make some key observations.

In the case of positive covariance, both samples tend to show similar behavior in relation to their averages. Either they are higher than their respective means, or both are lower. The difference is similar to their average.

The samples are usually the opposite in the case of negative covariance. If an observation is less than the average of the sample, it is higher than the average observation of the other sample, and if it is higher than the average of the sample, it will be low for the other one. Nonetheless, we may assume that the samples are always related, but in a different way from positive covariance.

The more positive covariance is, the more the samples are connected, whereas a covariance value more towards zero indicates no strong connection between sample variations.

In the case of Garret, covariance is 0.561. It will be best for garret if he buys stocks whose covariance prices are close to zero in comparison with stocks he already has because he will then understand that the second stock will not change at the same time as the first stock.

But in order to make the correct decision, the covariance of the closing prices for the “Star Estates” and “Your Property” stock must still be calculated.

You can use our online covariance tool to calculate the covariance for both companies. The following table shows the closing prices for “Star Estates” as xi and “Your Property” as yi.



















Repeat the same process as we did above to calculate covariance for the closing prices of those two companies. The sample covariance for this pair of companies will be 1.26. It is much higher than the covariance calculated for “Home for All” and “Star Estates.” It means Garret should purchase the shares of “Star Estate” to diversify his investment in the stock market.

Population covariance using samples

Normally we don’t have access to data of the total population. We have access to the sample sizes, which are limited. Nonetheless, for random variables X and Y, such samples are capable of providing a population covariance estimate. Below is the formula to calculate population covariance using limited samples.

Covpop (X, Y) = sum (xi - xmean) (yi - ymean) / (n-1)

The denominator n-1 gives slightly better value than the formula for sample covariance. It is natural for us to assume so, since small samples do not necessarily represent complete variation between whole populations, and the right corrective factor is the denominator n-1.

Relationship between a sample and population Covariance

The relationship between population and sample covariance can be written as the formula below.

Covpop (X, Y) = (n / n-1) * Covsam (x, y)

But keep in mind that the difference between n and n-1 becomes smaller as the sample size increases. Thus, for large samples, the population covariance formula and covariance formula for sample produce similar results.

Instead of using the sample formula of covariance, you can see what the effects would be for shares of Garret if we used the population covariance formula.

Covariance vs. Correlation and variance

Covariance is a function to measure the variation between X and Y, which are two random variables, while variance tests the degree to which a random variable differs on its own. The relationship between covariance and variance can be written as:

Cov (X, X) = Var (X)

The disparity between the X and itself is thus exactly the covariance. The correlation between random variables X and Y is another way to express the variability between two random variables. The relation between covariance and correlation is:

Corr (X, Y) = Cov (X, Y) / (σX * σY)

Where σX is the standard deviation of X, and σY is the standard deviation of Y.

Correlation can be considered as the stabilized type of covariance. Correlation should be between 1 and -1, according to the above formula. This is why correlation is used more often than covariance, even if they perform the same task. In the case of Garret, we had to understand the size of covariance, but we don’t have to do that in correlation.

Applications of Covariance

Covariance has several applications in real life, which is why it is considered very important among statisticians and researchers. Below are some of the applications of covariance in real life.

Reduction of dimensionality: One of the most common applications of covariance is system aggregation, extraction of functions, and reduction of dimensionality. The covariance of variables in a data set helps to expose a smaller space that can still contain the bulk of the data variance. Variables that are highly correlated can be combined without losing too much information.
Multi-view learning: Multi-view learning uses additional data in the form of several independent, and integrated data feature sets and unlabeled data to improve modeling.
Feature selection & classification: A number of machine learning approaches use the covariance with a label and also used to select features for classification purposes. One of the fastest and easiest ways of selecting a feature is to filter certain features that are least related to the response variable or the label. This is also necessary to reduce the number of functions to a manageable level quickly before using a more expensive method of selection. The linear discriminant analysis also depends on covariance in some ways and uses covariance for analysis.

Need Custom Calculator?

With Over Online Tools, eCalculator.co Helping Millions of Students, Teachers, Businessmen & Nutritionists Every Month.

Related Articles