Last active
August 29, 2015 14:05
-
-
Save shirayuca/0e6e00182086f7149a15 to your computer and use it in GitHub Desktop.
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 パッケージの watts.strogatz.game で、確率 p を 0 から 1 まで 0.01 刻みで変化させるシミュレーションを行います。 | |
library(igraph) | |
Clustering <- 1:101 | |
Distance <- 1:101 | |
# 101個の要素から成るベクトルの入れ物 | |
p <- seq(0, 1, by = 0.01) | |
# p の値を 0 から 1 まで 0.01 刻みで変化させる | |
for (i in 1:101) { | |
g <- watts.strogatz.game(1, 100, 2, p[i], loops=FALSE, multiple=FALSE) | |
g_t <- transitivity(g, type="local") | |
g_t[which(g_t == "NaN")] <-0 | |
Clustering[i] <- mean(g_t) | |
Distance[i] <- average.path.length(g) | |
} | |
par (mfcol = c(1,2)) | |
plot(p, Clustering, xlab = "p", ylab = "Clustering Coefficient") | |
plot(p, Distance, xlab = "p", ylab = "Average Path Length") | |
# 2つのグラフを横に並べてプロット |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment