as.network.matrix: Coercion from Matrices to Network Objects

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

Description

as.network.matrix attempts to coerce its first argument to an object of class network.

Usage

1
2
3
4
5
6
7
## Default S3 method:
as.network(x, ...)
## S3 method for class 'matrix'
as.network(x, matrix.type = NULL, directed = TRUE, 
    hyper = FALSE, loops = FALSE, multiple = FALSE, bipartite = FALSE,
    ignore.eval = TRUE, names.eval = NULL, na.rm = FALSE, 
    edge.check = FALSE, ...)

Arguments

x

a matrix containing an adjacency structure

matrix.type

one of "adjacency", "edgelist", "incidence", or NULL

directed

logical; should edges be interpreted as directed?

hyper

logical; are hyperedges allowed?

loops

logical; should loops be allowed?

multiple

logical; are multiplex edges allowed?

bipartite

count; should the network be interpreted as bipartite? If present (i.e., non-NULL) it is the count of the number of actors in the bipartite network. In this case, the number of nodes is equal to the number of actors plus the number of events (with all actors preceding all events). The edges are then interpreted as nondirected.

ignore.eval

logical; ignore edge values?

names.eval

optionally, the name of the attribute in which edge values should be stored

na.rm

logical; ignore missing entries when constructing the network?

edge.check

logical; perform consistency checks on new edges?

...

additional arguments

Details

Depending on matrix.type, one of three edgeset constructor methods will be employed to read the input matrix (see edgeset.constructors). If matrix.type==NULL, which.matrix.type will be used to guess the appropriate matrix type.

The coercion methods will recognize and attempt to utilize the sna extended matrix attributes where feasible. These are as follows:

These attributes are generally used with edgelists, and indeed data in sna edgelist format should be transparently converted in most cases. Where the extended matrix attributes are in conflict with the actual contents of x, results are no guaranteed (but the latter will usually override the former). For an edge list, the number of nodes in a network is determined by the number of unique nodes specified. If there are isolate nodes not in the edge list, the "n" attribute needs to be set. See example below.

Value

An object of class network

Author(s)

Carter T. Butts buttsc@uci.edu and David Hunter dhunter@stat.psu.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

edgeset.constructors, network, which.matrix.type

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#Draw a random matrix
m<-matrix(rbinom(25,1,0.5),5)
diag(m)<-0

#Coerce to network form
g<-as.network.matrix(m,matrix.type="adjacency")

# edge list example. Only 4 nodes in the edge list.
m = matrix(c(1,2, 2,3, 3,4), byrow = TRUE, nrow=3)
attr(m, 'n') = 7
as.network(m, matrix.type='edgelist')

Example output

network: Classes for Relational Data
Version 1.15 created on 2019-04-01.
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.

 Network attributes:
  vertices = 7 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  total edges= 3 
    missing edges= 0 
    non-missing edges= 3 

 Vertex attribute names: 
    vertex.names 

No edge attributes

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