同質相連(Assortativity)
在這個練習中,你要對第一章中的第二個朋友網路計算 assortativity()。這個指標衡量頂點是否傾向連到具有相同屬性的其他頂點。你也會計算度數同質相連,評估頂點是否傾向連到度數相近的其他頂點。
本練習屬於課程
R 的 Network Analysis
練習說明
- 使用
plot()對朋友網路物件g1做一個探索式繪圖。 - 將每個頂點的
gender屬性先因子化,再用as.numeric()轉成數字向量,命名為values。 - 使用
assortativity()依性別計算同質相連。第一個引數為圖形物件g1,第二個引數為values。 - 使用
assortativity.degree()計算網路的度數同質相連。第一個引數為圖形物件。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot the network
___(g1)
# Convert the gender attribute into a numeric value
values <- as.numeric(factor(V(___)$___))
# Calculate the assortativity of the network based on gender
___(g1, ___)
# Calculate the assortativity degree of the network
___(___, directed = FALSE)