Coerce One or More Networks to Sociomatrix Form
as.sociomatrix.Rdas.sociomatrix takes adjacency matrices, adjacency arrays,
network objects, or lists thereof, and returns one or more
sociomatrices (adjacency matrices) as appropriate. This routine provides a
useful input-agnostic front-end to functions which process adjacency
matrices.
Arguments
- x
an adjacency matrix, array,
networkobject, or list thereof.- attrname
optionally, the name of a network attribute to use for extracting edge values (if
xis anetworkobject).- simplify
logical; should
as.sociomatrixattempt to combine its inputs into an adjacency array (TRUE), or return them as separate list elements (FALSE)?- expand.bipartite
logical; if
xis bipartite, should we return the full adjacency matrix (rather than the abbreviated, two-mode form)?- ...
additional arguments for the coercion routine.
Value
One or more adjacency matrices. If all matrices are of the same
dimension and simplify==TRUE, the matrices are joined into a single
array; otherwise, the return value is a list of single adjacency matrices.
Details
as.sociomatrix provides a more general means of coercing input into
adjacency matrix form than as.matrix.network. In particular,
as.sociomatrix will attempt to coerce all input networks into the
appropriate form, and return the resulting matrices in a regularized manner.
If simplify==TRUE, as.sociomatrix attempts to return the
matrices as a single adjacency array. If the input networks are of variable
size, or if simplify==FALSE, the networks in question are returned as
a list of matrices. In any event, a single input network is always returned
as a lone matrix.
If attrname is given, the specified edge attribute is used to extract
edge values from any network objects contained in x.
Note that the same attribute will be used for all networks; if no attribute
is specified, the standard dichotomous default will be used instead.
References
Butts, C. T. (2008). “network: a Package for Managing Relational Data in R.” Journal of Statistical Software, 24(2). doi:10.18637/jss.v024.i02
Author
Carter T. Butts buttsc@uci.edu
Examples
#Generate an adjacency array
g<-array(rbinom(100,1,0.5),dim=c(4,5,5))
#Generate a network object
net<-network(matrix(rbinom(36,1,0.5),6,6))
#Coerce to adjacency matrix form using as.sociomatrix
as.sociomatrix(g,simplify=TRUE) #Returns as-is
#> , , 1
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 0 0 1
#> [2,] 0 0 0 1 1
#> [3,] 1 0 0 1 0
#> [4,] 1 0 0 0 0
#>
#> , , 2
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 1 1 1 1
#> [2,] 1 0 1 1 1
#> [3,] 0 1 1 0 0
#> [4,] 0 0 0 0 0
#>
#> , , 3
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 1 0 0 1
#> [2,] 1 1 1 1 1
#> [3,] 1 1 1 1 0
#> [4,] 1 1 1 1 1
#>
#> , , 4
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 0 1 1 0
#> [2,] 0 0 1 0 1
#> [3,] 0 0 1 0 1
#> [4,] 1 1 1 1 0
#>
#> , , 5
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 0 1 0 0 1
#> [3,] 1 1 0 0 1
#> [4,] 0 0 0 1 1
#>
as.sociomatrix(g,simplify=FALSE) #Returns as list
#> [[1]]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 0 0 1 1
#> [2,] 1 1 1 0 1
#> [3,] 0 1 0 1 1
#> [4,] 0 1 0 1 1
#> [5,] 1 1 1 0 1
#>
#> [[2]]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 1 1 0 0
#> [2,] 0 0 1 0 1
#> [3,] 0 1 1 1 0
#> [4,] 1 1 1 0 0
#> [5,] 1 1 1 1 1
#>
#> [[3]]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 0 1 0 1
#> [2,] 0 1 1 0 1
#> [3,] 0 1 1 1 0
#> [4,] 1 0 1 0 0
#> [5,] 0 0 0 1 1
#>
#> [[4]]
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 0 1 1 0
#> [2,] 0 0 1 1 0
#> [3,] 0 0 1 1 0
#> [4,] 0 0 1 1 1
#> [5,] 0 0 1 0 1
#>
as.sociomatrix(net) #Coerces to matrix
#> 1 2 3 4 5 6
#> 1 0 1 1 1 1 1
#> 2 1 0 0 0 0 0
#> 3 1 0 0 1 1 1
#> 4 0 1 1 0 0 1
#> 5 0 0 1 0 0 0
#> 6 1 1 0 0 1 0
as.sociomatrix(list(net,g)) #Returns as list of matrices
#> [[1]]
#> 1 2 3 4 5 6
#> 1 0 1 1 1 1 1
#> 2 1 0 0 0 0 0
#> 3 1 0 0 1 1 1
#> 4 0 1 1 0 0 1
#> 5 0 0 1 0 0 0
#> 6 1 1 0 0 1 0
#>
#> [[2]]
#> , , 1
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 0 0 1
#> [2,] 0 0 0 1 1
#> [3,] 1 0 0 1 0
#> [4,] 1 0 0 0 0
#>
#> , , 2
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 1 1 1 1
#> [2,] 1 0 1 1 1
#> [3,] 0 1 1 0 0
#> [4,] 0 0 0 0 0
#>
#> , , 3
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 1 0 0 1
#> [2,] 1 1 1 1 1
#> [3,] 1 1 1 1 0
#> [4,] 1 1 1 1 1
#>
#> , , 4
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 0 1 1 0
#> [2,] 0 0 1 0 1
#> [3,] 0 0 1 0 1
#> [4,] 1 1 1 1 0
#>
#> , , 5
#>
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1 1 1 1 1
#> [2,] 0 1 0 0 1
#> [3,] 1 1 0 0 1
#> [4,] 0 0 0 1 1
#>
#>