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.

How to Read a Covariance Matrix

The diagonal holds each variable’s variance and the off-diagonal entries are covariances between pairs. For x = 1, 2, 3 and y = 2, 4, 7, the sample covariance is 5 ÷ 2 = 2.5, the variances are 1 and 6.333, and the correlation is 2.5 ÷ √(1 × 6.333) = 0.993.

A positive covariance means the variables rise together and a negative one means one rises as the other falls. Covariance depends on the units, so use the correlation to compare pairs. The calculator shows both and picks the strongest pair.

Where Covariance Matrix Is Used

Several variables

See variances and covariances for all pairs in one matrix.

Strongest relationship

Find which pair of variables is most strongly correlated.

Regression and PCA prep

Get the matrix that many multivariate methods start from.

Total variance

Read the trace as the total variance.

Common Covariance Matrix Mistakes to Avoid

  • Choose the divisor: n − 1 for a sample, n for a population.
  • Covariance depends on the units, so only its sign is easy to read directly.
  • Each row is one observation and each column is one variable.
  • Correlation lies between −1 and 1 and is unit-free.

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?

It is a square table with the variance of each variable on the diagonal and the covariance of each pair off the diagonal.

What is the difference between covariance and correlation?

Correlation is covariance divided by the product of the two standard deviations. It is unit-free and lies between −1 and 1, which makes pairs comparable.

Sample or population covariance?

Use the sample version, with n − 1, for data from a larger group. Use the population version, with n, only for the whole group.

Can covariance be negative?

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

Related calculators

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