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
- Paste your data with one observation per line and one variable per column.
- Optionally start with a header row of names.
- Choose sample (n − 1) or population (n).
- Read the pairwise covariances and correlations.
Covariance Matrix Formula
Sample covariance
Correlation
Covariance Matrix Variables Explained
| Symbol | Meaning | Notes |
|---|---|---|
| Cov(X, Y) | Covariance of two variables | |
| Var(X) | Variance | diagonal of the matrix |
| r | Correlation coefficient | Cov ÷ (sₓ s_y) |
| n | Number 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:
- Column means: Height = 172.5, Weight = 70.1667, Age = 30.5.
- Covariance(X, Y) = Σ(x − x̄)(y − ȳ) ÷ (n − 1); the diagonal holds each variable's variance.
- 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.