Install free

Guides

How to make a covariance matrix in Google Sheets

Covariance measures how two variables move together. A covariance matrix shows it for every pair of columns, with each column's variance on the diagonal. Example: the ad spend, price and sales data from the regression guide, 15 months.

ABC
1Ad spendPriceSales
2128.237.8
3159.645.2
497.439.8
5229.166
61810.352.5
7257.988.3
8309.490.5
9148.847.4
10207.177.2
11271079.7
12338.5108.6
13119.927.5
14247.681.5
15298.995.5
161710.445

With the Covariance tool

  1. Open Extensions, StatPak, Data Analysis and choose Covariance.
  2. Input range: A1:C16, Grouped by: Columns.
  3. Tick Labels in first row or column and click Run.
Ad spendPriceSales
Ad spend52.10667
Price0.050666671.068622
Sales166.84-6.339333579.864

How to read it

Population or sample covariance?

Excel's Covariance tool computes COVARIANCE.P, the population covariance, which divides by n. Microsoft's ToolPak documentation states this, and StatPak matches it, so the diagonal equals VAR.P. Descriptive Statistics reports the sample variance, VAR.S, which is slightly larger.

If your data is a sample and you want the sample covariance (dividing by n - 1), multiply each cell by n / (n - 1). With 15 months that is 15/14: the ad spend and sales covariance becomes 178.7571. In Sheets, =COVARIANCE.S(A2:A16, C2:C16) gives the sample value directly and =COVARIANCE.P(A2:A16, C2:C16) gives the tool's value. The older COVAR function is the population version.

Covariance or correlation?

Covariance is in the units of the two variables multiplied together, so its size depends on scale: measure ad spend in cents and the covariance grows 100 times. That makes it hard to say whether 166.84 is large. Correlation divides the covariance by both standard deviations, which gives a unitless number between -1 and 1:

166.84 / SQRT(52.10667 * 579.864) = 0.9598215

That is the same value as in the correlation matrix. Use correlation to describe how strongly two variables are related. Use covariance when a formula calls for it, for example portfolio variance in finance or a principal component analysis.

Related guides