首页 文章

R SNA:创建一个包含所有参与者但仅包含子集值的邻接矩阵

提问于
浏览
3

我的问题如下:

我正在使用R SNA包进行社交网络分析 . 可以说,我的出发点是具有以下特征的边缘列表 . 每一行都包含一个公司名称,他们所涉及的项目的ID以及其他特征,比如项目年份 . 公司可以在几个项目中,一个项目可以由多个公司的合作组成 . 例:

Name   Project   Year
AA     1         2003
AB     1         2003
AB     2         2003
AB     3         2004
AC     2         2003
AC     4         2005

对于网络分析,我需要一个邻接矩阵,所有公司都作为行和列 Headers ,我构造如下:

grants.edgelist <- read.csv("00-composed.csv", header = TRUE, sep = ";", quote="\"", dec=",", fill = TRUE, comment.char="")

grants.2mode <-  table(grants.edgelist)   # cross tabulate -> 2-mode sociomatrix

grants.adj <- grants.2mode%*%t(grants.2mode)     # Adjacency matrix as product of the 2-mode sociomatrix`

现在我的问题是:我想在邻接矩阵上运行netlm回归,在那里我测试一年中的网络如何解释明年的网络 . 但是,因此我想将grants.edgelist分组为(仅举办)2003和2005 . 但是,我发现并非所有公司每年都在项目中,因此相应的邻接矩阵具有不同的行和列 .

现在我的问题是:我如何获得一个包含行和列 Headers 中所有公司的邻接矩阵,但是它们的交集设置在我想要观察的年份的零期望值上 . 我希望我的意思很清楚 .

非常感谢你提前 . 这个问题让我今天抓狂!

最好的祝愿

丹尼尔

1 回答

  • 1

    假设同一家公司有可能在多年内同一个项目(如果没有,那么肯定会有更简单的解决方案) . 一种方法是构造一个networkDynamic对象,然后提取所需的年份并将它们提供给 netlm .

    library(networkDynamic)
    
    # construct example dataset
    firmProj <- matrix(
                        c('AA', 1,  2003,
                          'AB', 1, 2003,
                          'AB', 2, 2003,
                          'AB', 3, 2004,
                          'AC', 2, 2003,
                          'AC', 4, 2005),
                           ncol=3,byrow=TRUE)
    colnames(firmProj)<-c('Name',   'Project',   'Year')
    
    # make network encompassing all edges
    baseNet<-network(firmProj[,1:2])
    
    # get the ids/names of the vertices
    ids<-network.vertex.names(baseNet)
    
    # convert original data to a timed edgelist
    tel<-cbind(as.numeric(firmProj[,3]),   # convert years to numeric start time
               as.numeric(firmProj[,3])+1, # convert years to numeric end  time
               match(firmProj[,1],ids),    # match label to network id
               match(firmProj[,2],ids))    # match label to network id
    
    # convert to a networkDynamic object
    dynFirmProj<-networkDynamic(baseNet, edge.spells = tel)
    
    # bin static networks from the dynamic one, and convert them into list of adjacency matrices
    lapply(
           get.networks(dynFirmProj,start=2003, end = 2006, time.increment = 1),
           as.matrix)
    
    [[1]]
       1 2 3 4 AA AB AC
    1  0 0 0 0  0  0  0
    2  0 0 0 0  0  0  0
    3  0 0 0 0  0  0  0
    4  0 0 0 0  0  0  0
    AA 1 0 0 0  0  0  0
    AB 1 1 0 0  0  0  0
    AC 0 1 0 0  0  0  0
    
    [[2]]
       1 2 3 4 AA AB AC
    1  0 0 0 0  0  0  0
    2  0 0 0 0  0  0  0
    3  0 0 0 0  0  0  0
    4  0 0 0 0  0  0  0
    AA 0 0 0 0  0  0  0
    AB 0 0 1 0  0  0  0
    AC 0 0 0 0  0  0  0
    
    [[3]]
       1 2 3 4 AA AB AC
    1  0 0 0 0  0  0  0
    2  0 0 0 0  0  0  0
    3  0 0 0 0  0  0  0
    4  0 0 0 0  0  0  0
    AA 0 0 0 0  0  0  0
    AB 0 0 0 0  0  0  0
    AC 0 0 0 1  0  0  0
    

    但是,我不确定 netlm 是最好的方式来看待这个,因为因变量的二分数据"..is strongly discouraged due to the assumptions of the analysis."但也许我不太了解你的问题 .

相关问题