Loading [MathJax]/extensions/TeX/AMSmath.js
データ分析理論

多変量データの行列・ベクトル表現と導出 〜多変量データ行列から分散共分散行列まで〜

アイキャッチ画像

この記事では、多変量解析法を理論展開する際の基礎となる多変量データの行列・ベクトル表記を、標本データと母集団の2つの視点から体系的かつ厳密にまとめています。

本記事は、以下のような方に最適です。

  • 多変量解析の理論を学び始めた人
  • 行列・ベクトル表記を用いて、多変量データに対する簡潔かつ首尾一貫した表記法を知りたい人

また、線形代数を学び始めた人が統計解析の理論展開に慣れる上でも本記事は役立つはずです。

多変量データの行列・ベクトル表現

このセクションでは、標本としての多変量データに関して、最も基本的な多変量データ行列から始めて、平均偏差行列や偏差積率行列を経由しつつ、最終的には、分散共分散行列、相関行列までを一気貫通で導出していきます。

多変量データ行列/データベクトル

p個の測定変数 x_1, x_2, \cdots , x_p について、n個体分のデータをとり、これらをn行p列の表形式にまとめたとします。ちょうど、エクセルデータやデータベースのテーブルデータに相当します。

このn行p列の表形式データを、そのままn\times p行列とみなしたとき、この行列を多変量データ行列と言います。

本記事では、これ以降、多変量データ行列をn\times p行列として、 X で表します。

X = \begin{pmatrix} x_{11} & x_{12} & \dots & x_{1p} \\ x_{21} & x_{22} & \dots & x_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ x_{n1} & x_{n2} & \dots & x_{np} \\ \end{pmatrix}

多変量データ行列の特徴は行単位・列単位という2つの視点で捉えるとはっきりします。

まず、行単位で見れば、例えば、第j行の場合、個体jに関するp個の測定変数に関する測定データが格納されています。

ここから、 X の各行は「個体ごとの確率変数ベクトル X の実現値」ともみなすことができます。これに関しては、本記事の後半で改めて説明します。

より重要なのは、列単位の視点です。 Xを列単位で見ると、例えば、第i列の場合、変数 x_i に関するn個体分の測定データが格納されています。

この事実を利用して、第i列のみを取り出し、それをn次元列ベクトル\mathbf{x}_iとして扱うことを考えます。

\mathbf{x}_i = \begin{pmatrix} x_{1i} \\ x_{2i} \\ \vdots \\ x_{ni} \end{pmatrix}

このベクトルを、変数x_iに関するデータベクトルと定義します。

多変量データ行列 Xからは p個のデータベクトルを作ることができますが、これらp個のデータベクトルを用いると、Xは以下のようにも表されます。

X = \begin{pmatrix}\mathbf{x}_1 & \mathbf{x}_2 & \cdots & \mathbf{x}_p\end{pmatrix}

この表記法は、以降の理論展開で重要な役割を果たします。

標本平均ベクトル

標本平均ベクトル\bar{\mathbf{x}}とは、p個の測定変数の標本平均を要素とするp次元ベクトルです。

\bar{\mathbf{x}} = \begin{pmatrix} \bar{x_1} \\ \bar{x_2} \\ \vdots \\ \bar{x_p} \end{pmatrix}\:\:\: \bar{x}_i = \frac{1}{n}\sum_{k=1}^n x_{ki}

\bar{\mathbf{x}}は、多変量データ行列 X から算出できます。

まず、 Xに対して、全ての要素が1のn次元ベクトル\mathbf{1} = (1\: 1\: \cdots\: 1)^\topを用いた \mathbf{1}^\top X という積を考えます。

\begin{align} \mathbf{1}^\top X &= \mathbf{1}^\top\begin{pmatrix}\mathbf{x}_1 & \mathbf{x}_2 & \cdots & \mathbf{x}_p\end{pmatrix}\\ &= \begin{pmatrix} \mathbf{1}^\top \mathbf{x}_1 & \mathbf{1}^\top \mathbf{x}_2 & \cdots & \mathbf{1}^\top \mathbf{x}_p\end{pmatrix}\\ &= \left(\sum_{k=1}^{n} x_{k1}\: \sum_{k=1}^{n} x_{k2}\: \cdots \sum_{k=1}^{n} x_{kp}\right) \end{align}

上記が示す通り、 \mathbf{1}^\top Xは、変数ごと(Xの列ごと)のデータの合計を要素とする1\times p行列です。

これを利用すれば、標本平均ベクトル\bar{\mathbf{x}}と多変量データ行列 X の関係式は以下のようになります。

\begin{align} \bar{\mathbf{x}} &= \frac{1}{n}(\mathbf{1}^\top X)^\top \\ &= \frac{1}{n}X^\top \mathbf{1} \\ &= (\bar{x_1}\: \bar{x_2}\: \cdots \bar{x_p})^\top \end{align}

上式のX^\topは多変量データ行列 Xの転置行列ですが、 X = \begin{pmatrix}\mathbf{x}_1 & \mathbf{x}_2 & \cdots & \mathbf{x}_p\end{pmatrix} なので、

\begin{align} X^\top &= \begin{pmatrix} \mathbf{x}_1 & \mathbf{x}_2 & \cdots & \mathbf{x}_p \end{pmatrix}^\top \\ &= \begin{pmatrix} \mathbf{x}_{1}^\top \\ \mathbf{x}_{2}^\top \\ \vdots \\ \mathbf{x}_{p}^\top \end{pmatrix}\\ \end{align}

と表されます。Xでは、「列」が「変数」、「行」が「個体の測定データ」だったのに対し、X^\topでは、「列」が「個体の測定データ」、「行」が「変数項目」になります。

なお、本節で導入した全ての要素が1のn次元ベクトル\mathbf{1} = (1\: 1\: \cdots\: 1)^\topですが、以降でもしばしば利用します。特に断りがない限り、\mathbf{1} は、本節と同様にn次元の列ベクトルであるとします。当然、全ての要素は1です。

標本平均行列

n次元ベクトル\mathbf{1}とp次元標本平均ベクトル\bar{\mathbf{x}}を用いて、\mathbf{1}\bar{\mathbf{x}}^\topという積をとれば、全ての行が\bar{\mathbf{x}}^\topn \times p行列が生成されます。この行列を標本平均行列と定義します。

\begin{align} \mathbf{1}\bar{\mathbf{x}}^\top &= \begin{pmatrix} 1\\ 1\\ \vdots\\ 1 \end{pmatrix}(\bar{x_1}\: \bar{x_2}\: \cdots \bar{x_p})\\ &= \begin{pmatrix} \bar{x_1} & \bar{x_2} & \dots & \bar{x_p} \\ \bar{x_1} & \bar{x_2} & \dots & \bar{x_p} \\ \vdots & \vdots & \ddots & \vdots \\ \bar{x_1} & \bar{x_2} & \dots & \bar{x_p} \\ \end{pmatrix} \\ &= \begin{pmatrix} \bar{\mathbf{x}}^\top \\ \bar{\mathbf{x}}^\top \\ \vdots \\ \bar{\mathbf{x}}^\top \end{pmatrix} \end{align}

標本平均行列は、標本平均ベクトル\bar{\mathbf{x}} の拡張で、次に導入する平均編纂行列の算出に必要な行列です。

平均偏差行列

平均偏差行列X_Cとは、多変量データ行列Xと標本平均行列\mathbf{1}\bar{\mathbf{x}}^\topから算出されるn \times p行列です。

\begin{align} X_C &= X – \mathbf{1}\bar{\mathbf{x}}^\top \\ &= \begin{pmatrix} x_{11} & x_{12} & \dots & x_{1p} \\ x_{21} & x_{22} & \dots & x_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ x_{n1} & x_{n2} & \dots & x_{np} \\ \end{pmatrix} – \begin{pmatrix} \bar{x_1} & \bar{x_2} & \dots & \bar{x_p} \\ \bar{x_1} & \bar{x_2} & \dots & \bar{x_p} \\ \vdots & \vdots & \ddots & \vdots \\ \bar{x_1} & \bar{x_2} & \dots & \bar{x_p} \\ \end{pmatrix} \end{align}

X_C(i,j)要素には、個体iの変数x_jに関する平均偏差データが格納されています。

以降のことも考慮して、X_C(i,j)成分を\acute{x_{ij}}とおきます。このとき、\acute{x_{ij}}X(i,j)成分x_{ij}\mathbf{1}\bar{\mathbf{x}}^\topのj列目の任意の要素\bar{x_j}との差として

\acute{x_{ij}} = x_{ij} – \bar{x_j}

と表されます。よって、

X_C = \begin{pmatrix} \acute{x_{11}} & \acute{x_{12}} & \dots & \acute{x_{1p}} \\ \acute{x_{21}} & \acute{x_{22}} & \dots & \acute{x_{2p}} \\ \vdots & \vdots & \ddots & \vdots \\ \acute{x_{n1}} & \acute{x_{n2}} & \dots & \acute{x_{np}} \\ \end{pmatrix}

平均偏差ベクトル

変数x_iに関する平均偏差ベクトルとは、多変量データXのときと同様に、平均偏差行列X_Cを列単位のn次元ベクトルとしてまとめて、

X_C = (\acute{\mathbf{x_1}}\: \acute{\mathbf{x_2}}\: \cdots \acute{\mathbf{x_p}})

とおきいたときのn次元ベクトル\acute{\mathbf{x}_i}です。

\acute{\mathbf{x}_i}は、測定変数x_iに関するn個体分の平均偏差を要素にもつn次元ベクトルです。つまり、

\acute{\mathbf{x}_i} = \begin{pmatrix} x_{1i} – \bar{x}_i \\ x_{2i} – \bar{x}_i \\ \vdots \\ x_{ni} – \bar{x}_i \\ \end{pmatrix}

平均偏差ベクトルを導入することで、いくつかの馴染みのある統計量をベクトル表記で簡潔に表すことができます。

まず、観測変数x_iの偏差平方和S_{x_i x_i}は、

S_{x_i x_i} = \sum_{k=1}^{n} (x_{ki} – \bar{x}_i)^2 = \acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_i} = \|\acute{\mathbf{x}_i}\|^2

と、変数 x_iに関する平均偏差ベクトル \acute{\mathbf{x}_i} のノルムの二乗となります。

続いて、x_ix_jの偏差積和S_{x_i x_j}は、

S_{x_i x_j} = \sum_{k=1}^n (x_{ki} – \bar{x}_i)(x_{kj}-\bar{x}_j) = \acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_j}

と、変数 x_iに関する平均偏差ベクトル \acute{\mathbf{x}_i}と変数 x_jに関する平均偏差ベクトル \acute{\mathbf{x}_j}の内積となります。

よって、x_ix_jの相関係数r_{x_i x_j}は、

r_{x_i x_j} = \frac{S_{x_i x_j}}{\sqrt{S_{x_i x_i}S_{x_j x_j}}} = \frac{\acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_j}}{\|\acute{\mathbf{x}_i}\| \; \|\acute{\mathbf{x}_j}\|}

です。つまり、変数 x_iに関する正規化された平均偏差ベクトル

\frac{\acute{\mathbf{x}_i}}{\|\mathbf{x}_i\|}

と変数 x_jに関する正規化された平均偏差ベクトル

\frac{\acute{\mathbf{x}_i}}{\|\mathbf{x}_i\|}

の内積となります。ここで、一般に正規化されたベクトルどうしの内積は\cos \thetaに等しいので、

r_{x_i x_j} = \frac{\acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_j}}{\|\acute{\mathbf{x}_i}\| \; \|\acute{\mathbf{x}_j}\|} = \cos \theta

と表せます。\thetaは、\acute{\mathbf{x}_i}\acute{\mathbf{x}_j}のなす角です。この辺りのより詳しい解説は『コーシー・シュワルツ不等式とその証明 〜内積/コサイン/角度との関連〜』で解説しているので参考にしてください。

アイキャッチ画像
コーシー・シュワルツ不等式とその証明 〜内積/コサイン/角度との関連〜本記事では、ベクトルで表されたコーシー・シュワルツ不等式の証明を、1)幾何学的な方法、2)代数的な方法の2パターンで解説していきます。その後は、コーシー・シュワルツ不等式から、まず、内積とコサインの関係式を導き、さらには「2つの異なるベクトルの角度」の概念の自然な導出を試みます。...

 

また、X_{C}^\top \mathbf{1} = \mathbf{0}が成り立つことにも注意しましょう。なぜなら、X_C = (\acute{\mathbf{x_1}}\: \acute{\mathbf{x_2}}\: \cdots \acute{\mathbf{x_p}})に対して、

\begin{align} X_{C}^\top \mathbf{1} &= \begin{pmatrix} \acute{\mathbf{x}_1}^\top \\ \acute{\mathbf{x}_2}^\top \\ \vdots \\ \acute{\mathbf{x}_p}^\top \end{pmatrix}\mathbf{1} \\\\ &=\begin{pmatrix} \acute{\mathbf{x}_1}^\top \mathbf{1} \\ \acute{\mathbf{x}_2}^\top \mathbf{1} \\ \vdots \\ \acute{\mathbf{x}_p}^\top \mathbf{1} \\ \end{pmatrix} \end{align}

であり、i番目の要素\acute{\mathbf{x}_i}^\top \mathbf{1}は、

\begin{align} \acute{\mathbf{x}_1}^\top \mathbf{1} &= \sum_{k=1}^n (x_{ki}-\bar{x}_i)\\ &= \sum_{k=1}^n x_{ki} – \sum_{k=1}^n \bar{x}_i \\ &= n \bar{x}_i – n \bar{x}_i \\ &= 0 \end{align}

なので、X_{C}^\top \mathbf{1}の全ての要素は0となり、X_{C}^\top \mathbf{1} = \mathbf{0}が成り立ちます。要するに、「ある変数に関する偏差データの合計は0」ということです。

偏差積率行列

平均偏差行列 X_Cをもとに、X_C^\top X_Cという行列を定めます。この行列を偏差積率行列と定義します。

\begin{align} X_{C}^\top X_C &= \begin{pmatrix} \acute{\mathbf{x}_1}^\top \\ \acute{\mathbf{x}_2}^\top \\ \vdots \\ \acute{\mathbf{x}_p}^\top \end{pmatrix}\;(\acute{\mathbf{x}_1}\: \acute{\mathbf{x}_2}\: \cdots \acute{\mathbf{x}_p}) \\\\ &= \begin{pmatrix} \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_1} & \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_2} & \dots & \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_p} \\ \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_1} & \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_2} & \dots & \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_p} \\ \vdots & \vdots & \ddots & \vdots \\ \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_1} & \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_2} & \dots & \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_p} \\ \end{pmatrix}\\\\ &= \begin{pmatrix} \|\acute{\mathbf{x}_1}\|^2 & \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_2} & \dots & \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_p} \\ \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_1} & \|\acute{\mathbf{x}_2}\|^2 & \dots & \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_p} \\ \vdots & \vdots & \ddots & \vdots \\ \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_1} & \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_2} & \dots & \|\acute{\mathbf{x}_p}\|^2 \\ \end{pmatrix} \end{align}

偏差積率行列は、p次対称行列であり、第i対角成分には、変数 x_iの偏差平方和\|\acute{\mathbf{x}_i}\|^2 、第 (i,j),(j,i)非対角成分には、変数x_i,\; x_jの偏差積和\acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_j} があります。

この行列は、さまざまな多変量解析法の土台にもなる行列でとても重要です。特に、X_C^\top X_Cのランクは、次に説明する分散共分散行列の逆行列が求まるかどうかの指標にもなります。

(標本)分散共分散行列

偏差積率行列X_{C}^\top X_Cから、p個の変数x_1, x_2, \cdots, x_pに関する分散共分散行列Vが定まります。

\begin{align} V &= \frac{1}{n}X_{C}^\top X_C \\\\ &= \frac{1}{n}\begin{pmatrix} \acute{\mathbf{x}_1}^\top \\ \acute{\mathbf{x}_2}^\top \\ \vdots \\ \acute{\mathbf{x}_p}^\top \end{pmatrix}\;(\acute{\mathbf{x}_1}\: \acute{\mathbf{x}_2}\: \cdots \acute{\mathbf{x}_p}) \\\\ &= \frac{1}{n}\begin{pmatrix} \|\acute{\mathbf{x}_1}\|^2 & \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_2} & \dots & \acute{\mathbf{x}_1}^\top \acute{\mathbf{x}_p} \\ \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_1} & \|\acute{\mathbf{x}_2}\|^2 & \dots & \acute{\mathbf{x}_2}^\top \acute{\mathbf{x}_p} \\ \vdots & \vdots & \ddots & \vdots \\ \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_1} & \acute{\mathbf{x}_p}^\top \acute{\mathbf{x}_2} & \dots & \|\acute{\mathbf{x}_p}\|^2 \\ \end{pmatrix} \end{align}

\acute{\mathbf{x}_i}は、変数x_iに関するn次元平均偏差ベクトル

\acute{\mathbf{x}_i} = \begin{pmatrix} x_{1i} – \bar{x}_i \\ x_{2i} – \bar{x}_i \\ \vdots \\ x_{ni} – \bar{x}_i \\ \end{pmatrix}

でした。よって、Vの第i対角成分をv_{ii}とすれば、

v_{ii} = \frac{1}{n} \|\acute{\mathbf{x}_i}\|^2 = \frac{1}{n}\sum_{k=1}^n(x_{ki} – \bar{x_i})^2

となり、x_iの標本分散です。

一方で、Vの第(i,j)非対角成分をv_{ij}とすれば、

v_{ij} = \frac{1}{n}\acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_j} = \frac{1}{n-1}\sum_{k=1}^n (x_{ki} – \bar{x}_i)(x_{kj}-\bar{x}_j)

となり、x_ix_jの共分散になります。

(標本)分散行列・(標本)標準偏差行列

分散共分散行列Vの対角成分のみを抽出した行列を(標本)分散行列 D として定義します。

\begin{align} D &= \frac{1}{n} \mathrm{diag} (X_{C}^\top X_C) \\ &= \frac{1}{n} \begin{pmatrix} \|\acute{\mathbf{x}_1}\|^2 \\ & \|\acute{\mathbf{x}_2}\|^2 & & \huge{0} \\ & &  \ddots& &\\ & \huge{0} & & \|\acute{\mathbf{x}_p}\|^2 \end{pmatrix} \end{align}

分散行列Dに対して、全ての成分の平方根をとった行列を(標本)標準偏差行列D^{1/2}として定めます。

D^{1/2} = \frac{1}{\sqrt{n}}\begin{pmatrix} \|\acute{\mathbf{x}_1}\| \\ & \|\acute{\mathbf{x}_2}\| & & \huge{0} \\ & & \ddots & & \\ & \huge{0} & & \|\acute{\mathbf{x}_p}\| \end{pmatrix}

これらの行列は、多変量データ行列 Xを標準化し、標準化データ行列を生成するために使います。

標準化データ行列

標準偏差行列D^{1/2}を利用して、多変量データ行列Xの全ての変数に関するデータを平均0、分散1に標準化することを考えます。

標準偏差行列D^{1/2}は対角行列なので、その逆行列D^{-1/2}は、

\begin{align} D^{-1/2} &= \begin{pmatrix} \sqrt{n}/\|\acute{\mathbf{x}_1}\| \\ & \sqrt{n}/\|\acute{\mathbf{x}_2}\| & & \huge{0} \\ &  &  \ddots & &\\ & \huge{0} & & \sqrt{n}/\|\acute{\mathbf{x}_p}\| \end{pmatrix} \\\\ &= \begin{pmatrix} 1/\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\} \\ & 1/\{\|\acute{\mathbf{x}_2}\|/\sqrt{n}\} & &\huge{0} \\ & & \ddots & &\\ & \huge{0} & & 1/\{\|\acute{\mathbf{x}_p}\| / \sqrt{n}\} \end{pmatrix} \end{align}

D^{-1/2} を用いることで、Xを平均0、分散1に標準化した標準化データ行列Zが定まります。

\begin{align} Z &= X_C D^{-1/2} \\ &= (\acute{\mathbf{x_1}}\: \acute{\mathbf{x_2}}\: \cdots \acute{\mathbf{x_p}}) \begin{pmatrix} 1/\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\} \\ & 1/\{\|\acute{\mathbf{x}_2}\|/\sqrt{n}\} & &\huge{0} \\ & & \ddots & &\\ & \huge{0} & & 1/\{\|\acute{\mathbf{x}_p}\| / \sqrt{n}\} \end{pmatrix}\\\\ &= \left(\frac{\acute{\mathbf{x_1}}}{\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\}}\: \frac{\acute{\mathbf{x_2}}}{\{\|\acute{\mathbf{x}_2}\|/ \sqrt{n}\}}\: \cdots \: \frac{\acute{\mathbf{x_p}}}{\{\|\acute{\mathbf{x}_p}\|/ \sqrt{n}\}}\:\right)\\\\ \end{align}

(標本)相関行列

標準化データ行列Zから標準化積率行列Z^\top Zが定まり、さらに、Z^\top Zからp個の変数x_1,x_2, \cdots, x_pに関する標本相関行列Rが定まります。

\begin{align} R &= \frac{1}{n}Z^\top Z \\\\ &= \frac{1}{n}\begin{pmatrix} \frac{\acute{\mathbf{x_1}^\top}}{\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\}} \\ \frac{\acute{\mathbf{x_2}^\top}}{\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\}} \\ \vdots \\ \frac{\acute{\mathbf{x_p}^\top}}{\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\}} \\ \end{pmatrix} \left(\frac{\acute{\mathbf{x_1}}}{\{\|\acute{\mathbf{x}_1}\|/ \sqrt{n}\}}\:\: \frac{\acute{\mathbf{x_2}}}{\{\|\acute{\mathbf{x}_2}\|/ \sqrt{n}\}}\: \cdots \: \frac{\acute{\mathbf{x_p}}}{\{\|\acute{\mathbf{x}_p}\|/ \sqrt{n}\}}\:\right) \end{align}

Rの第i対角成分をr_{ii}とすると、1になる。

\begin{align} r_{ii} &= \frac{1}{n} \frac{\acute{\mathbf{x_i}^\top}}{\{\|\acute{\mathbf{x}_i}\|/ \sqrt{n}\}}\:\:\: \frac{\acute{\mathbf{x_i}}}{\{\|\acute{\mathbf{x}_i}\|/ \sqrt{n}\}}\\\\ &= \frac{\acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_i}}{\|\acute{\mathbf{x}_i}\|^2} \\ &= 1 \end{align}

一方で、Rの第(i,j)非対角成分をr_{ij}とすると、x_ix_jの相関係数になる。

\begin{align} r_{ij} &= \frac{1}{n} \frac{\acute{\mathbf{x_i}}}{\{\|\acute{\mathbf{x}_i}\|/ \sqrt{n}\}}\:\:\: \frac{\acute{\mathbf{x_j}^\top}}{\{\|\acute{\mathbf{x}_j}\|/ \sqrt{n}\}}\\ &= \frac{\acute{\mathbf{x}_i}^\top \acute{\mathbf{x}_j}}{\|\acute{\mathbf{x}_i}\| \; \|\acute{\mathbf{x}_j}\|} \end{align}

(標本)積率行列

多変量データ行列Xから、標本積率行列Mを以下で定めます。

\begin{align} M &= \frac{1}{n}X^\top X \\ &= \frac{1}{n} \begin{pmatrix} \mathbf{x}_{1}^\top \\ \mathbf{x}_{2}^\top \\ \vdots \\ \mathbf{x}_{p}^\top \end{pmatrix} \begin{pmatrix}\mathbf{x}_1 & \mathbf{x}_2 & \cdots & \mathbf{x}_p\end{pmatrix} \\\\ &= \frac{1}{n}\begin{pmatrix} \|\mathbf{x}_1\| & \mathbf{x}_1^\top \mathbf{x}_2 & \dots & \mathbf{x}_1^\top \mathbf{x}_p \\ \mathbf{x}_2^\top \mathbf{x}_1 & \|\mathbf{x}_2\| & \dots & \mathbf{x}_2^\top \mathbf{x}_p \\ \vdots & \vdots & \ddots & \vdots \\ \mathbf{x}_p^\top \mathbf{x}_1 & \mathbf{x}_p^\top \mathbf{x}_2 & \dots & \|\mathbf{x}_p\| \\ \end{pmatrix}\\\\ \end{align}

ここで、\mathbf{x}_iは、変数x_i のデータベクトルなので、

\mathbf{x}_i = \begin{pmatrix} x_{1i} \\ x_{2i} \\ \vdots \\ x_{ni} \end{pmatrix}

です。従って、Mの第i対角要素は、

\frac{1}{n}\|\mathbf{x}_i\| = \frac{1}{n}\sum_{k=1}^n x_{ki}^2

であり、非対角の(i,j)要素は、

\frac{1}{n}\mathbf{x}_i^\top \mathbf{x}_j = \frac{1}{n}\sum_{k=1}^n x_{ki} x_{kj}

各種標本行列の関係性

ここでは、ここまで導出してきた行列・ベクトルの関係性を整理していきます。

分散共分散行列と相関行列の関係

標本分散共分散行列と標本相関行列の間には、標準偏差行列の逆行列 D^{-1/2}を介して、以下の関係式が成り立ちます。

\begin{align} R &= \frac{1}{n}Z^\top Z \\ &= \frac{1}{n}(X_C D^{-1/2})^\top (X_C D^{-1/2}) \\ &= \frac{1}{n}(D^{-1/2})^\top X_{C}^\top X_C D^{-1/2} \\ &= D^{-1/2}\frac{1}{n}X_{C}^\top X_C D^{-1/2} \\ &= D^{-1/2} V D^{-1/2} \end{align}

これより、直ちに以下が成り立ちます。

V = D^{1/2} R D^{1/2}

多変量データと平均偏差行列の関係

多変量データ行列 X と平均偏差行列X_C の間には、標本平均行列 \mathbf{1}\bar{\mathbf{x}}^\top を介して以下の関係があります。

X_C = X – \mathbf{1}\bar{\mathbf{x}}^\top

より、

X = X_C + \mathbf{1}\bar{\mathbf{x}}^\top

つまり、平均偏差行列X_Cと標本平均行列 \mathbf{1}\bar{\mathbf{x}}^\top があれば、多変量データ行列Xを復元できるわけです。

偏差積率行列と分散共分散行列の関係

偏差積率行列 Mは、分散共分散行列 Vと標本平均ベクトル \bar{\mathbf{x}}からなる行列に分解できます。つまり、偏差積率は、分散・共分散と平均の情報を含んでいます。

\begin{align} M &= \frac{1}{n} X^\top X \\ &= \frac{1}{n} (X_C + \mathbf{1}\bar{\mathbf{x}}^\top)^\top (X_C + \mathbf{1}\bar{\mathbf{x}}^\top) \\ &= \frac{1}{n} (X_{C}^\top + \bar{\mathbf{x}} \mathbf{1}^\top)(X_C + \mathbf{1}\bar{\mathbf{x}}^\top) \\ &= \frac{1}{n}(X_{C}^\top X_C + X_{C}^\top \mathbf{1}\bar{\mathbf{x}}^\top + \bar{\mathbf{x}}\mathbf{1}^\top X_C + \bar{\mathbf{x}} \mathbf{1}^\top \mathbf{1}\bar{\mathbf{x}}^\top)\\ &= \frac{1}{n}X_{C}^\top X_C + \frac{1}{n} \bar{\mathbf{x}} \mathbf{1}^\top \mathbf{1}\bar{\mathbf{x}}^\top \\ &= V + \bar{\mathbf{x}}\bar{\mathbf{x}}^\top \end{align}

4行から5行目への変形では、

X_{C}^\top \mathbf{1} = \mathbf{1}^\top X_C = \mathbf{0}

により、 X_{C}^\top \mathbf{1}\bar{\mathbf{x}}^\top + \bar{\mathbf{x}}\mathbf{1}^\top X_Cという項は消えます。また、\mathbf{1}は、全ての要素が1のn次元ベクトルなので、\mathbf{1}^\top \mathbf{1}=nです。

多変数の確率変数の行列・ベクトル表記

ここまでは、「標本」としての多変量データに関する行列・ベクトル表記をみてきました。ここからは、「母集団」としての多変量データに関する行列・ベクトル表記をみていきます。

確率変数ベクトル

p個の測定変数x_1,x_2,\cdots, x_pを確率変数とみなし、X_1,X_2, \cdots, X_pと表します。このとき、p次元確率変数ベクトル\mathbf{X}を以下のように定める。

\mathbf{X} = \begin{pmatrix} X_1\\ X_2\\ \vdots \\ X_p \end{pmatrix}

多変量データ行列 X を確率変数ベクトルの観点から見ると、 X の各行は、確率変数ベクトル Xの実現値という解釈が可能となります。

期待値ベクトル

p次元確率変数ベクトル\mathbf{X}に対して、p次元期待値ベクトル\boldsymbol{\mu} = E[\mathbf{X}]を以下のように定義します。

\begin{align} E[\mathbf{X}] &= \begin{pmatrix} E[X_1] \\ E[X_2]\\ \vdots \\ E[X_p] \end{pmatrix}\\ &= \begin{pmatrix} \mu_1 & \mu_2 & \cdots & \mu_p \end{pmatrix}^\top \end{align}

ただし、E[X_i] = \mu_iです。

分散共分散行列

分散共分散行列の定義に先立ち、期待値ベクトルが\mathbf{0}ベクトルの確率変数ベクトルを以下にて定めます。

\mathbf{X} – \boldsymbol{\mu} = \begin{pmatrix} X_1 – \mu_1 \\ X_2 – \mu_2 \\ \vdots \\ X_p – \mu_p \end{pmatrix}

このもとで、p次元確率変数ベクトル\mathbf{X}のp次分散共分散行列V[\mathbf{X}]を以下のように定義します。

\begin{align} V[\mathbf{X}] &= E[(\mathbf{X} – \boldsymbol{\mu})(\mathbf{X} – \boldsymbol{\mu})^\top] \\ &= E\left[\begin{pmatrix} X_1 – \mu_1 \\ X_2 – \mu_2 \\ \vdots \\ X_p – \mu_p \end{pmatrix} \begin{pmatrix} X_1-\mu_1 & X_2-\mu_2 & \cdots & X_p – \mu\end{pmatrix}\right]\\\\ &= E\left[\begin{pmatrix} (X_1 – \mu_1)^2 & (X_1 – \mu_1)(X_2 – \mu_2) & \cdots & (X_1 – \mu_1)(X_p – \mu_p) \\ (X_2 – \mu_2)(X_1 – \mu_1) & (X_2 – \mu_2)^2 & \cdots & (X_2 – \mu_2)(X_p – \mu_p) \\ \vdots & \vdots & \ddots & \vdots \\ (X_p – \mu_p)(X_1 – \mu_1) & \cdots & \cdots & (X_p – \mu_p)^2 \end{pmatrix}\right]\\\\ &= \begin{pmatrix} E[(X_1 – \mu_1)^2] & E[(X_1 – \mu_1)(X_2 – \mu_2)] & \cdots & E[(X_1 – \mu_1)(X_p – \mu_p)] \\ E[(X_2 – \mu_2)(X_1 – \mu_1)] & E[(X_2 – \mu_2)^2] & \cdots & E[(X_2 – \mu_2)(X_p – \mu_p)] \\ \vdots & \vdots & \ddots & \vdots \\ E[(X_p – \mu_p)(X_1 – \mu_1)] & \cdots & \cdots & E[(X_p – \mu_p)^2] \end{pmatrix} \\\\ &= \begin{pmatrix} V[X_1] & Cov[X_1,X_2] & \cdots & Cov[X_1, X_p] \\ Cov[X_2,X_1] & V[X_2] & \cdots & Cov[X_2, X_p] \\ \vdots & \vdots & \ddots & \vdots \\ Cov[X_p, X_1] & \cdots & \cdots & V[X_p] \end{pmatrix} \end{align}

分散行列/標準偏差行列

\mathbf{X}の分散行列\Deltaを以下にて定めます。ただし、V[X_i] = \sigma_{i}^2とおきます。

\begin{align} \Delta &= \mathrm{diag}(V[\mathbf{X}]) \\ &= \mathrm{diag}( E[(\mathbf{X} – \boldsymbol{\mu})(\mathbf{X} – \boldsymbol{\mu})^\top])\\ &= \begin{pmatrix} \sigma_{1}^2 \\ & \sigma_{2}^2 & & {\Huge O} \\ & {\Huge O} & & \ddots \\ & & & & \sigma_{p}^2 \end{pmatrix} \end{align}

分散行列\Deltaをもとにすると、標準偏差行列\Delta^{1/2}は以下のようになります。

\Delta^{1/2} = \begin{pmatrix} \sigma_{1} \\ & \sigma_{2} & & {\Huge O} \\ & {\Huge O} & & \ddots \\ & & & & \sigma_{p} \end{pmatrix}

標準化された確率変数ベクトル

確率変数ベクトル\mathbf{X}を標準化した\mathbf{Z}を考えていきます。

\mathbf{Z}は、期待値ベクトル\boldsymbol{\mu}と標準偏差行列\Delta^{1/2}の逆行列\Delta^{-1/2}を用いて以下のように定義されます。

\begin{align} \mathbf{Z} &= \Delta^{-1/2} (\mathbf{X} – \boldsymbol{\mu}) \\ &= \begin{pmatrix} 1/\sigma_{1} \\ & 1/\sigma_{2} & & {\Huge O} \\ & {\Huge O} & & \ddots \\ & & & & 1/\sigma_{p} \end{pmatrix}\begin{pmatrix} X_1 – \mu_1 \\ X_2 – \mu_2 \\ \vdots \\ X_p – \mu_p \end{pmatrix}\\\\ &= \begin{pmatrix} (X_1 – \mu_1)/\sigma_1 \\ (X_2 – \mu_2)/\sigma_2 \\ \vdots \\ (X_p – \mu_p)/\sigma_p \end{pmatrix} \end{align}

以上のように定義された\mathbf{Z}が標準化されていることを確かめてみます。

すなわち、\mathbf{Z}の期待値ベクトルが \mathbf{0}に 、分散共分散行列 V[\mathbf{Z}] が対角成分((母)分散)が1で、非対角成分が(母)相関係数になることを確認します。

まず、\mathbf{Z}の期待値ベクトルE[\mathbf{Z}]は、

\begin{align} E[\mathbf{Z}] &= E[\Delta^{-1/2}\: (\mathbf{X} – \boldsymbol{\mu})]\\ &= \Delta^{-1/2}\:\{E[\mathbf{X}]- \boldsymbol{\mu}\} \\ &= \mathbf{0} \end{align}

次に、\mathbf{Z}の分散共分散行列V[\mathbf{Z}]は、

\begin{align} V[\mathbf{Z}] &= E[\{\Delta^{-1/2}\: (\mathbf{X} – \boldsymbol{\mu})-E[\mathbf{Z}]\}\{\Delta^{-1/2}\: (\mathbf{X} – \boldsymbol{\mu})-E[\mathbf{Z}]\}^\top] \\ &= E[\{\Delta^{-1/2} \:(\mathbf{X} – \boldsymbol{\mu})\}\{\Delta^{-1/2} \:(\mathbf{X} – \boldsymbol{\mu})\}^\top] \\ &= E[\Delta^{-1/2}\: (\mathbf{X} – \boldsymbol{\mu})(\mathbf{X} – \boldsymbol{\mu})^\top \Delta^{-1/2}\:]\\ &=\Delta^{-1/2}\: E[(\mathbf{X} – \boldsymbol{\mu})(\mathbf{X} – \boldsymbol{\mu})^\top]\Delta^{-1/2}\\ &=\Delta^{-1/2}\: V[\mathbf{X]}\Delta^{-1/2}\\ \end{align}

であり、V[\mathbf{Z}]の第i対角成分は

\frac{V[X_i]}{\sigma_{i}^2} = \frac{V[X_i]}{V[X_i]} =1

V[\mathbf{Z}]の非対角成分の(i,j)成分は

\frac{Cov[X_i,X_j]}{\sigma_i \sigma_j} = \frac{Cov[X_i,X_j]}{\sqrt{V[X_i]\cdot V[X_j]}}= \rho[X_i,X_j]

参考図書

本記事を作成するにあたり使用した書籍を紹介します。

統計学のための数学入門30講

行列を列単位・行単位でまとめる表記法や統計量のベクトル表記はこの本を参考にさせて頂きました。

統計学を理論的に学ぶための必要最低限の数学が微積分・線形代数・多変数微積分の3パートでコンパクトにまとめられています。

また、コラム的な扱いではあるものの数理統計学の解説も非常に学びがあります。

共分散構造分析〜入門編〜

本記事の大枠は、本書の第2章によるところが大きいです。多変量データからスタートして相関行列までをきっちり導出する過程は本書から多大な学びを得ました。

また、本書は共分散構造分析の入門書であり、共分散構造分析を理論的にきっちり学びたい人には最適な本でもあります。

プログラミングのための確率統計

「母集団」としての確率変数ベクトル、分散共分散行列の各種式変形は、この本を参考にしています。

期待値記号の中に入った定数行列や定数ベクトルの操作で不安がある人は、この本で詳細に解説しています。

また、本書は、数理統計学や機械学習理論の最低限の基礎になる確率論を平易に解説している書籍でもあります。