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.
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.