The as_ functions in {manynet} coerce objects of any of the following common classes of social network objects in R into the declared class:

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

  • as_matrix() coerces the object into an adjacency (one-mode/unipartite) or incidence (two-mode/bipartite) matrix.

  • as_igraph() coerces the object into an {igraph} graph object.

  • as_tidygraph() coerces the object into a {tidygraph} tbl_graph objects.

  • as_network() coerces the object into a {network} network objects.

  • as_siena() coerces the (igraph/tidygraph) object into a SIENA dependent variable.

  • as_graphAM() coerces the object into a graph adjacency matrix.

  • as_diffusion() coerces a table of diffusion events into a diff_model object similar to the output of play_diffusion().

An effort is made for all of these coercion routines to be as lossless as possible, though some object classes are better at retaining certain kinds of information than others. Note also that there are some reserved column names in one or more object classes, which could otherwise lead to some unexpected results.

as_edgelist(.data, twomode = FALSE)

as_matrix(.data, twomode = NULL)

as_igraph(.data, twomode = FALSE)

as_tidygraph(.data, twomode = FALSE)

as_network(.data, twomode = FALSE)

as_siena(.data, twomode = FALSE)

as_graphAM(.data, twomode = NULL)

as_diffusion(events, .data)

Arguments

.data

An object of a manynet-consistent class:

  • matrix (adjacency or incidence) from {base} R

  • edgelist, a data frame from {base} R or tibble from {tibble}

  • igraph, from the {igraph} package

  • network, from the {network} package

  • tbl_graph, from the {tidygraph} package

twomode

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

events

A table (data frame or tibble) of diffusion events with columns t indicating the time (typically an integer) of the event, nodes indicating the number or name of the node involved in the event, and event, which can take on the values "I" for an infection event, "E" for an exposure event, or "R" for a recovery event.

Value

The currently implemented coercions or translations are:

data.framediff_modeligraphlistmatrixnetworknetwork.goldfishsienatbl_graph
as_edgelist101011111
as_graphAM101011111
as_igraph101011111
as_matrix101011111
as_network101011111
as_siena001000001
as_tidygraph111111111

as_diffusion() and play_diffusion() return a 'diff_model' object that contains two different tibbles (tables) -- a table of diffusion events and a table of the number of nodes in each relevant component (S, E, I, or R) -- as well as a copy of the network upon which the diffusion ran. By default, a compact version of the component table is printed (to print all the changes at each time point, use print(..., verbose = T)). To retrieve the diffusion events table, use summary(...).

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.

This information is usually already embedded in {igraph}, {tidygraph}, and {network} objects.

See also

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 af38eb9 DN-- 6 5 -- 
#> + attr: name (v/c)
#> + edges from af38eb9 (vertex names):
#> [1] A->I B->G B->I C->G C->H
as_tidygraph(test)
#> # A labelled, directed network with 6 nodes and 5 arcs
#> # A tibble: 6 × 1
#>   name 
#>   <chr>
#> 1 A    
#> 2 B    
#> 3 C    
#> 4 I    
#> 5 G    
#> 6 H    
#> # 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
  # How to create a diff_model object from (basic) observed data
  events <- data.frame(t = c(0,1,1,2,3), nodes = c(1,2,3,2,4), event = c("I","I","I","R","I"))
  as_diffusion(events, manynet::create_filled(4))
#> # A tibble: 3 × 4
#>       t     S     I     R
#>   <dbl> <dbl> <int> <int>
#> 1     0     3     1     0
#> 2     1     1     3     0
#> 3     2     1     2     1