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.
as_nodelist(.data)
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(.data, twomode = FALSE, events)
as_diffnet(.data, twomode = FALSE)
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
Logical option used to override heuristics for distinguishing incidence (two-mode/bipartite) from adjacency (one-mode/unipartite) networks. By default FALSE.
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.
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(...)
.
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.
Other modifications:
manip_correlation
,
manip_deformat
,
manip_from
,
manip_levels
,
manip_miss
,
manip_nodes
,
manip_paths
,
manip_permutation
,
manip_preformat
,
manip_project
,
manip_reformat
,
manip_scope
,
manip_split
,
manip_ties
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 1f49656 DN-- 6 5 --
#> + attr: name (v/c)
#> + edges from 1f49656 (vertex names):
#> [1] A->I B->G B->I C->G C->H
as_tidygraph(test)
#> # A labelled, directed network of 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(create_filled(4), events = events)
#> # A tibble: 3 × 4
#> t S I R
#> <dbl> <ntwrk_ms> <int> <int>
#> 1 0 3 1 0
#> 2 1 1 3 0
#> 3 2 1 2 1