These functions project network data:
to_mode() projects a network onto one of its modes.
Two nodes of that mode get a tie when they have ties to the same nodes
of another mode.
Give the mode as an index or as a name.
It also projects a network of three or more modes.
to_mode1() projects a two-mode network onto its first mode,
for example the rows.
to_mode2() projects a two-mode network onto its second mode,
for example the columns.
to_mobility() projects a two-mode network of people and places
onto the places, with one tie for each move of a person.
to_linegraph() makes the line graph of a network.
Each tie becomes a node.
Two of these nodes get a tie when their ties share a node.
to_hypergraph() makes a hypergraph,
where one tie can connect more than two nodes.
to_simplicial() makes a simplicial complex,
such as the maximal cliques of a one-mode network.
to_mode1(
.data,
similarity = c("count", "jaccard", "rand", "pearson", "yule", "match", "overlap",
"crossmin", "maxcrossmin", "sqdiff", "covariance", "bonacich", "ochiai", "ochiai2",
"czekanowski", "sokalsneath", "hamann", "rogerstanimoto", "euclidean", "manhattan",
"hamming", "cosine", "spearman", "kendall", "ruzicka", "agreement", "disagreement",
"signed", "activity", "association", "fractional")
)
to_mode2(
.data,
similarity = c("count", "jaccard", "rand", "pearson", "yule", "match", "overlap",
"crossmin", "maxcrossmin", "sqdiff", "covariance", "bonacich", "ochiai", "ochiai2",
"czekanowski", "sokalsneath", "hamann", "rogerstanimoto", "euclidean", "manhattan",
"hamming", "cosine", "spearman", "kendall", "ruzicka", "agreement", "disagreement",
"signed", "activity", "association", "fractional")
)
to_mobility(.data, layer = NULL, weighted = FALSE)
to_mode(
.data,
mode = 1,
similarity = c("count", "jaccard", "rand", "pearson", "yule", "match", "overlap",
"crossmin", "maxcrossmin", "sqdiff", "covariance", "bonacich", "ochiai", "ochiai2",
"czekanowski", "sokalsneath", "hamann", "rogerstanimoto", "euclidean", "manhattan",
"hamming", "cosine", "spearman", "kendall", "ruzicka", "agreement", "disagreement",
"signed", "activity", "association", "fractional"),
through = NULL
)
to_linegraph(.data)
to_hypergraph(.data)
to_simplicial(.data)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
How to measure how alike two nodes are. The default is "count". Each measure compares the ties of two nodes to the other mode.
The measures are in groups below. The measures in one group put the pairs of nodes in the same order, and differ only in their scale. So the choice of group is more important than the choice in a group.
Measures for valued and binary data:
"count" counts the shared ties, as \(XX'\). For valued data, it adds the products of the tie weights, and a repeated tie counts as many times as it is repeated. For signed data, it adds the products of their absolute values, since the signed rules below read the signs. It is the default, and the fastest.
"match" counts the nodes of the other mode where the two nodes have the same value. This includes the nodes that neither of them has a tie to. For binary data, it is "rand" times the number of nodes in the other mode. Use it when the level of each tie is important.
"crossmin" adds the smaller of the two weights for each shared node. It shows what two nodes can give together. For binary data, it is the same as "count".
"overlap" divides "crossmin" by the smaller of the two nodes' totals. This is the Szymkiewicz-Simpson coefficient. For data with no negative values, it is from 0 to 1. Use it when one node is much more active than the other. For valued data, xUCINET divides the count and not "crossmin", so its values can be more than 1.
"ruzicka" divides "crossmin" by the sum of the two nodes' totals minus "crossmin". This is Ruzicka's weighted Jaccard coefficient, from 0 to 1. For binary data, it is the same as "jaccard". Use it when you want "jaccard" but must keep the tie weights.
"maxcrossmin" takes the largest of these smaller weights, not their sum. So one strong shared tie is enough. For binary data, it only shows if two nodes share any tie.
"sqdiff" adds the squared differences of the weights, as \(d\). It gives \(1/(1+d)\), so that a larger value means more alike. Two nodes with the same ties get 1. To get \(d\) back, calculate \(1/x - 1\).
"pearson" is the correlation of the two nodes' ties. "covariance" is the same, but not standardised. Use "covariance" when the variance of the ties is important.
"spearman" and "kendall" are rank correlations. Use them when the order of the weights is reliable, but the spacing is not. An example is ordinal ratings.
"cosine" is the cosine of the angle between the two nodes' ties. It is like "pearson", but it does not centre the ties first. So two nodes are alike when their ties are proportional. For binary data, it is the same as "ochiai". For a node with no ties, "cosine" gives 0, but "ochiai" divides by zero.
"euclidean" and "manhattan" use the distance \(d\) between the two nodes' ties, and give \(1/(1+d)\), as "sqdiff" does. "manhattan" adds the absolute differences. "euclidean" gives more weight to one large difference than to many small differences. To get \(d\) back, calculate \(1/x - 1\).
Measures for binary data only. These measures change valued data to binary data first, and give a warning. For two nodes, \(a\) is the number of nodes in the other mode that both have a tie to. \(b\) and \(c\) are the numbers that only one of them has a tie to. \(d\) is the number that neither has a tie to.
Measures that do not use \(d\). Use them when two missing ties tell you nothing, for example in a sparse network with many events. "jaccard" is \(a/(a+b+c)\). "czekanowski" (also Dice or Sorensen) is \(2a/(2a+b+c)\), which gives more weight to \(a\). "sokalsneath" is \(a/(a+2(b+c))\), which gives more weight to \(b\) and \(c\). For valued data, use "ruzicka" in place of "jaccard".
Measures that count \(d\) as a match. Use them when a missing tie tells you as much as a tie. "rand" (simple matching) is \((a+d)/(a+b+c+d)\). "hamann" is \(((a+d)-(b+c))/(a+b+c+d)\), from -1 to 1. It is positive when there are more matches than differences. "rogerstanimoto" is \((a+d)/(a+2(b+c)+d)\).
Measures from the odds ratio \(ad/bc\). "yule" is Yule's Q, \((ad-bc)/(ad+bc)\). "bonacich" is \(\sqrt{ad}/(\sqrt{ad}+\sqrt{bc})\), which is Yule's Y from 0 to 1. Both give 1 when \(b\) or \(c\) is 0.
Geometric measures. "ochiai" is \(a/\sqrt{(a+b)(a+c)}\), the cosine for binary data. "ochiai2" (Sokal and Sneath's fifth measure) is \(ad/\sqrt{(a+b)(a+c)(d+b)(d+c)}\), which also uses \(d\). These two do not put pairs in the same order as any other group, so try them too.
"hamming" counts the differences, \(b+c\), as the Hamming distance. It gives \(1/(1+b+c)\). It puts pairs in the same order as "rand".
Measures that change "count" for how active each node is:
"activity" divides "count" by the average number of ties of the two nodes. For binary data, it is the same as "czekanowski".
"association" divides "count" by the count that chance would give. A value above 1 means that two nodes share more than chance would give. This is the association strength of van Eck and Waltman (2009).
"fractional" shares each node of the other mode among its members. For example, a work with \(n\) authors adds \(1/(n-1)\) to each pair of its authors. Each author then gets a total of 1 from each work. A work with one author adds nothing. This is the fractional counting of Perianes-Rodriguez et al. (2016).
Measures that read the sign of each tie: "agreement", "disagreement", and "signed". See the section on weighted and signed networks below.
These six measures count every tie, also when a node has more than one tie to the same node.
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.
Logical. If TRUE, the ties of the moves between two
places are summed into one tie, with the number of moves as its weight.
The default is FALSE, one tie for each move.
The mode to project the network onto.
Give an index, such as 1 or 2, or the name of the mode.
For a two-mode network, FALSE is the first mode and TRUE the second.
The default is 1, the first mode, for example the rows.
A name is compared with the names of the modes from mode_names().
Set these names with add_info().
The comparison ignores case, plurals, and other words in the name.
For example, if the modes are "women" and "social events",
then "social events", "events", and "event" all give the second mode.
If a name matches more than one mode, the function stops.
Then give a name that tells the modes apart, or give an index.
The modes to project mode through,
as indices or names, as for mode.
The default is all the other modes.
This makes a difference only for a network of three or more modes.
The nodes of all the modes in through then count as one mode.
Ties within one mode, and ties to other modes, are not used.
For example, take a network of authors, works, and keywords.
to_mode(.data, "authors", through = "works") ties two authors
who wrote a work together.
to_mode(.data, "works") ties two works that share an author
or a keyword.
To keep two modes, for example to tie authors to keywords,
use to_twomode(.data, through = "works").
An object of the same class as the function was given, modified as explained in the function description, details, or section. Functions that split a network return a list of such objects.
Not all functions have methods available for all object classes. Below are the currently implemented S3 methods:
| Category | Feature | manynet::to_mode1()/to_mode2() | igraph::bipartite_projection() | network/sna manual |
| Input | Dedicated function | yes | yes | no |
| Accepted input classes | igraph, network, tidygraph, matrix, edgelist | igraph only | any (manual extraction) | |
| Detects mode membership from | mode node attribute | type vertex attribute | bipartite network attr (positional) | |
| Projection | Returns both projections at once | no — one per call | yes — list of two | two manual calls |
| Projects mode 1 (actors) | to_mode1() | which = "true" | A %*% t(A) | |
| Projects mode 2 (events) | to_mode2() | which = "false" | t(A) %*% A | |
| Weights | Raw co-membership counts | yes | yes (multiplicity = TRUE) | yes |
| Binary (unweighted) output | yes | yes (multiplicity = FALSE) | threshold manually | |
| Jaccard normalisation | yes | no | code manually | |
| Cosine normalisation | yes | no | code manually | |
| Other similarity measures | 31 in all, see similarity | no | code manually | |
| Attributes | Retains node attributes | yes | yes | no — lost in matrix round-trip |
| Retains edge attributes | weight only | weight only | no | |
| Removes self-loops automatically | yes | yes | diag(P) <- 0 manually | |
| Output | Output class matches input | yes | no | no |
| Directed projection support | limited | no — undirected only | yes — asymmetric matrix | |
| Usability | Lines of code (basic case) | 1 | 1 | 4–6 |
| Lines of code (Jaccard weights) | 1 | ~8 manual | ~8 manual | |
| Pipe-friendly | yes | with wrappers | no |
Most measures read the weight of a tie as how strong the tie is. The measures for binary data change each weight to 1 first, and give a warning.
Three measures read the sign of a tie instead.
The sign shows if a node is for (1) or against (-1)
a node of the other mode.
For example, in irps_nuclear,
each speaker supports or opposes each concept.
"agreement" counts the pairs of ties with the same sign. Two speakers who both support a concept agree. Two speakers who both oppose a concept also agree.
"disagreement" counts the pairs of ties with opposite signs.
"signed" is "agreement" minus "disagreement". The result is a signed network. A negative tie means that two nodes disagree more often than they agree.
If a speaker makes two statements about the same concept,
both statements count.
To keep agreement and disagreement in one network,
join the two networks with from_layers().
The weights can also be on a scale, for example from -2 to 2. Then each pair of ties adds a part of 1 to "agreement", and the rest to "disagreement". Two ties with the same value add 1 to "agreement". Two ties at the two ends of the scale add 1 to "disagreement". In general, "disagreement" adds \(|s_1 - s_2|/r\), where \(r\) is the range of the scale.
To weight a two-mode network of documents and terms
before the projection, use to_normalised(rule = "tfidf").
to_mobility() projects a two-mode network of people and places
onto the places.
The people are the first mode, and the places 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.
A move is the end of one stay of a person and the begin of the next.
The result is a directed network of the places,
with their attributes,
and one tie from the origin to the destination for each move.
The tie has the time of the move and the person who moves.
to_mobility() also takes a network of places with an occupant record,
as play_mobility() gives.
The person of each tie is then the name of the occupant,
and the nodes keep only the attributes of the places.
See also as_monan(), which gives the places of the people
at two times to {MoNAn}.
In a hypergraph, one tie can connect any number of nodes.
This tie is a hyperedge.
Examples are the people at a meeting, or the authors of a paper.
to_hypergraph() returns the class it was given.
Nothing is lost.
For a two-mode network, each node of the second mode becomes
a hyperedge.
The hyperedge connects the nodes of the first mode
that have ties to that node.
The attributes of the second-mode nodes become attributes
of the hyperedges.
The attributes of the ties, such as weights, stay with each member.
to_twomode() gives the two-mode network back.
For a one-mode network, each tie becomes a hyperedge of its two nodes,
with its attributes.
If the ties are directed, the hyperedges are directed too.
The sender is on the 'from' side, and the receiver on the 'to' side.
to_mode() gives the one-mode network back.
A 'stocnet' object keeps each hyperedge as one row of its ties.
The with column of that row lists the members of the hyperedge
(see the Hypergraphs section of make_stocnet()).
Other classes have no hyperedges.
They keep each hyperedge as a node of a second mode, with a mark.
With this mark, is_hypergraph() finds the hypergraph,
and coercion back to a 'stocnet' object gives the hyperedges back.
A 'network' object is different, because {network} has hyperedges.
A simplicial complex is a hypergraph where each subset of a hyperedge
is also a hyperedge.
So its largest hyperedges, the faces, describe all of it.
to_simplicial() finds these faces,
and marks the result as a simplicial complex.
For a one-mode network, the faces are the maximal cliques,
because each subset of a clique is also a clique.
The direction, weights, and other attributes of the ties are lost.
to_mode() gives the one-mode network that the cliques cover.
For a two-mode network or a hypergraph, the faces are the hyperedges that are not a subset of another hyperedge.
Borgatti, Stephen P., and Daniel S. Halgin. 2011. "Analyzing affiliation networks". In The SAGE Handbook of Social Network Analysis, 417-433. London: SAGE.
Bonacich, Phillip. 1972. "Technique for analyzing overlapping memberships". Sociological Methodology 4: 176-185. doi:10.2307/270732
van Eck, Nees Jan, and Ludo Waltman. 2009. "How to normalize cooccurrence data? An analysis of some well-known similarity measures". Journal of the American Society for Information Science and Technology 60(8): 1635-1651. doi:10.1002/asi.21075
Perianes-Rodriguez, Antonio, Ludo Waltman, and Nees Jan van Eck. 2016. "Constructing bibliometric networks: A comparison between full and fractional counting". Journal of Informetrics 10(4): 1178-1195. doi:10.1016/j.joi.2016.10.006
to_proximity(), which uses the same measures on a one-mode
network.
It compares nodes by their ties to each other,
not by their ties to another mode.
to_cosine(), which gives the cosine over the columns of a matrix
without a projection.
Other modifications:
modif_backbone,
modif_concepts,
modif_direction,
modif_from_parts,
modif_from_ternary,
modif_influence,
modif_labels,
modif_layers,
modif_levels,
modif_loops,
modif_miss,
modif_motifs,
modif_paths,
modif_permutation,
modif_proximity,
modif_scope,
modif_split,
modif_weight
Other projections:
modif_concepts
to_mode1(ison_southern_women)
#>
#> ── # Projection of Southern Women Data ─────────────────────────────────────────
#> # A labelled, weighted, undirected network of 18 nodes and 139 participation
#> ties
#> # Transformed by projection: mode 1 (count)
#>
#> ── Nodes
#> # A tibble: 18 × 4
#> label Surname Title active
#> <chr> <chr> <chr> <lgl>
#> 1 Evelyn Jefferson Mrs TRUE
#> 2 Laura Mandeville Miss TRUE
#> 3 Theresa Anderson Miss TRUE
#> 4 Brenda Rogers Miss TRUE
#> 5 Charlotte McDowd Miss TRUE
#> 6 Frances Anderson Miss TRUE
#> # ℹ 12 more rows
#>
#> ── Ties
#> # A tibble: 139 × 3
#> from to weight
#> <int> <int> <dbl>
#> 1 1 2 6
#> 2 1 4 6
#> 3 1 3 7
#> 4 1 5 3
#> 5 1 6 4
#> 6 1 7 3
#> # ℹ 133 more rows
#>
to_mode2(ison_southern_women)
#> ── # Projection of Southern Women Data ─────────────────────────────────────────
#> # A labelled, weighted, undirected network of 14 nodes and 66 participation
#> ties
#> # Transformed by projection: mode 2 (count)
#>
#> ── Nodes
#> # A tibble: 14 × 4
#> label Surname Title active
#> <chr> <chr> <chr> <lgl>
#> 1 E1 6/27 NA FALSE
#> 2 E2 3/2 NA FALSE
#> 3 E3 4/12 NA FALSE
#> 4 E4 9/26 NA FALSE
#> # ℹ 10 more rows
#>
#> ── Changes
#> # A tibble: 14 × 4
#> time node var value
#> <date[1d]> <int> <chr> <list>
#> 1 1936-02-23 11 active TRUE<lgl>
#> 2 1936-02-25 5 active TRUE<lgl>
#> 3 1936-03-02 2 active TRUE<lgl>
#> 4 1936-03-15 7 active TRUE<lgl>
#> # ℹ 10 more rows
#>
#> ── Ties
#> # A tibble: 66 × 3
#> from to weight
#> <int> <int> <dbl>
#> 1 1 2 2
#> 2 1 3 3
#> 3 1 4 2
#> 4 1 5 3
#> # ℹ 62 more rows
#>
moves <- make_stocnet(info = list(directed = FALSE, update = "replace"),
nodes = data.frame(label = c("Ann", "Bob", "Home", "Work"),
mode = c("people", "people", "places", "places")),
ties = data.frame(from = c(1, 1, 2, 2), to = c(3, 4, 3, 3),
time = c(1, 2, 1, 2)))
to_mobility(moves)
#> # A longitudinal, labelled, directed network of 2 nodes and 1 arcs over 1 waves
#>
#> ── Nodes
#> # A tibble: 2 × 1
#> label
#> <chr>
#> 1 Home
#> 2 Work
#>
#> ── Ties
#> # A tibble: 1 × 4
#> from to time person
#> <int> <int> <dbl> <chr>
#> 1 1 2 2 Ann
#>
to_mode(ison_southern_women, 2)
#> ── # Projection of Southern Women Data ─────────────────────────────────────────
#> # A labelled, weighted, undirected network of 14 nodes and 66 participation
#> ties
#> # Transformed by projection: mode 2 (count)
#>
#> ── Nodes
#> # A tibble: 14 × 4
#> label Surname Title active
#> <chr> <chr> <chr> <lgl>
#> 1 E1 6/27 NA FALSE
#> 2 E2 3/2 NA FALSE
#> 3 E3 4/12 NA FALSE
#> 4 E4 9/26 NA FALSE
#> # ℹ 10 more rows
#>
#> ── Changes
#> # A tibble: 14 × 4
#> time node var value
#> <date[1d]> <int> <chr> <list>
#> 1 1936-02-23 11 active TRUE<lgl>
#> 2 1936-02-25 5 active TRUE<lgl>
#> 3 1936-03-02 2 active TRUE<lgl>
#> 4 1936-03-15 7 active TRUE<lgl>
#> # ℹ 10 more rows
#>
#> ── Ties
#> # A tibble: 66 × 3
#> from to weight
#> <int> <int> <dbl>
#> 1 1 2 2
#> 2 1 3 3
#> 3 1 4 2
#> 4 1 5 3
#> # ℹ 62 more rows
#>
to_mode(ison_southern_women, "events")
#> ── # Projection of Southern Women Data ─────────────────────────────────────────
#> # A labelled, weighted, undirected network of 14 nodes and 66 participation
#> ties
#> # Transformed by projection: mode 2 (count)
#>
#> ── Nodes
#> # A tibble: 14 × 4
#> label Surname Title active
#> <chr> <chr> <chr> <lgl>
#> 1 E1 6/27 NA FALSE
#> 2 E2 3/2 NA FALSE
#> 3 E3 4/12 NA FALSE
#> 4 E4 9/26 NA FALSE
#> # ℹ 10 more rows
#>
#> ── Changes
#> # A tibble: 14 × 4
#> time node var value
#> <date[1d]> <int> <chr> <list>
#> 1 1936-02-23 11 active TRUE<lgl>
#> 2 1936-02-25 5 active TRUE<lgl>
#> 3 1936-03-02 2 active TRUE<lgl>
#> 4 1936-03-15 7 active TRUE<lgl>
#> # ℹ 10 more rows
#>
#> ── Ties
#> # A tibble: 66 × 3
#> from to weight
#> <int> <int> <dbl>
#> 1 1 2 2
#> 2 1 3 3
#> 3 1 4 2
#> 4 1 5 3
#> # ℹ 62 more rows
#>
to_mode(irps_nuclear, "speakers", "signed")
#> ── # Projection of German nuclear discourse network ────────────────────────────
#> # A labelled, signed, weighted, undirected network of 337 nodes and 11035 ties
#> # Transformed by projection: mode 1 (signed)
#>
#> ── Nodes
#> # A tibble: 337 × 9
#> label active politician govt coalition office org party power
#> <chr> <lgl> <lgl> <lgl> <lgl> <lgl> <chr> <chr> <int>
#> 1 VfEW TRUE FALSE FALSE NA FALSE VfEW NA 0
#> 2 Angela Merkel TRUE TRUE TRUE TRUE TRUE CDU 31 2
#> 3 Sunday Times TRUE FALSE FALSE NA FALSE Sunday T… NA 0
#> 4 SPD TRUE TRUE FALSE FALSE FALSE SPD 32 1
#> 5 Norbert Röttgen TRUE TRUE TRUE TRUE TRUE CDU 31 1
#> 6 Torsten Krauel TRUE FALSE FALSE NA FALSE Die Welt NA 0
#> # ℹ 331 more rows
#>
#> ── Ties
#> # A tibble: 11,035 × 4
#> from to weight sign
#> <int> <int> <dbl> <dbl>
#> 1 1 2 -7 -1
#> 2 1 4 -5 -1
#> 3 1 5 -1 -1
#> 4 1 10 -4 -1
#> 5 1 11 -1 -1
#> 6 1 13 -1 -1
#> # ℹ 11,029 more rows
#>
to_linegraph(ison_adolescents)
#> ── # Line graph ────────────────────────────────────────────────────────────────
#> # A labelled, undirected network of 10 nodes and 20 ties
#>
#> ── Nodes
#> # A tibble: 10 × 1
#> label
#> <chr>
#> 1 Betty-Sue
#> 2 Sue-Alice
#> 3 Alice-Jane
#> 4 Sue-Dale
#> 5 Alice-Dale
#> 6 Jane-Dale
#> # ℹ 4 more rows
#>
#> ── Ties
#> # A tibble: 20 × 2
#> from to
#> <int> <int>
#> 1 1 2
#> 2 2 3
#> 3 1 4
#> 4 2 4
#> 5 4 5
#> 6 2 5
#> # ℹ 14 more rows
#>
to_hypergraph(ison_southern_women)
to_simplicial(ison_adolescents)
#> ── # The Adolescent Society ────────────────────────────────────────────────────
#> # A labelled, undirected simplicial complex of 8 adolescents and 6 hyperedges
#> of 2 to 3 nodes
#> # Transformed by projection: maximal cliques as hyperedges
#>
#> ── Nodes
#> # A tibble: 8 × 1
#> label
#> <chr>
#> 1 Betty
#> 2 Sue
#> 3 Alice
#> 4 Jane
#> 5 Dale
#> 6 Pam
#> # ℹ 2 more rows
#>
#> ── Ties
#> # A tibble: 6 × 4
#> from to with label
#> <int> <int> <list> <chr>
#> 1 NA NA <int [2]> h1
#> 2 NA NA <int [2]> h2
#> 3 NA NA <int [2]> h3
#> 4 NA NA <int [3]> h4
#> 5 NA NA <int [3]> h5
#> 6 NA NA <int [3]> h6
#>