sna-coercion: sna Coercion Functions

sna-coercionR Documentation

sna Coercion Functions

Description

Functions to coerce network data into one form or another; these are generally internal, but may in some cases be helpful to the end user.

Usage

as.sociomatrix.sna(x, attrname=NULL, simplify=TRUE, force.bipartite=FALSE)
## S3 method for class 'sna'
as.edgelist(x, attrname = NULL, as.digraph = TRUE, 
    suppress.diag = FALSE, force.bipartite = FALSE, ...)
is.edgelist.sna(x)

Arguments

x

network data in any of several acceptable forms (see below).

attrname

if x is a network object, the (optional) edge attribute to be used to obtain edge values.

simplify

logical; should output be simplified by collapsing adjacency matrices of identical dimension into adjacency arrays?

force.bipartite

logical; should the data be interpreted as bipartite (with rows and columns representing different data modes)?

as.digraph

logical; should network objects be coded as digraphs, regardless of object properties? (Recommended)

suppress.diag

logical; should loops be suppressed?

...

additional arguments to sna.edgelist (currently ignored).

Details

The sna coercion functions are normally called internally within user-level sna functions to convert network data from various supported forms into a format usable by the function in question. With few (if any) exceptions, formats acceptable by these functions should be usable with any user-level function in the sna library.

as.sociomatrix.sna takes one or more input graphs, and returns them in adjacency matrix (and/or array) form. If simplify==TRUE, consolidation of matrices having the same dimensions into adjacency arrays is attempted; otherwise, elements are returned as lists of matrices/arrays.

as.edgelist.sna takes one or more input graphs, and returns them in sna edgelist form – i.e., a three-column matrix whose rows represent edges, and whose columns contain (respectively) the sender, receiver, and value of each edge. (Undirected graphs are generally assumed to be coded as fully mutual digraphs; edges may be listed in any order.) sna edgelists must also carry an attribute named n indicating the number of vertices in the graph, and may optionally contain the attributes vnames (carrying a vector of vertex names, in order) and/or bipartite (optionally, containing the number of row vertices in a two-mode network). If the bipartite attribute is present and non-false, vertices whose numbers are less than or equal to the attribute value are taken to belong to the first mode (i.e., row vertices), and those of value greater than the attribute are taken to belong to the second mode (i.e., column vertices). Note that the bipartite attribute is not strictly necessary to represent two-mode data, and may not be utilized by all sna functions.

is.edgelist.sna returns TRUE if its argument is a sna edgelist, or FALSE otherwise; if called with a list, this check is performed (recursively) on the list elements.

Data for sna coercion routines may currently consist of any combination of standard or sparse (via SparseM) adjacency matrices or arrays, network objects, or sna edgelists. If multiple items are given, they must be contained within a list. Where adjacency arrays are specified, they must be in three-dimensional form, with dimensions given in graph/sender/receiver order. Matrices or arrays having different numbers of rows and columns are taken to be two-mode adjacency structures, and are treated accordingly; setting force.bipartite will cause square matrices to be treated in similar fashion. In the case of network or sna edgelist matrices, bipartition information is normally read from the object's internal properties.

Value

An adjacency or edgelist structure, or a list thereof.

Note

For large, sparse graphs, edgelists can be dramatically more efficient than adjacency matrices. Where such savings can be realized, sna package functions usually employ sna edgelists as their “native” format (coercing input data with as.edgelist.sna as needed). For this reason, users of large graphs can often obtain considerable savings by storing data in edgelist form, and passing edgelists (rather than adjacency matrices) to sna functions.

The maximum size of adjacency matrices and edgelists depends upon R's vector allocation limits. On a 64-bit platform, these limits are currently around 4.6e4 vertices (adjacency case) or 7.1e8 edges (edgelist case). The number of vertices in the edgelist case is effectively unlimited (and can technically be infinite), although not all functions will handle such objects gracefully. (Use of vertex names will limit the number of edgelist vertices to around 2e9.)

Author(s)

Carter T. Butts buttsc@uci.edu

See Also

sna, network

Examples

#Produce some random data, and transform it
g<-rgraph(5)
g
all(g==as.sociomatrix.sna(g))     #TRUE
as.edgelist.sna(g)                #View in edgelist form
as.edgelist.sna(list(g,g))        #Double the fun
g2<-as.sociomatrix.sna(list(g,g)) #Will simplify to an array
dim(g2)
g3<-as.sociomatrix.sna(list(g,g),simplify=FALSE)  #Do not simplify
g3                                                #Now a list

#We can also build edgelists from scratch...
n<-6
edges<-rbind(
c(1,2,1),
c(2,1,2),
c(1,3,1),
c(1,5,2),
c(4,5,1),
c(5,4,1)
)
attr(edges,"n")<-n
attr(edges,"vnames")<-letters[1:n]
gplot(edges,displaylabels=TRUE)               #Plot the graph
as.sociomatrix.sna(edges)                     #Show in matrix form

#Two-mode data works similarly
n<-6
edges<-rbind(
c(1,4,1),
c(1,5,2),
c(4,1,1),
c(5,1,2),
c(2,5,1),
c(5,2,1),
c(3,5,1),
c(3,6,2),
c(6,3,2)
)
attr(edges,"n")<-n
attr(edges,"vnames")<-c(letters[1:3],LETTERS[4:6])
attr(edges,"bipartite")<-3
edges
gplot(edges,displaylabels=TRUE,gmode="twomode")  #Plot
as.sociomatrix.sna(edges)                        #Convert to matrix


sna documentation built on Feb. 16, 2023, 9:52 p.m.

Related to sna-coercion in sna...