These functions coerce objects into different objects by extracting and translating the information contained in the original object:

  • as_edgelist() coerces the object into an edgelist, as data frames or tibbles.

  • as_nodelist() coerces the object into a nodelist, as a data frame or tibble.

  • as_changelist() coerces the object into a changelist, as a data frame or tibble.

  • as_globallist() coerces the object into a globallist, as a data frame or tibble.

  • as_missinglist() coerces the object into a list of the ties it records as missing, as a tibble.

  • as_infolist() coerces the object into a list of network-level information, such as the names of the nodes and ties, if not given in the nodelist or edgelist.

  • as_matrix() coerces the object into an adjacency (one-mode/unipartite) or incidence (two-mode/bipartite) matrix. If the network is a cognitive social structure (i.e. the edgelist contains a 'by' column indicating who reported/recorded each tie), as_matrix() returns a three-dimensional array instead, with dimensions for senders, receivers, and reporters. Where a network holds parallel ties, i.e. where tie_is_parallel() is TRUE for any tie, the cells of the matrix report how many ties join each pair of nodes, and so may be greater than one even where the network is neither weighted nor signed.

These coercions are extractive in the sense that they will lose any information that cannot be contained in the target format. for example, as_matrix() will lose any information about edge attributes, such as edge types or weights.

as_nodelist(.data)

as_changelist(.data, time = NULL)

as_edgelist(.data, twomode = FALSE)

as_infolist(.data)

as_globallist(.data)

as_missinglist(.data)

as_matrix(.data, twomode = NULL)

Arguments

.data

An object of a {manynet}-consistent class:

  • adjacency or incidence matrix from {base} R

  • edgelist data.frame from {base} R or tbl/tbl_df from {tibble}

  • stocnet stocnet, from the {manynet} package

  • igraph igraph, from the {igraph} package

  • network network, from the {network} package

  • tidygraph tbl_graph, from the {tidygraph} package

time

A moment to gather the changes in force at. By default NULL, in which case every change the network records is returned. Where a moment is given, only the changes recorded up to and including it are returned, one for each nodal variable a node changes, since a change states what a variable becomes from that moment on and is carried forward until another change states otherwise.

twomode

Logical option used to override heuristics for distinguishing incidence (two-mode/bipartite) from adjacency (one-mode/unipartite) networks. By default FALSE.

Value

The currently implemented coercions or translations are:

               data.frame default diff_model igraph matrix network
as_changelist           *                         *      *       *
as_edgelist             *                         *      *       *
as_globallist           *                         *      *       *
as_infolist             *                         *      *       *
as_matrix               *                  *      *      *       *
as_missinglist          *       *                 *      *       *
as_nodelist             *                         *      *       *
               network.goldfish siena stocnet tbl_graph
as_changelist                               *         *
as_edgelist                   *     *       *         *
as_globallist                               *
as_infolist                                 *         *
as_matrix                     *     *       *         *
as_missinglist                              *         *
as_nodelist                                 *         *

Details

Edgelists are expected to be held in data.frame or tibble class objects. The first two columns of such an object are expected to be the senders and receivers of a tie, respectively, and are typically named "from" and "to" (even in the case of an undirected network). These columns can contain integers to identify nodes or character strings/factors if the network is labelled. If the sets of senders and receivers overlap, a one-mode network is inferred. If the sets contain no overlap, a two-mode network is inferred. If a third, numeric column is present, a weighted network will be created.

Matrices can be either adjacency (one-mode) or incidence (two-mode) matrices. Incidence matrices are typically inferred from unequal dimensions, but since in rare cases a matrix with equal dimensions may still be an incidence matrix, an additional argument twomode can be specified to override this heuristic.

Missing ties

A missing tie is one that could have been observed and was not, which is neither a tie nor the absence of one. as_missinglist() returns them as a tibble of 'from' and 'to', with 'layer' and 'time' where the network records them.

Compared to an observed tie, in which a tie is observed to be present or absent, with only present ties appearing as rows in the ties component, a missing tie is one that could have been observed but was not. There are four different reasons a tie could be missing, and they are treated differently depending on the context.

First, there are the nodal reasons a tie could be missing, which are recorded in the nodes and changes components.

  1. Non-availability. A node was not in the network and so cannot send or receive ties. This is recorded in the 'active' column of the nodes component, and can change over time through the changes component. Note that this renders all outgoing and incoming ties missing.

  2. Non-response. A node was in the network but chose not to respond or report its ties. This is recorded in the 'na' column of the nodes component, and can also change over time through the changes component. Note that this renders only outgoing ties missing for a directed layer, and both directions for an undirected layer.

Second, a tie might be missing or missing some information, even though both nodes were in the network. This is recorded in the ties.

  1. Unobserved tie. One or more specific ties could have been reported and were not, such as one name a respondent skipped. These are held in the missings component, as a tibble of 'from' and 'to', with 'layer' and 'time' where available.

  2. Unobserved weight. One or more ties are reported as existing, but the strength of the tie is not known. This is recorded as an NA in the 'weight' column of the ties component.

Note that missing ties are not ties. net_ties() does not count them, as_edgelist() does not return them, and they are not drawn or measured unless a function asks for them by name. Where necessary, as_missinglist() returns a list of all missing ties together. net_tie_missing() reports how many there are, and impute_ties() imputes them.

Each class holds them differently. A stocnet object records which nodes did not report, from which as_missinglist() derives the ties; see make_stocnet() for how those records are held. So, unlike the other as_*list() functions, this one does not return a component verbatim: it returns the missings component together with the ties that the non-responsive nodes imply, which is nearly always the larger part. An 'igraph' or 'tbl_graph' object carries the list in a graph attribute, since igraph has no way to mark an edge as missing. A 'network' object holds each as an edge marked in the reserved 'na' attribute, which is that package's own format and the one {ergm} expects. A matrix holds each as a missing cell.

See also

Other coercions: coerce_graph

Examples

test <- data.frame(from = c("A","B","B","C","C"), to = c("I","G","I","G","H"))
as_edgelist(test)
#>   from to
#> 1    A  I
#> 2    B  G
#> 3    B  I
#> 4    C  G
#> 5    C  H
as_matrix(test)
#>   G H I
#> A 0 0 1
#> B 1 0 1
#> C 1 1 0
as_igraph(test)
#> IGRAPH 4126b3d UN-B 6 5 -- 
#> + attr: name (v/c), type (v/l)
#> + edges from 4126b3d (vertex names):
#> [1] A--I B--G B--I C--G C--H
as_tidygraph(test)
#> # A labelled, two-mode network of 3 nodes and 3 nodes and 5 ties
#> 
#> ── Nodes 
#> # A tibble: 6 × 2
#>   name  type 
#>   <chr> <lgl>
#> 1 A     FALSE
#> 2 B     FALSE
#> 3 C     FALSE
#> 4 I     TRUE 
#> 5 G     TRUE 
#> 6 H     TRUE 
#> 
#> ── Ties 
#> # A tibble: 5 × 2
#>    from    to
#>   <int> <int>
#> 1     1     4
#> 2     2     5
#> 3     2     4
#> 4     3     5
#> 5     3     6
#> 
as_network(test)
#>  Network attributes:
#>   vertices = 6 
#>   directed = FALSE 
#>   hyper = FALSE 
#>   loops = FALSE 
#>   multiple = FALSE 
#>   bipartite = 3 
#>   total edges= 5 
#>     missing edges= 0 
#>     non-missing edges= 5 
#> 
#>  Vertex attribute names: 
#>     vertex.names 
#> 
#> No edge attributes
as_missinglist(ison_classmates)
#> # A tibble: 73 × 4
#>     from    to layer    time
#>    <int> <int> <chr>   <int>
#>  1     2     1 friends     2
#>  2     2     3 friends     2
#>  3     2     4 friends     2
#>  4     2     5 friends     2
#>  5     2     6 friends     2
#>  6     2     7 friends     2
#>  7     2     8 friends     2
#>  8     2     9 friends     2
#>  9     2    10 friends     2
#> 10     2    11 friends     2
#> # ℹ 63 more rows