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 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.
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.
Returns
The currently implemented coercions or translations are:
data.frame
diff_model
diffnet
igraph
list
matrix
network
network.goldfish
siena
tbl_graph
as_diffnet
0
1
0
0
0
0
0
0
0
0
as_diffusion
0
1
1
1
0
0
0
0
0
0
as_edgelist
1
0
0
1
0
1
1
1
1
1
as_graphAM
1
0
0
1
0
1
1
1
1
1
as_igraph
1
1
1
1
0
1
1
1
1
1
as_matrix
1
1
0
1
0
1
1
1
1
1
as_network
1
0
1
1
0
1
1
1
1
1
as_siena
0
0
0
1
0
0
0
0
0
1
as_tidygraph
1
1
1
1
1
1
1
1
1
1
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.
Examples
test <- data.frame(from = c("A","B","B","C","C"), to = c("I","G","I","G","H"))as_edgelist(test)as_matrix(test)as_igraph(test)as_tidygraph(test)as_network(test)# 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(create_filled(4), events = events)