Covariance Calculator

Data Visualization

Covariance Calculator

What is Covariance?

Covariance is a statistical measure that quantifies the degree to which two variables change together. It indicates the direction of the linear relationship between variables.

Formula and Its Meaning

The formula for covariance is:

\[cov(X,Y) = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{n}\]

Where:

  • \(x_i\) and \(y_i\) are individual values of variables X and Y
  • \(\bar{x}\) and \(\bar{y}\) are the means of X and Y
  • \(n\) is the number of data points

Calculation Steps

  1. Calculate the mean of X and Y separately.
  2. For each pair of data points, subtract the X mean from the X value and the Y mean from the Y value.
  3. Multiply these differences for each pair.
  4. Sum all these products.
  5. Divide the sum by the number of data points.

Example Calculation

Let's calculate the covariance for X = (1, 2, 3, 4, 5) and Y = (2, 4, 5, 4, 5)

  1. Calculate means: \(\bar{x} = 3\), \(\bar{y} = 4\)
  2. Calculate differences and products:
    • (1 - 3)(2 - 4) = 4
    • (2 - 3)(4 - 4) = 0
    • (3 - 3)(5 - 4) = 0
    • (4 - 3)(4 - 4) = 0
    • (5 - 3)(5 - 4) = 2
  3. Sum the products: 4 + 0 + 0 + 0 + 2 = 6
  4. Divide by n: 6 / 5 = 1.2

Therefore, the covariance is 1.2.

Visual Representation

This scatter plot represents the example dataset. The pattern shows a generally positive relationship, consistent with the positive covariance we calculated.