SNA folks: I am trying to create a two-mode network from a data frame in R. I have a list of organizations which are connected via common membership in a parent organization. I have membership in that organization coded in a binary variable. I have successfully created a sociomatrix and subsequent network object based on those data via the following code (from Create adjacency matrix based on binary variable):
library(statnet)
org <- c("A","B","C","D","E","F","G","H","I","J")
link <- c(1,0,0,0,1,1,0,0,1,1)
person <- c("Mary","Michael","Mary","Jane","Jimmy",
"Johnny","Becky","Bobby","Becky","Becky")
df <- data.frame(org,link,person)
socmat1 <- tcrossprod(df$link)
rownames(socmat1) <- df$org
colnames(socmat1) <- df$org
diag(socmat1) <- 0
socmat1
#> A B C D E F G H I J
#> A 0 0 0 0 1 1 0 0 1 1
#> B 0 0 0 0 0 0 0 0 0 0
#> C 0 0 0 0 0 0 0 0 0 0
#> D 0 0 0 0 0 0 0 0 0 0
#> E 1 0 0 0 0 1 0 0 1 1
#> F 1 0 0 0 1 0 0 0 1 1
#> G 0 0 0 0 0 0 0 0 0 0
#> H 0 0 0 0 0 0 0 0 0 0
#> I 1 0 0 0 1 1 0 0 0 1
#> J 1 0 0 0 1 1 0 0 1 0
testnet <- as.network(x = socmat1,
directed = FALSE,
loops = FALSE,
matrix.type = "adjacency"
)
testnet
#> Network attributes:
#> vertices = 10
#> directed = FALSE
#> hyper = FALSE
#> loops = FALSE
#> multiple = FALSE
#> bipartite = FALSE
#> total edges= 10
#> missing edges= 0
#> non-missing edges= 10
#>
#> Vertex attribute names:
#> vertex.names
#>
#> No edge attributes
Created on 2020-10-24 by the reprex package (v0.3.0)
However, I obviously can't use tcrossprod()
similarly to achieve the same result with individuals connected by organizations or vice versa, as shown by the following code:
socmat2 <- tcrossprod(df$org)
#> Error in df$org: object of type 'closure' is not subsettable
rownames(socmat2) <- df$person
#> Error in df$person: object of type 'closure' is not subsettable
colnames(socmat2) <- df$person
#> Error in df$person: object of type 'closure' is not subsettable
diag(socmat2) <- 0
#> Error in diag(socmat2) <- 0: object 'socmat2' not found
socmat2
#> Error in eval(expr, envir, enclos): object 'socmat2' not found
How can I create a two-mode network with the first set of edges being an organization's membership in the larger organization (denoted by the link variable) and the second being an individual's leadership position in an organization?
Thanks, all.
Created on 2020-10-24 by the reprex package (v0.3.0)