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_siena(.data, twomode = FALSE)
as_graphAM(.data, twomode = NULL)
as_diffusion(.data, twomode = FALSE, events)
as_diffnet(.data, twomode = FALSE)
as_stocnet(.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 mnet network
as_diffnet *
as_diffusion * * * *
as_graphAM * * * *
as_igraph * * * * * *
as_network * * * * *
as_siena *
as_stocnet * * *
as_tidygraph * * * * * * *
network.goldfish networkDynamic siena stocnet tbl_graph
as_diffnet
as_diffusion
as_graphAM * * * *
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(...).
Other coercions:
coerce_list
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 b4d390c DN-- 6 5 --
#> + attr: name (v/c)
#> + edges from b4d390c (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
#>
#> ── Nodes
#> # A tibble: 6 × 1
#> name
#> <chr>
#> 1 A
#> 2 B
#> 3 C
#> 4 I
#> 5 G
#> 6 H
#>
#> ── 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
# 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"))
add_changes(create_filled(4), events)
#> ── # Filled network ────────────────────────────────────────────────────────────
#> # A undirected network of 4 nodes and 6 ties
#>
#> ── Nodes
#> # A tibble: 4 × 1
#> diffusion
#> <chr>
#> 1 S
#> 2 S
#> 3 S
#> 4 S
#>
#> ── Changes
#> # A tibble: 5 × 4
#> time node var value
#> <dbl> <dbl> <chr> <chr>
#> 1 0 1 diffusion I
#> 2 1 2 diffusion I
#> 3 1 3 diffusion I
#> 4 2 2 diffusion R
#> # ℹ 1 more row
#>
#> ── Ties
#> # A tibble: 6 × 2
#> from to
#> <int> <int>
#> 1 1 2
#> 2 1 3
#> 3 1 4
#> 4 2 3
#> # ℹ 2 more rows
#>