【问题标题】:How to create a one-mode network (adjacency matrix) based on matches from two-mode network如何基于双模网络的匹配创建单模网络(邻接矩阵)
【发布时间】:2020-05-24 16:51:32
【问题描述】:

我正在处理一项调查数据(row=respondents;col=opin​​ion),并尝试在受访者之间创建一个单模邻接矩阵,以衡量他们为每个二元网络给出相同答案的次数。具体来说,

affiliation_matrix <- matrix(c(
  0,1,0,
  1,0,0,
  0,1,1
)
,nrow=3
,ncol=3,
byrow=TRUE)

dimnames(affiliation_matrix) <- list(
  c("Alyssa", "Brad", "Carla"),
  c("opinion1", "opinion2", "opinion3")
)

affiliation_matrix

在上面的 3x3 矩阵示例中,我想创建一个看起来像这样的矩阵

ideal_matrix <- matrix(c(
  1,1,2,
  1,1,0,
  2,0,2
)
,nrow=3
,ncol=3,
byrow=TRUE)

dimnames(ideal_matrix) <- list(
  c("Alyssa", "Brad", "Carla"),
  c("Alyssa", "Brad", "Carla")
)

因此,在 Alyssa 和 Carla 之间,他们的关联度为 2,因为他们对意见 1 和意见 2 的回答相同。同样,Alyssa 和 Brad 之间的联系得到 1,因为他们在意见 3 中都回答了 0。

我正在查找代码 get.adjacency() 和 bipartite.projection 但这似乎只处理人员事件网络,其中只有 1 的值被视为匹配项。是否有一个 R 包可以让我这样做,或者我是否需要手动创建自己的循环(如果有的话......如何??)?

谢谢!!

【问题讨论】:

    标签: igraph social-networking adjacency-matrix bipartite network-analysis


    【解决方案1】:

    可能有一个我不知道的现成解决方案。然而,在这种特殊的(二进制)情况下,我们可以重新编码矩阵,将每个矩阵乘以它的转置,最后将它们加在一起:

    affiliation_matrix_recoded <- affiliation_matrix
    affiliation_matrix_recoded[] <- ifelse(affiliation_matrix_recoded > 0, 0, 1)
    
    a <- tcrossprod(affiliation_matrix)
    b <- tcrossprod(affiliation_matrix_recoded )
    
    r <- a + b
    diag(r) <- 0
    r
    

    导致:

           Alyssa Brad Carla
    Alyssa      0    1     2
    Brad        1    0     0
    Carla       2    0     0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      • 2020-01-04
      • 1970-01-01
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多