# Covariance Calculator

Instructions: Use this Covariance Calculator to find the covariance coefficient between two variables $$X$$ and $$Y$$ that you provide. Please input the sample data for the independent variable $$(X_i)$$ and the dependent variable ($$Y_i$$), in the form below:

Independent variable $$X$$ sample data (comma or space separated) =
Dependent variable $$Y$$ sample data (comma or space separated) =
Independent variable Name (optional) =
Dependent variable Name (optional) =

## How to use this Covariance Calculator

The use of this calculator is simple: You need to input the sample data for the variables $$X$$ and $$Y$$, and press the "Calculate" button. The calculator will show you all the steps required to compute the covariance coefficient.

### How do you compute the sample covariance

First, we need to have two samples of the same size: $$X_1, X_2, ...., X_n$$ and $$Y_1, Y_2, ...., Y_n$$. Then, using this information about the samples, you use the following formula:

$cov(X, Y) = \displaystyle \frac{1}{n-1}\left(\sum_{i=1}^n X_i Y_i - \left( \sum_{i=1}^n X_i \right) \times \left( \sum_{i=1}^n Y_i \right) \right)$

Usually, this is computed by constructing a table with $$X_i$$ and $$Y_i$$ values, but also with the products $$X_i Y_i$$ in a column.:

### Alternative formulas to compute the sample covariance

Often times, you will see a different formula for sample covariance shown as:

$cov(X, Y) = \displaystyle \frac{1}{n-1}\left(\sum_{i=1}^n (X_i - \bar X)(Y_i - \bar Y) \right)$

This formula is absolutely equivalent to the previous ones, and it is a matter of taste whether you use this or the other one.

Some people think that the latter formula is better because it shows the covariance as this product of deviations from the mean. But other people think that the latter is inefficient, because it is forced to compute the sample means, which are not required in the former one.

### Are the covariance and correlation related in any way?

Yes, they are. Both the covariance and the correlation coefficient measure the degree of linear association between two variables.

The main difference is that the correlation measures the association relative to the standard deviations, which makes the correlation coefficient range between -1 and 1, which makes a MUCH more interpretable measure of association than the covariance itself

Still, the covariance coefficient, even if it is less interpretable, has its uses in finance, especially in the calculation of the beta for a company.

### Covariance Calculator continuous case

Notice that the case above corresponds to the sample correlation. When you know the distribution of the X and Y variables, as well as their joint distribution, you can compute the exact covariance using the expression:

$cov(X, Y) = E(XY) - E(X)E(Y)$

In case you have any suggestion, or if you would like to report a broken solver/calculator, please do not hesitate to contact us.