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_igraph() coerces the object into an {igraph} graph object.

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

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

  • 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().

  • as_diffnet() coerces a diff_model object into a {netdiffuseR} diffnet object.

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_igraph(.data, twomode = FALSE)

as_tidygraph(.data, twomode = FALSE)

as_network(.data, twomode = FALSE)

as_stocnet(.data, twomode = FALSE, ...)

# S3 method for class 'node_measure'
as_stocnet(
  .data,
  twomode = FALSE,
  compare = c("absdiff", "diff", "sender", "receiver"),
  ...
)

# S3 method for class 'node_member'
as_stocnet(.data, twomode = FALSE, compare = "same", ...)

as_hypergraph(.data)

# S3 method for class 'array'
as_stocnet(
  .data,
  twomode = FALSE,
  ...,
  attribute = c("time", "by", "about", "layer")
)

as_siena(.data, twomode = FALSE)

as_graphAM(.data, twomode = NULL)

as_diffusion(.data, twomode = FALSE, events)

as_diffnet(.data, twomode = FALSE)

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

twomode

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

...

Further arguments passed to or from other methods, such as attribute for an array.

compare

For a node measure or a node membership, how the values of two nodes are compared to give the tie between them; see as_matrix(). Comparing by "same" or "absdiff" gives an undirected network, and comparing by "diff", "sender", or "receiver" a directed one. A comparison of zero is no tie.

attribute

For a three-dimensional array, what its third dimension holds, which becomes a column of the ties: "time" for the waves of a panel, "by" for the reporters of a cognitive social structure, "about" for the targets of gossip, or "layer" for the layers of a multiplex network. An array cannot say which of these it holds. Where its third dimension is as long as the network has nodes, it could hold any of them, so this must be given. Otherwise it cannot hold reporters or targets, and "time" is assumed.

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:

              array data.frame default diff_model diffnet hypergraph igraph
as_diffnet                                      *
as_diffusion                                    *       *                 *
as_graphAM                           *
as_hypergraph                        *                             *
as_igraph                    *                  *       *                 *
as_network                   *                          *                 *
as_siena                             *
as_stocnet        *          *                                     *      *
as_tidygraph                 *                  *       *                 *
              list matrix mnet network network.goldfish networkDynamic
as_diffnet
as_diffusion                 *
as_graphAM              *
as_hypergraph
as_igraph               *            *                *              *
as_network              *            *                *              *
as_siena
as_stocnet              *            *
as_tidygraph     *      *            *                *              *
              node_measure node_member siena sienadata stocnet tbl_graph
as_diffnet
as_diffusion                                                 *
as_graphAM
as_hypergraph
as_igraph                                  *         *       *         *
as_network                                 *         *       *         *
as_siena                                                     *
as_stocnet               *           *               *       *
as_tidygraph                               *         *       *         *

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(...).

Hypergraphs

as_hypergraph() returns a 'hypergraph' object of the {HyperG} package, which is a sparse incidence matrix of hyperedges by nodes, and as_stocnet() reads one. A network that is not a hypergraph is reformatted as one first, as by to_hypergraph(). A 'hypergraph' object holds which nodes each hyperedge has and their names, and nothing else, so weights, attributes, directions, and times are not carried. Neither function needs {HyperG} to be installed.

Note that is_hypergraph() marks a network of any class that holds hyperedges, of which a 'stocnet' object holds the most (see the Hypergraphs section of make_stocnet()).

See also

Other coercions: coerce_list, coerce_matrix

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 e4ca1e6 UN-B 6 5 -- 
#> + attr: name (v/c), type (v/l)
#> + edges from e4ca1e6 (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_hypergraph(create_ring(4))
#> $M
#> 4 x 4 sparse Matrix of class "dgCMatrix"
#>      1 2 3 4
#> [1,] 1 1 . .
#> [2,] . 1 1 .
#> [3,] . . 1 1
#> [4,] 1 . . 1
#> 
#> attr(,"class")
#> [1] "hypergraph"
  # How to create a diff_model object from (basic) observed data
  events <- data.frame(time = c(0,1,1,2,3), 
                       node = c(1,2,3,2,4),
                       var = "diffusion", 
                       value = c("I","I","I","R","I"))
  bind_changes(create_filled(4), events)