LoginSignup
0
0

More than 1 year has passed since last update.

Octave で相関係数行列,分散共分散行列

Posted at

Octave で相関係数行列,分散共分散行列

データ行列のすべての 2 列の組み合わせで,相関係数,分散共分散を計算する。

usage:
corr (x)
corr (x, y)

cov (x)
cov (x, y)

x, y: データ行列

使用例

pkg load statistics % statistics が必要
format long % 表示精度を高くする(任意)
x = csvread("iris.csv")(2:151, 2:5);

相関係数行列

corr(x)
ans =

   1.000000000000000  -0.117569784133002   0.871753775886583   0.817941126271576
  -0.117569784133002   1.000000000000000  -0.428440104330540  -0.366125932536440
   0.871753775886583  -0.428440104330540   1.000000000000000   0.962865431402796
   0.817941126271576  -0.366125932536440   0.962865431402796   1.000000000000000
a = x(:, 1:2);
b = x(:, 3:4);
corr(a, b)
ans =

   0.871753775886583   0.817941126271576
  -0.428440104330540  -0.366125932536439

分散共分散行列

cov(x)
ans =

 Columns 1 through 3:

   6.856935123042505e-01  -4.243400447427291e-02   1.274315436241610e+00
  -4.243400447427291e-02   1.899794183445188e-01  -3.296563758389263e-01
   1.274315436241610e+00  -3.296563758389263e-01   3.116277852348994e+00
   5.162706935123044e-01  -1.216393736017898e-01   1.295609395973154e+00

 Column 4:

   5.162706935123044e-01
  -1.216393736017898e-01
   1.295609395973154e+00
   5.810062639821029e-01
cov(a, b)
ans =

   1.274315436241611   0.516270693512304
  -0.329656375838926  -0.121639373601790
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0