These functions coerce networks into the 'stocnet' class of {manynet},
and from it into the data objects of the modelling packages:
as_stocnet() coerces the object into a 'stocnet' object
(see make_stocnet()).
as_siena() coerces the object into a {RSiena} 'sienadata' object.
This object holds the dependent variables and the covariates together.
See the section "SIENA" for which variables become dependent.
as_monan() coerces a two-mode network of people and places
into a {MoNAn} 'processState.monan' 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.
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", ...)
# S3 method for class 'array'
as_stocnet(
.data,
twomode = FALSE,
...,
over = c("time", "by", "about", "layer")
)
as_siena(.data, twomode = FALSE, focal = NULL, ...)
as_monan(.data, layer = NULL, time1, time2)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
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 over for an array.
attribute is the former name of over, and still works.
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.
For a three-dimensional array, what its third dimension
runs over, which becomes a column of the ties, as the over of
to_aggregated() names the column it combines:
"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.
A character vector of the names of the tie layers and
node attributes that become dependent variables.
By default, as_siena() uses the focal element of the information
of the network.
This argument replaces that element; it does not add to it.
For a network of people and places with more than one layer of ties between people and places, the name of the layer that says where each person is.
The two times at which the places of the people are taken, as the origin and the destination. The defaults are the first and the last time of the network.
as_stocnet() returns a 'stocnet' object,
as_siena() a 'sienadata' object of {RSiena}
(the data object for RSiena::siena07(), not one dependent variable),
and as_monan() a 'processState.monan' object.
as_stocnet() reads a document-feature matrix of {quanteda} ('dfm')
and a term-document or document-term matrix of {tm}
('TermDocumentMatrix', 'DocumentTermMatrix').
Each gives a two-mode network of "documents" and "terms",
with the count (or other weighting) of each term in each document as the
weight of its tie, as collect_text() gives.
The document variables of a 'dfm' become attributes of the documents.
Neither {quanteda} nor {tm} needs to be installed.
as_stocnet() reads the bibliographic records of {bibliometrix}
('bibliometrixDB', as bibliometrix::convert2df() gives)
as collect_bibliography() does,
into a multimodal network of works, authors, keywords, and sources.
The other coercions, such as as_igraph() and as_tidygraph(),
read the records through as_stocnet(),
so the functions of the stocnet packages take the records directly.
The records cannot be rebuilt from a network,
so a function that would return the class it was given
returns a 'stocnet' for them.
{bibliometrix} does not need to be installed.
as_siena() returns the data object of {RSiena} ('sienadata'),
as RSiena::sienaDataCreate() gives it.
It does not return one dependent variable.
The object holds all the variables of the network,
and each variable has one of these roles:
Each tie layer that focal names becomes a dependent network.
Each node attribute that focal names becomes a dependent behaviour.
The attribute must have a value at each wave, as changes.
Each other tie layer becomes a dyadic covariate. The covariate is varying when the layer has ties at two or more waves, and constant when it has ties at one wave only or has no waves.
Each other node attribute becomes a node covariate. The covariate is varying when the attribute has changes over the waves, and constant when it has no changes.
A change of the 'active' status of a node becomes a composition change.
By default, focal is the focal element of the information
of the network (see mutate_info()).
When focal is empty in an interactive session,
as_siena() asks which tie layers and attributes are dependent.
When focal is empty in other sessions,
the first tie layer becomes the dependent network
and all node attributes become covariates.
A dependent network must be binary and must have two or more waves.
Arguments in ... go to RSiena::sienaDependent() for each
dependent variable, for example allowOnly = FALSE.
as_monan() takes a two-mode network,
with people as the first mode and places as the second mode.
The ties between people and places say where each person is.
They have begin and end times, or the time of each wave of a panel.
A person holds one place at a time.
as_monan() takes the place of each person at time1 and time2,
and gives these elements:
moves, the dependent variable, with one row for each person:
the place at time1 and the place at time2.
A person who stays has the same place twice.
people and places, the two node sets.
each numeric attribute of the people or of the places, under its own name.
each layer of ties among the places, such as adjacency or distance, under its layer name.
as_monan() also takes a network of places with an occupant record,
as play_mobility() gives.
The occupants are then the people,
and the attributes of the occupants at the start are
the attributes of the people.
The start is time 0.
A person who has no place at one of the two times is not included.
MoNAn requires that every place occurs in moves,
so a place that no person holds at either time is removed.
See also to_mobility(), which gives the moves as a network of places.
Other coercions:
coerce_graph,
coerce_list,
coerce_matrix
test <- data.frame(from = c("A","B","B","C","C"), to = c("I","G","I","G","H"))
as_stocnet(test)
#> # A labelled, undirected network of 6 nodes and 5 ties
#>
#> ── Nodes
#> # A tibble: 6 × 1
#> label
#> <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
#>