使用隨機化評估關聯性(assortativity)
在這個練習中,你要透過隨機化程序,判定在給定各頂點性別的情況下,友誼網路中觀察到的關聯性有多可能出現。你會將網路中頂點的性別隨機重排 1000 次,並為每個隨機網路重新計算關聯性。
本練習屬於課程
R 的 Network Analysis
練習說明
- 使用
assortativity(),根據性別與前一題計算的物件values,計算圖形物件g1的關聯性,並將結果指定給物件observed.assortativity。 - 在 for 迴圈中,每次用
sample()隨機重排物件values,並使用assortativity()計算網路g1的關聯性。 - 使用
hist()繪製此隨機化程序得到的關聯性分布,並加上一條紅色垂直線,標示原始g1網路的觀察關聯性數值(儲存在observed.assortativity)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Calculate the observed assortativity
observed.assortativity <- ___(g1, values)
# Calculate the assortativity of the network randomizing the gender attribute 1000 times
results <- vector('list', 1000)
for(i in 1:1000){
results[[i]] <- ___(g1, sample(___))
}
# Plot the distribution of assortativity values and add a red vertical line at the original observed value
___(unlist(results))
abline(v = ___, col = "red", lty = 3, lwd=2)