$(\Omega,\mathcal F,\mathbb P)$ を確率空間とし、$X,Y:\Omega\to\mathbb R$ を二乗可積分な実数値確率変数とする。
すなわち、
$$
\mathbb E[X^2]<\infty,\qquad \mathbb E[Y^2]<\infty
$$
が成り立つとする。このとき、$X$ と $Y$ の共分散 $\operatorname{Cov}(X,Y)$ を
$$
\operatorname{Cov}(X,Y)
:=
\mathbb E\left[(X-\mathbb E[X])(Y-\mathbb E[Y])\right]
$$
で定義する。
$X,Y$ は二乗可積分であるから、$X,Y$ は可積分であり、
$$
\mathbb E[X]\in\mathbb R,\qquad \mathbb E[Y]\in\mathbb R
$$
である(
証明はコチラ
)。また、$X-\mathbb E[X]$ と $Y-\mathbb E[Y]$ も二乗可積分である。
したがって、$\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式より、
$$
\mathbb E\left[\left|(X-\mathbb E[X])(Y-\mathbb E[Y])\right|\right]
\le
\left(\mathbb E[(X-\mathbb E[X])^2]\right)^{1/2}
\left(\mathbb E[(Y-\mathbb E[Y])^2]\right)^{1/2}
<
\infty
$$
である。よって、
$$
(X-\mathbb E[X])(Y-\mathbb E[Y])
$$
は可積分であり、$\operatorname{Cov}(X,Y)$ は有限な実数として定義される。
共分散は、$X$ の平均からのずれ
$$
X-\mathbb E[X]
$$
と、$Y$ の平均からのずれ
$$
Y-\mathbb E[Y]
$$
の積の期待値である。
したがって、$X$ と $Y$ が平均から同じ向きにずれやすいとき、共分散は正になりやすい。
一方、$X$ と $Y$ が平均から反対向きにずれやすいとき、共分散は負になりやすい。
共分散は分散の一般化である。
実際、$X=Y$ とおくと、
$$
\operatorname{Cov}(X,X)
=
\mathbb E\left[(X-\mathbb E[X])^2\right]
=
\mathbb V(X)
$$
である。
したがって、
$$
\operatorname{Cov}(X,X)=\mathbb V(X)
$$
が成り立つ。
$(\Omega,\mathcal F,\mathbb P)$ を確率空間とし、$X:\Omega\to\mathbb R$ を二乗可積分な実数値確率変数とする。
すなわち、
$$
\mathbb E[X^2]<\infty
$$
が成り立つとする。
このとき、
$$
\operatorname{Cov}(X,X)=\mathbb V(X)
$$
が成り立つ。
$X$ は二乗可積分であるから、特に可積分である。
したがって、
$$
\mathbb E[X]\in\mathbb R
$$
である。ここで、
$$
\mu:=\mathbb E[X]
$$
とおく。共分散の定義より、
$$
\operatorname{Cov}(X,X)
=
\mathbb E\left[(X-\mathbb E[X])(X-\mathbb E[X])\right]
$$
である。$\mu=\mathbb E[X]$ であるから、
$$
\operatorname{Cov}(X,X)
=
\mathbb E\left[(X-\mu)(X-\mu)\right]
$$
である。
任意の $\omega\in\Omega$ に対して、
$$
(X(\omega)-\mu)(X(\omega)-\mu)
=
(X(\omega)-\mu)^2
$$
であるから、$\Omega$ 上の非負可測関数として
$$
(X-\mu)(X-\mu)=(X-\mu)^2
$$
である。
したがって、
$$
\begin{align}
\operatorname{Cov}(X,X)
&=
\mathbb E\left[(X-\mu)(X-\mu)\right] \\
&=
\mathbb E\left[(X-\mu)^2\right] \\
&=
\mathbb V(X)
\end{align}
$$
である。
以上より、
$$
\operatorname{Cov}(X,X)=\mathbb V(X)
$$
が成り立つ。
$$ \Box$$
$(\Omega,\mathcal F,\mathbb P)$ を確率空間とし、$X,Y:\Omega\to\mathbb R$ を二乗可積分な実数値確率変数とする。
すなわち、
$$
\mathbb E[X^2]<\infty,\qquad \mathbb E[Y^2]<\infty
$$
が成り立つとする。
このとき、
$$
\operatorname{Cov}(X,Y)=\operatorname{Cov}(Y,X)
$$
が成り立つ。
-以上より、
$$
\operatorname{Cov}(X,Y)=\operatorname{Cov}(Y,X)
$$
が成り立つ。
$$ \Box$$
共分散を有限な実数として扱うためには、
$$
\mathbb E\left[\left|(X-\mathbb E[X])(Y-\mathbb E[Y])\right|\right]<\infty
$$
が必要である。
この命題では、$X,Y$ の二乗可積分性を仮定しているため、$\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式により、この可積分性が保証される。
したがって、$\operatorname{Cov}(X,Y)$ と $\operatorname{Cov}(Y,X)$ はどちらも有限な実数として定義される。
任意の $x\in\mathbb R$ に対して $x^2\ge0$ であるから、任意の実数 $a,b$ について
$$
(a-b)^2\ge0
$$
が成り立つ。これを展開すると
$$
a^2-2ab+b^2\ge0
$$
である。従って
$$
2ab\le a^2+b^2
$$
が得られる。ここで
$$
(a+b)^2=a^2+2ab+b^2
$$
であるから、上の不等式 $2ab\le a^2+b^2$ を用いて
$$
(a+b)^2=a^2+2ab+b^2\le a^2+(a^2+b^2)+b^2=2a^2+2b^2
$$
となる。
$$ \Box$$
$(\Omega,\mathcal F,\mathbb P)$ を確率空間とし、$X,Y:\Omega\to\mathbb R$ を二乗可積分な実数値確率変数とする。
すなわち、
$$
\mathbb E[X^2]<\infty,\qquad \mathbb E[Y^2]<\infty
$$
が成り立つとする。
このとき、
$$
\operatorname{Cov}(X,Y)
=
\mathbb E[XY]-\mathbb E[X]\mathbb E[Y]
$$
が成り立つ。
-以上より、
$$
\operatorname{Cov}(X,Y)
=
\mathbb E[XY]-\mathbb E[X]\mathbb E[Y]
$$
が成り立つ。
$$ \Box$$
公式
$$
\operatorname{Cov}(X,Y)
=
\mathbb E[XY]-\mathbb E[X]\mathbb E[Y]
$$
を書くためには、$\mathbb E[XY]$ が有限な実数として定義されている必要がある。
この命題では、$X,Y$ の二乗可積分性を仮定しているため、$\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式により、
$$
\mathbb E[|XY|]<\infty
$$
が保証される。
$(\Omega,\mathcal F,\mathbb P)$ を確率空間とし、$n\in\mathbb N_{>0}$ とする。
$X_1,\dots,X_n:\Omega\to\mathbb R$ を二乗可積分な実数値確率変数とする。すなわち、任意の $i\in\{1,\dots,n\}$ に対して
$$
\mathbb E[X_i^2]<\infty
$$
が成り立つとする。
また、$a_1,\dots,a_n\in\mathbb R$ とし、
$$
S:=\sum_{j=1}^{n}a_jX_j
$$
とおく。
このとき、$S$ も二乗可積分であり、
$$
\mathbb V(S)
=
\sum_{i=1}^{n}\sum_{j=1}^{n}a_i a_j\operatorname{Cov}(X_i,X_j)
$$
が成り立つ。すなわち、
$$
\mathbb V\left(\sum_{j=1}^{n}a_jX_j\right)
=
\sum_{i=1}^{n}\sum_{j=1}^{n}a_i a_j\operatorname{Cov}(X_i,X_j)
$$
が成り立つ。
-以上より、
$$
\mathbb V(S)
=
\sum_{i=1}^{n}\sum_{j=1}^{n}
a_i a_j
\operatorname{Cov}(X_i,X_j)
$$
が成り立つ。$S=\sum_{j=1}^{n}a_jX_j$ であるから、
$$
\mathbb V\left(\sum_{j=1}^{n}a_jX_j\right)
=
\sum_{i=1}^{n}\sum_{j=1}^{n}
a_i a_j
\operatorname{Cov}(X_i,X_j)
$$
が成り立つ。
$$ \Box$$
任意の $x\in\mathbb R$ に対して $x^2\ge0$ であるから、任意の実数 $a,b$ について
$$
(a-b)^2\ge0
$$
が成り立つ。これを展開すると
$$
a^2-2ab+b^2\ge0
$$
である。従って
$$
2ab\le a^2+b^2
$$
が得られる。ここで
$$
(a+b)^2=a^2+2ab+b^2
$$
であるから、上の不等式 $2ab\le a^2+b^2$ を用いて
$$
(a+b)^2=a^2+2ab+b^2\le a^2+(a^2+b^2)+b^2=2a^2+2b^2
$$
となる。
$$ \Box$$
有限個の実数 $a_1,\dots,a_n$ に対して
$$
\left(\sum_{i=1}^{n}a_i\right)^2
\le
n\sum_{i=1}^{n}a_i^2
$$
が成り立つ理由は、有限列に対する $\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式を、以下の$2$ つの列
$$
(a_1,\dots,a_n),\quad (1,\dots,1)
$$
に適用するからである。
有限列に対する $\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式は、
$$
\left(\sum_{i=1}^{n}a_i b_i\right)^2
\le
\left(\sum_{i=1}^{n}a_i^2\right)
\left(\sum_{i=1}^{n}b_i^2\right)
$$
である。
ここで、任意の $i\in\{1,\dots,n\}$ に対して
$$
b_i:=1
$$
とおくと、
$$
\sum_{i=1}^{n}a_i b_i
=
\sum_{i=1}^{n}a_i\cdot 1
=
\sum_{i=1}^{n}a_i
$$
であり、また
$$
\sum_{i=1}^{n}b_i^2
=
\sum_{i=1}^{n}1^2
=
\sum_{i=1}^{n}1
=
n
$$
である。
したがって、$\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式より、
$$
\left(\sum_{i=1}^{n}a_i\right)^2
=
\left(\sum_{i=1}^{n}a_i\cdot 1\right)^2
\le
\left(\sum_{i=1}^{n}a_i^2\right)
\left(\sum_{i=1}^{n}1^2\right)
=
n\sum_{i=1}^{n}a_i^2
$$
が従う。
つまり、この不等式は、$a_1,\dots,a_n$ の和を、ベクトル $(a_1,\dots,a_n)$ とベクトル $(1,\dots,1)$ の内積と見て、
$\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式を適用したものである。
$\mathbf a\in\mathbb R^n$ を
$$
\mathbf a:=
\begin{pmatrix}
a_1\\
\vdots\\
a_n
\end{pmatrix}
$$
で定める。
また、共分散行列 $\Sigma$ を
$$
\Sigma:=
\left(\operatorname{Cov}(X_i,X_j)\right)_{1\le i,j\le n}
$$
で定める。
このとき、
$$
\mathbf a^{\top}\Sigma\mathbf a
=
\sum_{i=1}^{n}\sum_{j=1}^{n}
a_i a_j\operatorname{Cov}(X_i,X_j)
$$
である。
したがって、上の公式は行列形式で
$$
\mathbb V(S)=\mathbf a^{\top}\Sigma\mathbf a
$$
と書ける。
任意の $i\in\{1,\dots,n\}$ について $a_i=1$ とおくと、
$$
S=\sum_{i=1}^{n}X_i
$$
であり、公式は
$$
\mathbb V\left(\sum_{i=1}^{n}X_i\right)
=
\sum_{i=1}^{n}\sum_{j=1}^{n}
\operatorname{Cov}(X_i,X_j)
$$
となる。
これは、有限和の分散と共分散の公式に一致する。
$(\Omega,\mathcal F,\mathbb P)$ を確率空間とし、$X,Y:\Omega\to\mathbb R$ を二乗可積分な実数値確率変数とする。
すなわち、
$$
\mathbb E[X^2]<\infty,\qquad \mathbb E[Y^2]<\infty
$$
が成り立つとする。
共分散を
$$
\operatorname{Cov}(X,Y)
:=
\mathbb E\left[(X-\mathbb E[X])(Y-\mathbb E[Y])\right]
$$
で定義する。
このとき、
$$
|\operatorname{Cov}(X,Y)|
\le
\sqrt{\mathbb V(X)\mathbb V(Y)}
$$
が成り立つ。
-以上より、
$$
|\operatorname{Cov}(X,Y)|
\le
\sqrt{\mathbb V(X)\mathbb V(Y)}
$$
が成り立つ。
$$ \Box$$
$\mathbb V(X)>0$ かつ $\mathbb V(Y)>0$ のとき、相関係数を
$$
\rho(X,Y)
:=
\frac{\operatorname{Cov}(X,Y)}
{\sqrt{\mathbb V(X)\mathbb V(Y)}}
$$
で定義する。上の命題より、
$$
|\rho(X,Y)|\le1
$$
が成り立つ。
つまり、相関係数は常に $-1$ 以上 $1$ 以下の値をとる。
もし $\mathbb V(X)=0$ または $\mathbb V(Y)=0$ ならば、右辺は
$$
\sqrt{\mathbb V(X)\mathbb V(Y)}=0
$$
である。
この場合も、$\mathrm{Cauchy}$-$\mathrm{Schwarz}$ の不等式より
$$
|\operatorname{Cov}(X,Y)|\le0
$$
となるため、
$$
\operatorname{Cov}(X,Y)=0
$$
である。
したがって、不等式はこの場合にも成り立つ。
任意の $x\in\mathbb R$ に対して $x^2\ge0$ であるから、任意の実数 $a,b$ について
$$
(a-b)^2\ge0
$$
が成り立つ。これを展開すると
$$
a^2-2ab+b^2\ge0
$$
である。従って
$$
2ab\le a^2+b^2
$$
が得られる。ここで
$$
(a+b)^2=a^2+2ab+b^2
$$
であるから、上の不等式 $2ab\le a^2+b^2$ を用いて
$$
(a+b)^2=a^2+2ab+b^2\le a^2+(a^2+b^2)+b^2=2a^2+2b^2
$$
となる。
$$ \Box$$