相関行列

COR=function(X,sel=1) sel=0:相関行列; 1:共分散行列

COR(X=D,s=0)
s=0:相関行列; 1:共分散行列

D=Ip('x45') #簡単なデータ例 x45.txt
## File: x45.txt / Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3
COR(s=0) #相関係数行列
##            A          B          C          D         E
## A  1.0000000  0.7869105  0.9439288 -0.4803934 0.4361146
## B  0.7869105  1.0000000  0.9449976 -0.0918305 0.8958233
## C  0.9439288  0.9449976  1.0000000 -0.3313783 0.7086724
## D -0.4803934 -0.0918305 -0.3313783  1.0000000 0.1404660
## E  0.4361146  0.8958233  0.7086724  0.1404660 1.0000000
COR(s=1) #共分散行列
##          A       B       C       D       E
## A  27.6875 31.3125 27.0625 -11.375 10.4375
## B  31.3125 57.1875 38.9375  -3.125 30.8125
## C  27.0625 38.9375 29.6875  -8.125 17.5625
## D -11.3750 -3.1250 -8.1250  20.250  2.8750
## E  10.4375 30.8125 17.5625   2.875 20.6875

連関行列 (Association matrix)

AM(M=D,s=‘a’)
s=‘s’: (A+D)/(A+B+C+D)#Simple

D=Ip('q54') #簡単なデータ例 q54.txt
## File: q54.txt / Class: data.frame / Rows: 5 / Columns: 4
##  
##    v1 v2 v3 v4
## d1 1  1  0  0 
## d2 0  0  1  0 
## d3 0  1  0  0 
## d4 0  0  1  1 
## d5 1  1  1  0
AM(s='a') # 共起回数
##    v1 v2 v3 v4
## v1  2  2  1  0
## v2  2  3  1  0
## v3  1  1  3  1
## v4  0  0  1  1
AM(s='s') # (A+D)/(A+B+C+D)#Simple
##     v1  v2  v3  v4
## v1 1.0 0.8 0.4 0.4
## v2 0.8 1.0 0.2 0.2
## v3 0.4 0.2 1.0 0.6
## v4 0.4 0.2 0.6 1.0
AM(s='j') # A/(A+B+C)#Jaccard
##           v1        v2        v3        v4
## v1 1.0000000 0.6666667 0.2500000 0.0000000
## v2 0.6666667 1.0000000 0.2000000 0.0000000
## v3 0.2500000 0.2000000 1.0000000 0.3333333
## v4 0.0000000 0.0000000 0.3333333 1.0000000
AM(s='d') # 2*A/(2*A+B+C)#Dice
##     v1        v2        v3  v4
## v1 1.0 0.8000000 0.4000000 0.0
## v2 0.8 1.0000000 0.3333333 0.0
## v3 0.4 0.3333333 1.0000000 0.5
## v4 0.0 0.0000000 0.5000000 1.0
AM(s='h') # ((A+D)-(B+C))/((A+D)+(B+C))#Hamann
##      v1   v2   v3   v4
## v1  1.0  0.6 -0.2 -0.2
## v2  0.6  1.0 -0.6 -0.6
## v3 -0.2 -0.6  1.0  0.2
## v4 -0.2 -0.6  0.2  1.0
AM(s='y') # (A*D-B*C)/(A*D+B*C)#Yule
##            v1 v2         v3 v4
## v1  1.0000000  1 -0.3333333 -1
## v2  1.0000000  1 -1.0000000 -1
## v3 -0.3333333 -1  1.0000000  1
## v4 -1.0000000 -1  1.0000000  1
AM(s='p') # (A*D-B*C)/((A+B)*(C+D)*(A+C)*(B+D))^(1/2)#Phi
##            v1         v2         v3         v4
## v1  1.0000000  0.6666667 -0.1666667 -0.4082483
## v2  0.6666667  1.0000000 -0.6666667 -0.6123724
## v3 -0.1666667 -0.6666667  1.0000000  0.4082483
## v4 -0.4082483 -0.6123724  0.4082483  1.0000000
AM(s='o') # A/((A+B)*(A+C))^(1/2)#Ochiai
##           v1        v2        v3        v4
## v1 1.0000000 0.8164966 0.4082483 0.0000000
## v2 0.8164966 1.0000000 0.3333333 0.0000000
## v3 0.4082483 0.3333333 1.0000000 0.5773503
## v4 0.0000000 0.0000000 0.5773503 1.0000000
AM(s='u') # (2*A-B-C)/(2*A+B+C)#Ueda
##      v1         v2         v3 v4
## v1  1.0  0.6000000 -0.2000000 -1
## v2  0.6  1.0000000 -0.3333333 -1
## v3 -0.2 -0.3333333  1.0000000  0
## v4 -1.0 -1.0000000  0.0000000  1
AM(s='mi')  # log2(A*(A+B+C+D)/((A+B)*(A+C)))#相互情報量
##            v1         v2         v3        v4
## v1  1.3219281  0.7369656 -0.2630344      -Inf
## v2  0.7369656  0.7369656 -0.8479969      -Inf
## v3 -0.2630344 -0.8479969  0.7369656 0.7369656
## v4       -Inf       -Inf  0.7369656 2.3219281
AM(s='rmi') # log(A*(A+B+C+D)/((A+B)*(A+C)))/log((A+D)/A)#相対相互情報量
##            v1        v2         v3        v4
## v1  1.0000000 0.7369656 -0.2630344       NaN
## v2  0.7369656 1.0000000       -Inf       NaN
## v3 -0.2630344      -Inf  1.0000000 0.4649735
## v4        NaN       NaN  0.4649735 1.0000000

距離行列

DM(X=D, d=‘e’, s=F)
d=‘e’:ユークリッド距離/‘m’:平均距離/‘r’:相対距離, s:標準化

D=Ip('x45') #簡単なデータ例 x45.txt
## File: x45.txt / Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3
DM() #ユークリッド距離
##           A         B         C        D         E
## A  0.000000  9.899495  4.690416 16.82260 10.677078
## B  9.899495  0.000000  6.000000 18.46619  9.486833
## C  4.690416  6.000000  0.000000 16.46208  9.273618
## D 16.822604 18.466185 16.462078  0.00000 12.124356
## E 10.677078  9.486833  9.273618 12.12436  0.000000
DM(s=T) #ユークリッド距離+標準化
##          A        B        C        D        E
## A 0.000000 2.549743 2.005456 4.449564 3.431411
## B 2.549743 0.000000 1.661103 4.575261 2.784997
## C 2.005456 1.661103 0.000000 3.779040 2.218398
## D 4.449564 4.575261 3.779040 0.000000 2.693110
## E 3.431411 2.784997 2.218398 2.693110 0.000000
DM(d='m') #平均距離
##          A        B        C        D        E
## A 0.000000 4.949747 2.345208 8.411302 5.338539
## B 4.949747 0.000000 3.000000 9.233093 4.743416
## C 2.345208 3.000000 0.000000 8.231039 4.636809
## D 8.411302 9.233093 8.231039 0.000000 6.062178
## E 5.338539 4.743416 4.636809 6.062178 0.000000
DM(d='m',s=T) #平均距離+標準化
##          A         B         C        D        E
## A 0.000000 1.2748715 1.0027279 2.224782 1.715706
## B 1.274871 0.0000000 0.8305514 2.287630 1.392498
## C 1.002728 0.8305514 0.0000000 1.889520 1.109199
## D 2.224782 2.2876305 1.8895200 0.000000 1.346555
## E 1.715706 1.3924984 1.1091988 1.346555 0.000000
DM(d='r') #相対距離
##            A         B          C         D         E
## A 0.00000000 0.1550633 0.04214559 0.6690307 0.3031915
## B 0.15506329 0.0000000 0.05056180 0.5562806 0.1590106
## C 0.04214559 0.0505618 0.00000000 0.5387674 0.1885965
## D 0.66903073 0.5562806 0.53876740 0.0000000 0.4117647
## E 0.30319149 0.1590106 0.18859649 0.4117647 0.0000000
DM(d='r',s=T) #相対距離+標準化
##           A         B         C         D         E
## A 0.0000000 0.1738729 0.1258259 0.6966608 0.4262609
## B 0.1738729 0.0000000 0.0609534 0.5017009 0.1895099
## C 0.1258259 0.0609534 0.0000000 0.3934499 0.1386244
## D 0.6966608 0.5017009 0.3934499 0.0000000 0.2269594
## E 0.4262609 0.1895099 0.1386244 0.2269594 0.0000000
D=t(D); D #転置行列
##   w1 w2 w3 w4
## A 10 11  0  0
## B 19  7  0  1
## C 14 10  1  2
## D  7  0 12  3
## E 12  1  1  3
DM() #ユークリッド距離
##          w1       w2        w3        w4
## w1  0.00000 18.19341 27.856777 25.787594
## w2 18.19341  0.00000 19.874607 15.297059
## w3 27.85678 19.87461  0.000000  9.327379
## w4 25.78759 15.29706  9.327379  0.000000
DM(s=T) #ユークリッド距離+標準化
##          w1       w2       w3       w4
## w1 0.000000 3.370726 4.764499 4.339743
## w2 3.370726 0.000000 3.881567 2.791648
## w3 4.764499 3.881567 0.000000 2.060224
## w4 4.339743 2.791648 2.060224 0.000000
DM(d='m') #平均距離
##           w1       w2        w3        w4
## w1  0.000000 8.136338 12.457929 11.532563
## w2  8.136338 0.000000  8.888194  6.841053
## w3 12.457929 8.888194  0.000000  4.171331
## w4 11.532563 6.841053  4.171331  0.000000
DM(d='m',s=T) #平均距離+標準化
##          w1       w2        w3        w4
## w1 0.000000 1.507434 2.1307486 1.9407921
## w2 1.507434 0.000000 1.7358897 1.2484630
## w3 2.130749 1.735890 0.0000000 0.9213603
## w4 1.940792 1.248463 0.9213603 0.0000000
DM(d='r') #相対距離
##           w1        w2        w3        w4
## w1 0.0000000 0.2952721 0.7791165 0.7617411
## w2 0.2952721 0.0000000 0.9472422 0.7959184
## w3 0.7791165 0.9472422 0.0000000 0.5147929
## w4 0.7617411 0.7959184 0.5147929 0.0000000
DM(d='r',s=T) #相対距離+標準化
##           w1        w2        w3        w4
## w1 0.0000000 0.3288442 0.6858137 0.6991220
## w2 0.3288442 0.0000000 0.9513567 0.8054668
## w3 0.6858137 0.9513567 0.0000000 0.5160612
## w4 0.6991220 0.8054668 0.5160612 0.0000000

—–

参考

トップページ

(東京大学 上田博人 Hiroto Ueda, 2022)