Skip to main content
Skip to main content
DigiCalcs
Kembali ke Panduan
4 min read6 Langkah

How to Calculate Covariance: Step-by-Step Guide

Calculate covariance manually

Lewati perhitungan — gunakan kalkulator

Petunjuk Langkah demi Langkah

1

Gather Your Inputs

Gather the paired x and y values for which you want to calculate the covariance. Ensure that the values are correctly paired, as the order of the pairs matters.

2

Calculate the Means of X and Y

Calculate the means of the X and Y datasets. The mean is calculated by summing all the values and dividing by the number of values.

3

Calculate the Deviations from the Means

For each pair of values, calculate the deviations from the means. This is done by subtracting the mean from each individual value.

4

Calculate the Products of the Deviations

Calculate the products of the deviations for each pair. This is done by multiplying the deviation of the x value by the deviation of the y value.

5

Calculate the Sum of the Products

Calculate the sum of the products of the deviations. This is done by adding up all the products calculated in the previous step.

6

Calculate the Covariance

Finally, calculate the covariance by dividing the sum of the products by n - 1 (for sample covariance) or n (for population covariance).

Introduction to Covariance Calculation

Covariance measures the linear relationship between two datasets. It is a fundamental concept in statistics and data analysis. In this guide, we will walk you through the step-by-step process of calculating the covariance between two datasets manually.

What is Covariance?

Covariance is a measure of how much two variables change together. It is calculated using the following formula:

cov(X, Y) = Σ[(xi - x̄)(yi - ȳ)] / (n - 1)

where:

  • cov(X, Y) is the covariance between datasets X and Y
  • xi and yi are individual data points
  • x̄ and ȳ are the means of datasets X and Y respectively
  • n is the number of data points
  • Σ denotes the sum of the values

Population vs Sample Covariance

The formula above calculates the sample covariance. To calculate the population covariance, the formula is slightly different:

cov(X, Y) = Σ[(xi - x̄)(yi - ȳ)] / n

The only difference is that the population covariance divides by n, whereas the sample covariance divides by n - 1.

Step-by-Step Guide to Calculating Covariance

Step 1: Gather Your Inputs

Gather the paired x and y values for which you want to calculate the covariance. Ensure that the values are correctly paired, as the order of the pairs matters.

Step 2: Calculate the Means of X and Y

Calculate the means of the X and Y datasets. The mean is calculated by summing all the values and dividing by the number of values.

Step 3: Calculate the Deviations from the Means

For each pair of values, calculate the deviations from the means. This is done by subtracting the mean from each individual value.

Step 4: Calculate the Products of the Deviations

Calculate the products of the deviations for each pair. This is done by multiplying the deviation of the x value by the deviation of the y value.

Step 5: Calculate the Sum of the Products

Calculate the sum of the products of the deviations. This is done by adding up all the products calculated in the previous step.

Step 6: Calculate the Covariance

Finally, calculate the covariance by dividing the sum of the products by n - 1 (for sample covariance) or n (for population covariance).

Worked Example

Suppose we have the following paired values:

x y
2 3
4 5
6 7

First, calculate the means of X and Y: x̄ = (2 + 4 + 6) / 3 = 12 / 3 = 4 ȳ = (3 + 5 + 7) / 3 = 15 / 3 = 5

Next, calculate the deviations and their products:

x y x - x̄ y - ȳ (x - x̄)(y - ȳ)
2 3 -2 -2 4
4 5 0 0 0
6 7 2 2 4

Then, calculate the sum of the products: Σ[(xi - x̄)(yi - ȳ)] = 4 + 0 + 4 = 8

Finally, calculate the covariance: cov(X, Y) = Σ[(xi - x̄)(yi - ȳ)] / (n - 1) = 8 / (3 - 1) = 8 / 2 = 4

Common Mistakes to Avoid

  • Ensure that the paired values are correctly aligned.
  • Double-check the calculations of the means and deviations.
  • Be careful when dividing by n or n - 1, depending on whether you are calculating the population or sample covariance.

When to Use a Calculator

While it is possible to calculate the covariance manually, it can be time-consuming and prone to errors, especially for large datasets. In such cases, it is recommended to use a calculator or statistical software to perform the calculation.

Siap Menghitung?

Lewati pekerjaan manual dan dapatkan hasil instan.

Buka Kalkulator

Pengaturan

PrivasiKetentuanTentang© 2026 DigiCalcs