-
Notifications
You must be signed in to change notification settings - Fork 7
/
member_components.R
66 lines (60 loc) · 2.19 KB
/
member_components.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#' Component partitioning algorithms
#'
#' @description
#' These functions create a vector of nodes' memberships in
#' components or degrees of coreness:
#'
#' - `node_components()` assigns nodes' component membership
#' using edge direction where available.
#' - `node_weak_components()` assigns nodes' component membership
#' ignoring edge direction.
#' - `node_strong_components()` assigns nodes' component membership
#' based on edge direction.
#' - `node_roulette()`
#'
#' In graph theory, components, sometimes called connected components,
#' are induced subgraphs from partitioning the nodes into disjoint sets.
#' All nodes that are members of the same partition as _i_ are reachable
#' from _i_.
#'
#' For directed networks,
#' strongly connected components consist of subgraphs where there are paths
#' in each direction between member nodes.
#' Weakly connected components consist of subgraphs where there is a path
#' in either direction between member nodes.
#'
#' Coreness captures the maximal subgraphs in which each vertex has at least
#' degree _k_, where _k_ is also the order of the subgraph.
#' As described in `igraph::coreness`,
#' a node's coreness is _k_ if it belongs to the _k_-core
#' but not to the (_k_+1)-core.
#' @inheritParams cohesion
#' @name components
#' @family memberships
NULL
#' @rdname components
#' @importFrom igraph components
#' @examples
#' node_components(mpn_bristol)
#' @export
node_components <- function(.data){
if(!manynet::is_graph(.data)) .data <- manynet::as_igraph(.data)
make_node_member(igraph::components(.data, mode = "strong")$membership,
.data)
}
#' @rdname components
#' @importFrom igraph components
#' @export
node_weak_components <- function(.data){
if(!manynet::is_graph(.data)) .data <- manynet::as_igraph(.data)
make_node_member(igraph::components(.data, mode = "weak")$membership,
.data)
}
#' @rdname components
#' @importFrom igraph components
#' @export
node_strong_components <- function(.data){
if(!manynet::is_graph(.data)) .data <- manynet::as_igraph(.data)
make_node_member(igraph::components(.data, mode = "strong")$membership,
.data)
}