as {manynet}R Documentation

Modifying network classes

Description

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

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.

Usage

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.

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.

Value

The currently implemented coercions or translations are:

data.frame diff_model igraph list matrix network network.goldfish siena tbl_graph
as_edgelist 1 0 1 0 1 1 1 1 1
as_graphAM 1 0 1 0 1 1 1 1 1
as_igraph 1 0 1 0 1 1 1 1 1
as_matrix 1 0 1 0 1 1 1 1 1
as_network 1 0 1 0 1 1 1 1 1
as_siena 0 0 1 0 0 0 0 0 1
as_tidygraph 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(...).

See Also

Other modifications: add_nodes(), add_ties(), from, miss, reformat, split(), to_levels, to_paths, to_project, to_scope

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(events, manynet::create_filled(4))

[Package manynet version 0.4.4 Index]