Main Content

多変量分散分析 (MANOVA) の実行

多変量分散分析 (MANOVA) の紹介

1 因子 ANOVA の実行 の分散分析の手法では、グループ化されたデータセットを取り、ある変数の平均がグループ間で有意差をもつかどうかを判定します。しばしば、複数の応答変数がありますが、平均の全集合があるグループと次のグループで異なるかどうかを判定することに興味があります。この問題に対処できる、多変量バージョンの分散分析があります。

複数の応答をもつ分散分析

データ セット carsmall には、1970 年、1976 年および 1982 年のさまざまな型式の自動車に関する測定値が含まれています。自動車の特性が時間の経過に従って変化したかどうかに関心があるとします。

load carsmall
whos
  Name                Size            Bytes  Class     Attributes

  Acceleration      100x1               800  double              
  Cylinders         100x1               800  double              
  Displacement      100x1               800  double              
  Horsepower        100x1               800  double              
  MPG               100x1               800  double              
  Mfg               100x13             2600  char                
  Model             100x33             6600  char                
  Model_Year        100x1               800  double              
  Origin            100x7              1400  char                
  Weight            100x1               800  double              

4 つの変数 (AccelerationDisplacementHorsepowerMPG) は、個々の自動車のモデルに関する連続測定です。変数 Model_Year は、自動車が生産された年を表します。これらの変数のグループ化されたプロット行列は、関数gplotmatrixを使用すると作成できます。

関数 gplotmatrix を使って、これらの変数のグループ化されたプロット行列を作成します。

x = [MPG Horsepower Displacement Weight];
gplotmatrix(x,[],Model_Year,[],'+xo')

Figure contains 16 axes objects. Axes object 1 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 2 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 3 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 4 contains 3 objects of type line. Axes object 5 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 6 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 7 contains 3 objects of type line. Axes object 8 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 9 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 10 contains 3 objects of type line. Axes object 11 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 12 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 13 contains 3 objects of type line. Axes object 14 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 15 contains 3 objects of type line. One or more of the lines displays its values using only markers Axes object 16 contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent 70, 76, 82.

(gplotmatrix の 2 番目の引数が空である場合、引数 x の各列が互いに対して図示され、対角線に沿ってヒストグラムが配置されます。空の 4 番目の引数は、既定の色を使ってグラフを作成します。5 番目の引数は、グループ間を区別するために使う記号を制御します)。

自動車は年単位で異なることがわかります。たとえば、右上のプロットは、MPG に対する Weight のグラフです。1982 年の自動車は、それ以前の自動車よりも燃費が良く、平均で重量が軽いことがわかります。しかし、グループとしては、3 つの年の間ではそれぞれの年で有意差がありますか。関数manova1を使用すると、その疑問に答えることができます。

[d,p,stats] = manova1(x,Model_Year)
d = 2
p = 2×1
10-6 ×

    0.0000
    0.1141

stats = struct with fields:
           W: [4x4 double]
           B: [4x4 double]
           T: [4x4 double]
         dfW: 90
         dfB: 2
         dfT: 92
      lambda: [2x1 double]
       chisq: [2x1 double]
     chisqdf: [2x1 double]
    eigenval: [4x1 double]
    eigenvec: [4x4 double]
       canon: [100x4 double]
       mdist: [2.8187 0.7899 0.6187 0.4050 0.8538 4.2337 6.0117 4.9600 6.8415 2.3139 NaN NaN NaN NaN NaN 3.2824 1.2757 NaN 6.5549 31.5273 3.4504 3.2043 4.7424 5.4743 4.2070 9.4102 6.1146 3.9290 4.0775 5.2368 4.1540 7.1245 7.9139 ... ] (1x100 double)
      gmdist: [3x3 double]
      gnames: {3x1 cell}

関数 manova1 は、3 つの出力を生成します。

  • 1 つ目の出力 d は、グループ平均の次元の推定です。平均がすべて同じである場合、次元は 0 になります。これは、平均が同じ点にあることを意味します。平均が異なっていても直線に沿っている場合、次元は 1 になります。この例の次元は 2 です。これは、グループ平均が平面内にあり直線には沿っていないことを示します。これは、3 つのグループの平均として取り得る最大の次元です。

  • 2 つ目の出力 p は、一連の検定に対する p 値のベクトルです。最初の p 値は次元が 0 であるかどうかを、次の値は次元が 1 であるかどうかを検定します。以降同様です。この場合、両方の p 値は、非常に小さい値です。これが、推定された次元が 2 である理由です。

  • 3 つ目の出力 stats は、次の節で説明する、いくつかのフィールドを含む構造体です。

stats 構造体のフィールド

フィールド WB および T は、通常の 1 因子 ANOVA における級内二乗和、級間二乗和および二乗総和に類似する行列です。次の 3 つのフィールドは、これらの行列に対する自由度です。フィールド lambdachisqchisqdf は、グループ平均の次元に対する検定の構成要素です (これらの検定の p 値は、manova1 の最初の出力引数です)。

次の 3 つのフィールドは、正準分析を行うために使われます。主成分分析 (PCA)で、可能な最大のばらつきをもつオリジナルの変数の組み合わせを探すことを思い出してください。多変量分散分析では、代わりにグループ間で最大の区切りをもつようなオリジナルの変数の線形結合を見つけます。一変量一要因分散分析において最も有意な結果を示すのは、1 変数です。その組み合わせが見つかったら、次に 2 番目に大きい区切りをもつ組み合せを見つける、というように行います。

eigenvec フィールドは、オリジナルの変数の線形結合の係数を定義する行列です。eigenval フィールドは、対応する線形結合に対して、グループ分散とグループ内分散の比を測るベクトルです。canon フィールドは、正準変数値の行列です。各列は、eigenvec 行列からの係数を使って、平均が中央に位置するオリジナルの変数の線形結合です。

c1 = stats.canon(:,1);
c2 = stats.canon(:,2);

最初の 2 つの正準変数のグループ化された散布図をプロットします。

figure
gscatter(c2,c1,Model_Year,[],'oxs')

Figure contains an axes object. The axes object with xlabel c2, ylabel c1 contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent 70, 76, 82.

最初の 2 つの正準変数をグループ化した散布図は、任意のオリジナル変数のペアをグループ化した散布図よりも、グループ間の隔たりをより明確に示しています。この例では、3 つの点の雲が重なっていますが、中心が別個であることを示します。右下の 1 つの点は、その他の点とは離れています。このプロット上の点は、関数gnameを使ってマークできます。

大まかに言うと、最初の正準変数 c1 は、1982 年の自動車 (c1 という高い値をもつ) をそれ以前の自動車と区別しています。2 番目の正準変数 c2 は、1970 年の自動車と 1976 年の自動車の明確な区別を示しています。

stats 構造体の最後の 2 つのフィールドは、マハラノビス距離です。フィールド mdist は、各点からそのグループ平均までの距離を測ります。大きい値をもつ点は、外れ値である場合があります。このデータ セットにおける最大の外れ値は、散布図内の Buick Estate ステーション ワゴンです (点をその行番号ではなくモデル名でラベル付けする場合は、上記の関数 gname にモデル名を指定できたことに注意してください)。

グループ平均からの最大距離を見つけます。

max(stats.mdist)
ans = 31.5273

グループ平均からの最大距離のポイントを見つけます。

find(stats.mdist == ans)
ans = 20

グループ平均からの最大距離に対応する自動車モデルを見つけます。

Model(20,:)
ans = 
'buick estate wagon (sw)          '

フィールド gmdist は、グループ平均の各ペア間の距離を測ります。grpstats を使用してグループ平均を調べます。

grpstats(x, Model_Year)
ans = 3×4
103 ×

    0.0177    0.1489    0.2869    3.4413
    0.0216    0.1011    0.1978    3.0787
    0.0317    0.0815    0.1289    2.4535

グループ平均の各ペア間の距離を求めます。

stats.gmdist
ans = 3×3

         0    3.8277   11.1106
    3.8277         0    6.1374
   11.1106    6.1374         0

予想されるように、極端な年である 1970 年 と 1982 年の間の多変量距離 (11.1) は、より間隔が狭い年の差 (3.8 および 6.1) よりも大きくなります。これは、1970 年から 1976 年を経て 1982 年へ年度が変わることによる変化に点が従って見える散布図と一致しています。より多くのグループがある場合、平均間の距離によって形成されるグループのクラスターを表す図の描画には、関数manovaclusterが便利だとわかるかもしれません。

参考

| | |