as.sociomatrix: Coerce One or More Networks to Sociomatrix Form

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

as.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.

Usage

1
2
as.sociomatrix(x, attrname = NULL, simplify = TRUE, 
    expand.bipartite = FALSE, ...)

Arguments

x

an adjacency matrix, array, network object, or list thereof.

attrname

optionally, the name of a network attribute to use for extracting edge values (if x is a network object).

simplify

logical; should as.sociomatrix attempt to combine its inputs into an adjacency array (TRUE), or return them as separate list elements (FALSE)?

expand.bipartite

logical; if x is bipartite, should we return the full adjacency matrix (rather than the abbreviated, two-mode form)?

...

additional arguments for the coercion routine.

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.

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.

Author(s)

Carter T. Butts buttsc@uci.edu

References

Butts, C. T. (2008). “network: a Package for Managing Relational Data in R.” Journal of Statistical Software, 24(2). http://www.jstatsoft.org/v24/i02/

See Also

as.matrix.network, network

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#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
as.sociomatrix(g,simplify=FALSE)  #Returns as list
as.sociomatrix(net)               #Coerces to matrix
as.sociomatrix(list(net,g))       #Returns as list of matrices

Example output

network: Classes for Relational Data
Version 1.14-377 created on 2019-03-04.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
                    Mark S. Handcock, University of California -- Los Angeles
                    David R. Hunter, Penn State University
                    Martina Morris, University of Washington
                    Skye Bender-deMoll, University of Washington
 For citation information, type citation("network").
 Type help("network-package") to get started.

, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    0    0
[2,]    0    0    1    1    0
[3,]    0    1    1    0    0
[4,]    0    1    1    0    0

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    0    1    1
[2,]    1    0    1    0    0
[3,]    0    1    0    0    1
[4,]    0    1    1    1    1

, , 3

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    1
[2,]    1    1    1    1    1
[3,]    0    0    1    1    1
[4,]    0    0    1    0    0

, , 4

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    1    1
[2,]    0    0    1    0    1
[3,]    0    1    0    0    0
[4,]    0    1    1    0    0

, , 5

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    0    1
[2,]    0    1    0    0    1
[3,]    0    0    1    1    1
[4,]    0    1    1    1    1

[[1]]
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    0    0
[2,]    1    1    0    1    1
[3,]    1    0    0    1    1
[4,]    0    1    0    1    0
[5,]    0    1    1    1    1

[[2]]
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    0    0
[2,]    0    0    1    0    1
[3,]    1    1    1    1    0
[4,]    1    0    1    0    0
[5,]    0    0    1    1    1

[[3]]
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    1    1    0    1    0
[3,]    1    0    1    0    1
[4,]    0    0    1    0    1
[5,]    0    1    1    0    1

[[4]]
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    1    1    0    1    1
[3,]    1    1    1    1    1
[4,]    0    1    0    0    1
[5,]    0    1    0    0    1

  1 2 3 4 5 6
1 0 1 1 1 0 1
2 0 0 0 1 1 0
3 0 0 0 1 1 0
4 0 0 0 0 0 1
5 1 1 0 1 0 0
6 1 0 1 0 0 0
[[1]]
  1 2 3 4 5 6
1 0 1 1 1 0 1
2 0 0 0 1 1 0
3 0 0 0 1 1 0
4 0 0 0 0 0 1
5 1 1 0 1 0 0
6 1 0 1 0 0 0

[[2]]
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    0    0
[2,]    0    0    1    1    0
[3,]    0    1    1    0    0
[4,]    0    1    1    0    0

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    0    1    1
[2,]    1    0    1    0    0
[3,]    0    1    0    0    1
[4,]    0    1    1    1    1

, , 3

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    1
[2,]    1    1    1    1    1
[3,]    0    0    1    1    1
[4,]    0    0    1    0    0

, , 4

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    1    1
[2,]    0    0    1    0    1
[3,]    0    1    0    0    0
[4,]    0    1    1    0    0

, , 5

     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    1    0    1
[2,]    0    1    0    0    1
[3,]    0    0    1    1    1
[4,]    0    1    1    1    1

network documentation built on May 2, 2019, 5:16 p.m.