Covariance Matrix Calculator

This covariance matrix calculator takes columns of data and returns the sample or population covariance of every pair of variables, along with the correlation of each pair.

Checks on your data

  • Covariance and correlation measure linear association only, and a strong correlation does not show one variable causes the other.
  • With few rows, a covariance matrix is unstable. Aim for many more observations than variables.

Results

Covariance Height, Weight
105.5
Correlation Height, Weight
0.99779116
Strongest pair
Height and Weight: r = 0.99779
Variance of Height
87.5
Variance of Weight
127.76667
Variance of Age
29.5
Total variance (trace)
244.76667
Rows n
6
Divisor
n − 1 (sample)
Weight against Height (strongest pair, r = 0.9978)
607080160165170175180185HeightWeight
Covariance and correlation by pair
PairCovarianceCorrelation r
Height – Weight105.50.99779
Height – Age48.50.95461
Weight – Age59.50.96916
Show step-by-step solution
  1. Column means: Height = 172.5, Weight = 70.1667, Age = 30.5.
  2. Covariance(X, Y) = Σ(x − x̄)(y − ȳ) ÷ (n − 1); the diagonal holds each variable's variance.
  3. Correlation(X, Y) = Cov(X, Y) ÷ (sₓ s_y) = 0.997791 for Height and Weight.
DiagonalVariances
Off-diagonalCovariances
SymmetricCov(X,Y) = Cov(Y,X)
ScaledCorrelation matrix

What Is Covariance Matrix?

A covariance matrix is a square table that holds the covariance between every pair of variables, with each variable's variance on the diagonal. It summarises how variables move together and is the starting point for regression, PCA and portfolio analysis.

Paste your data with one observation per line and one variable per column, with an optional header row. Choose the sample (n − 1) or population (n) divisor and the calculator returns the pairwise covariances and the correlation matrix, the variance of each variable and a scatter plot of the most strongly related pair.

Below you will find the formulas, variables, a worked example and answers about covariance versus correlation.

How to Use the Covariance Matrix Calculator

  1. Paste your data with one observation per line and one variable per column.
  2. Optionally start with a header row of names.
  3. Choose sample (n − 1) or population (n).
  4. Read the pairwise covariances and correlations.

Covariance Matrix Formula

Sample covariance

Cov(X,Y)=∑(xi−xˉ)(yi−yˉ)n−1Cov(X,Y)=\frac{\sum(x_i-\bar x)(y_i-\bar y)}{n-1}

Correlation

rxy=Cov(X,Y)sxsyr_{xy}=\frac{Cov(X,Y)}{s_x s_y}

Covariance Matrix Variables Explained

SymbolMeaningNotes
Cov(X, Y)Covariance of two variables
Var(X)Variancediagonal of the matrix
rCorrelation coefficientCov ÷ (sₓ s_y)
nNumber of observations (rows)

Covariance Matrix Worked Example

For x = 1, 2, 3 and y = 2, 4, 7: x̄ = 2, ȳ = 4.333. The cross-products are (−1)(−2.333) + 0 + (1)(2.667) = 5, so the sample covariance is 5 ÷ 2 = 2.5. The variances are 1 and 6.333, so r = 2.5 ÷ √(1 × 6.333) = 0.993.

With the example values loaded in the calculator above, the steps are:

  1. Column means: Height = 172.5, Weight = 70.1667, Age = 30.5.
  2. Covariance(X, Y) = Σ(x − x̄)(y − ȳ) ÷ (n − 1); the diagonal holds each variable's variance.
  3. Correlation(X, Y) = Cov(X, Y) ÷ (sₓ s_y) = 0.997791 for Height and Weight.

Result: Covariance Height, Weight = 105.5; Correlation Height, Weight = 0.99779116; Strongest pair = Height and Weight: r = 0.99779.

Where Covariance Matrix Is Used

Relationship between variables

Seeing which variables move together.

Regression preparation

Checking predictor correlations before a multiple regression.

Finance

Building a covariance matrix of returns.

Coursework

Checking covariance and correlation by hand.

Common Covariance Matrix Mistakes to Avoid

  • Use sample (n − 1) for data from a larger population.
  • Standardise variables before comparing covariances.
  • Check for outliers: they dominate covariance.

Covariance Matrix Terms and Definitions

Covariance
The average product of deviations of two variables from their means.
Covariance matrix
A symmetric table of all pairwise covariances with variances on the diagonal.

Covariance Matrix FAQs

What is a covariance matrix?

A square table of covariances between every pair of variables, with each variable's variance on the diagonal.

What is the difference between covariance and correlation?

Correlation is covariance divided by both standard deviations, so it is unit-free and between −1 and 1.

Sample or population covariance?

Use n − 1 when your data are a sample, and n when you have the whole population.

Can covariance be negative?

Yes. A negative value means one variable tends to fall as the other rises.

Related calculators

Last updated 2026-11-09. See our disclaimer.