search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to
near_me
Linear Algebra
54 guides
keyboard_arrow_down
check_circle
Mark as learned
thumb_up
0
thumb_down
0
chat_bubble_outline
0
Comment
auto_stories Bi-column layout
settings

# Covariance Matrix

schedule Jul 1, 2022
Last updated
local_offer
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

# Covariance matrix for two random variables

The covariance matrix for the two random variables $X_1$ and $X_2$ look like the following:

$$\boldsymbol{\Sigma}=\begin{pmatrix} \mathbb{V}(X_1)&\mathrm{cov}(X_1,X_2)\\ \mathrm{cov}(X_2,X_1)&\mathbb{V}(X_2)\\ \end{pmatrix}$$

Note that $\mathrm{cov}(X_1,X_2)=\mathrm{cov}(X_2,X_1)$.

As we can see, the diagonals contain the variance of the random variables $X_1,…,X_n$ while the other entries contain the covariance between these random variables. Since the covariance matrix contains information about both the covariance as well as the variance, we sometimes call the matrix the covariance-variance matrix.

# Extending to higher dimensions

To generalise this to more than two random variables:

$$\boldsymbol{\Sigma}=\mathrm{cov}(\boldsymbol{X})= \begin{pmatrix} \mathbb{V}(X_1)&\mathrm{cov}(X_1,X_2)&\dots&\mathrm{cov}(X_1,X_n)\\ \mathrm{cov}(X_2,X_1)&\mathbb{V}(X_2)&\dots&\mathrm{cov}(X_2,X_n)\\ \vdots&\vdots&\ddots&\vdots\\ \mathrm{cov}(X_n,X_1)&\mathrm{cov}(X_n,X_2)&\dots&\mathbb{V}(X_n)\\ \end{pmatrix}$$

To extend this concept to higher dimensions, we need to use some Linear Algebra. Let $X$ refer to random vectors, and subscripted $X_i$ is used to refer to random scalars.

Suppose we have the following random vector and vector mean:

$$\boldsymbol{X}=\begin{pmatrix} 1\\ \vdots\\ X_n\\ \end{pmatrix} \qquad \boldsymbol{\mu}=\begin{pmatrix} 1\\ \vdots\\ \mu_n\\ \end{pmatrix}$$

are random variables, each with finite variance, then the covariance matrix $\Sigma$ is the matrix whose $(i,j)$ entry is the covariance:

$$\Sigma_{ij}=\mathrm{cov}(X_i,X_j )=\mathbb{E}[(X_i-\mu_i )(X_j-\mu_j )]=\mathbb{E}(X_i X_j )-\mu_i\mu_j$$

Where $\mu_i=\mathbb{E}(X_i)$ and $\mu_j=\mathbb{E}(X_j)$. In matrix form, this translates to the following:

$$\Sigma=\mathrm{cov}(\boldsymbol{X})=\mathbb{E}\left(\boldsymbol{X}\boldsymbol{X}^T\right)-\boldsymbol{\mu}\boldsymbol{\mu}^T$$
NOTE

Trick when converting to matrix form

When we see $v_iv_j$, we can often rewrite this as $\mathbf{v}\mathbf{v}^T$.

Note that $\mathbf{X}\mathbf{X}^T$ is a matrix (i.e. recall that ​$\mathbf{a}\mathbf{b}^T$ results in a matrix), although $X$ is a vector here. An equivalent statement of the above would be:

$$\boldsymbol{\Sigma}=\mathrm{cov}(X)=\mathbb{E}[\mathbf{X}\mathbf{X}^T ]-\mathbb{E}(\mathbf{X})\mathbb{E}(\mathbf{X})^T$$
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!