多次元尺度法
getFreqDir関数の読み込み
source("getFreqDir.R")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
univディレクトリ内の頻度表の作成
univTable <- getFreqDir("univ", relative=TRUE)
head(univTable)
MDS: Euclidean距離
mds <- cmdscale(dist(t(univTable)),2)
plot(mds,type="n")
text(mds,rownames(mds))

データの標準化(平均:0, 分散:1)
std.univTable <- scale(univTable)
apply(std.univTable,2,mean)
## kyoto1 kyoto2 osaka1 osaka2 osaka3
## 7.910104e-18 -1.354846e-17 -7.924179e-18 5.787217e-18 -1.912062e-17
## osaka4 tokyo1 tokyo2 waseda1 waseda2
## -1.787650e-17 -2.479213e-18 2.121586e-17 2.821382e-17 3.375325e-17
apply(std.univTable,2,sd)
## kyoto1 kyoto2 osaka1 osaka2 osaka3 osaka4 tokyo1 tokyo2 waseda1 waseda2
## 1 1 1 1 1 1 1 1 1 1
データの標準化&MDS: Euclidean距離
mds <- cmdscale(dist(t(std.univTable)),2)
plot(mds,type="n")
text(mds,rownames(mds))

MDS:キャンベラ距離距離
mds <- cmdscale(dist(t(univTable), method = "canberra"),2)
plot(mds,type="n")
text(mds,rownames(mds))

MDS: コサイン距離距離
library(proxy)
##
## Attaching package: 'proxy'
## The following objects are masked from 'package:stats':
##
## as.dist, dist
## The following object is masked from 'package:base':
##
## as.matrix
mds <- cmdscale(dist(t(univTable), method = "cosine"),2)
plot(mds,type="n")
text(mds,rownames(mds))
