Last active
May 30, 2020 05:48
-
-
Save shirayuca/a6bb4eaad1089cc9434c4714c32e4664 to your computer and use it in GitHub Desktop.
情報学特殊講義A_演習1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nodeA | nodeB | weight | |
---|---|---|---|
佐藤 | 鈴木 | 1 | |
佐藤 | 高橋 | 1 | |
鈴木 | 高橋 | 1 | |
佐藤 | 田中 | 1 | |
鈴木 | 田中 | 1 | |
高橋 | 田中 | 1 | |
佐藤 | 伊藤 | 1 | |
佐藤 | 渡辺 | 1 | |
佐藤 | 山本 | 1 | |
伊藤 | 山本 | 1 | |
渡辺 | 山本 | 1 | |
佐藤 | 中村 | 1 | |
鈴木 | 中村 | 1 | |
高橋 | 中村 | 1 | |
田中 | 中村 | 1 | |
佐藤 | 小林 | 1 | |
高橋 | 小林 | 1 | |
高橋 | 加藤 | 1 | |
佐藤 | 吉田 | 1 | |
伊藤 | 吉田 | 1 | |
渡辺 | 吉田 | 1 | |
佐藤 | 山田 | 1 | |
佐藤 | 佐々木 | 1 | |
田中 | 佐々木 | 1 | |
佐藤 | 山口 | 1 | |
鈴木 | 山口 | 1 | |
高橋 | 山口 | 1 | |
田中 | 山口 | 1 | |
渡辺 | 木村 | 1 | |
山本 | 木村 | 1 | |
佐藤 | 林 | 1 | |
鈴木 | 林 | 1 | |
佐藤 | 清水 | 1 | |
鈴木 | 清水 | 1 | |
佐藤 | 森 | 1 | |
鈴木 | 森 | 1 | |
橋本 | 石川 | 1 | |
阿部 | 石川 | 1 | |
高橋 | 中島 | 1 | |
橋本 | 中島 | 1 | |
阿部 | 中島 | 1 | |
高橋 | 石井 | 1 | |
橋本 | 小川 | 1 | |
山下 | 小川 | 1 | |
鈴木 | 前田 | 1 | |
小林 | 前田 | 1 | |
佐藤 | 岡田 | 1 | |
阿部 | 岡田 | 1 | |
石川 | 岡田 | 1 | |
石井 | 岡田 | 1 | |
高橋 | 長谷川 | 1 | |
小林 | 長谷川 | 1 | |
松本 | 長谷川 | 1 | |
井上 | 長谷川 | 1 | |
斎藤 | 長谷川 | 1 | |
山崎 | 長谷川 | 1 | |
池田 | 長谷川 | 1 | |
橋本 | 長谷川 | 1 | |
小川 | 長谷川 | 1 | |
前田 | 長谷川 | 1 | |
岡田 | 長谷川 | 1 | |
小林 | 藤田 | 1 | |
加藤 | 藤田 | 1 | |
山口 | 藤田 | 1 | |
松本 | 藤田 | 1 | |
井上 | 藤田 | 1 | |
斎藤 | 藤田 | 1 | |
清水 | 藤田 | 1 | |
山崎 | 藤田 | 1 | |
池田 | 藤田 | 1 | |
橋本 | 藤田 | 1 | |
山下 | 藤田 | 1 | |
中島 | 藤田 | 1 | |
石井 | 藤田 | 1 | |
小川 | 藤田 | 1 | |
前田 | 藤田 | 1 | |
岡田 | 藤田 | 1 | |
長谷川 | 藤田 | 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### パッケージの準備 | |
# igraphパッケージをインストール | |
install.packages("igraph") | |
# igraphライブラリを読み込み | |
library(igraph) | |
### データの準備 | |
# work_1.csvを読み込み、 dというオブジェクトに代入。1行目はヘッダー。エンコーディングはShift-JIS。 | |
d <- read.csv("work_1.csv", header=T, fileEncoding = "CP932") | |
# igraphの関数graph.data.frameを使って、dの1-2列目をネットワークグラフのオブジェクトgに変換。directedは向きを表し、無向はF、有向はT。 | |
g <- graph.data.frame(d[1:2],directed=F) | |
### ネットワーク分析 | |
# ノード数、リンク数 | |
vcount(g) | |
# リンク数 | |
ecount(g) | |
# 各ノードの次数 | |
degree(g) | |
# 各ノードの次数をdegree.csvに書き出す | |
write.csv(degree(g), "degree.csv", fileEncoding = "CP932") | |
# 平均次数 | |
sum(degree(g))/vcount(g) | |
# ddにgの次数分布を代入 | |
dd <- degree.distribution(g) | |
# ddの散布図を作成する。x軸ラベルは次数、y軸ラベルは出現確率。 | |
plot(dd[-1],xlab="次数",ylab="出現確率") | |
# 平均経路長 | |
average.path.length(g) | |
# 局所クラスター係数をlocal_c.csvに書き出す(ラベルの出力ができないため、degree.csvのラベルと合わせて確認) | |
write.csv(transitivity(g, type="local",isolates="zero"), "local_c.csv", fileEncoding = "CP932") | |
# 平均クラスター係数 | |
transitivity(g, type="global") | |
# ネットワーク図としてプロット | |
plot(g,layout=layout.auto) | |
### 応用例 | |
# 媒介中心性に基づきコミュニティ(相対的に密度の高いサブグループ)ごとに色付け | |
eb <- edge.betweenness.community(g) | |
V(g)$color <- eb$membership | |
plot(g, vertex.size=12, vertex.label=V(g)$name, layout=layout.fruchterman.reingold) | |
# 次数の大きさをノードに反映 | |
plot(g,vertex.size=degree(g)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment