找到具有特定总节点数的邻居群集'属性值

时间:2017-11-29 22:48:46

标签: r igraph graph-algorithm

考虑这个问题:

国家/地区( AMD0 )分为多个管理单位 ADM1 i ,其中i = 1表示n = 34。对于每个 ADM1 i ,我知道其人口 POPADM i

现在,我想找到4个相邻单位的集群,使得集群的总人口等于 POPCLU j ,其中j = 1,n = 4。 / p>

该算法可以返回符合要求的多个输出。

让我们加载 ADM1 (从here下载)并为每个功能设置population

ADM1 <- readRDS("~/Downloads/AFG_adm1.rds")

set.seed(28100)
ADM1$population <- sample(1:100, nrow(afg_sp), replace = T)

让我们确定邻近的关系

require(spdep)

nb <- poly2nb(ADM1, row.names = ADM1$HASC_1)
mat <- nb2mat(nb, style="B")
colnames(mat) <- rownames(mat)

enter image description here

要布置图形,我们需要每个 AMD1 i 的质心。

centroids_df <- cbind(as.data.frame(coordinates(ADM1)), as.data.frame(ADM1[,c("HASC_1", "population")]))

现在我们可以创建一个基于mat的图表,如之前创建的那样:

require(igraph)
ADM1_g <- graph_from_adjacency_matrix(mat, mode='undirected')
V(ADM1_g)$population <- centroids_df$population[match(V(ADM1_g)$name,centroids_df$HASC_1)]
plot(ADM1_g, layout = as.matrix(centroids_df[,1:2]), vertex.label = V(ADM1_g)$population)

enter image description here

每个节点标签都标识要素的种群( POPADM i )。

这是我想要通过算法确定的聚类

enter image description here

基于这些输入值:

  1. POPCLU 1 = 460
  2. POPCLU 2 = 788
  3. POPCLU 3 = 208
  4. POPCLU 4 = 295
  5. 注意:在示例中,群集由

    决定
    set.seed(28100)
    clusters <- walktrap.community(ADM1_g) 
    

    给出了

    • "AF.BM" "AF.DK" "AF.GZ" "AF.HM" "AF.KD" "AF.KT" "AF.PK" "AF.PT" "AF.OZ" "AF.ZB"
    • "AF.BD" "AF.BL" "AF.KB" "AF.KP" "AF.KR" "AF.LA" "AF.LW" "AF.NG" "AF.NR" "AF.PJ" "AF.PV" "AF.TK"
    • "AF.BG" "AF.FH" "AF.GR" "AF.HR" "AF.NM"
    • "AF.BK" "AF.FB" "AF.JW" "AF.KZ" "AF.SM" "AF.SP"

0 个答案:

没有答案