-
Notifications
You must be signed in to change notification settings - Fork 7
/
measure_hierarchy.R
66 lines (63 loc) · 2.19 KB
/
measure_hierarchy.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
64
65
66
#' Graph theoretic dimensions of hierarchy
#'
#' @description
#' These functions, together with `network_reciprocity()`, are used jointly to
#' measure how hierarchical a network is:
#'
#' - `network_connectedness()` measures the proportion of dyads in the network
#' that are reachable to one another,
#' or the degree to which network is a single component.
#' - `network_efficiency()` measures the Krackhardt efficiency score.
#' - `network_upperbound()` measures the Krackhardt (least) upper bound score.
#'
#' @inheritParams cohesion
#' @name hierarchy
#' @family measures
#' @references
#' Krackhardt, David. 1994.
#' Graph theoretical dimensions of informal organizations.
#' In Carley and Prietula (eds) _Computational Organizational Theory_,
#' Hillsdale, NJ: Lawrence Erlbaum Associates. Pp. 89-111.
#'
#' Everett, Martin, and David Krackhardt. 2012.
#' “A second look at Krackhardt's graph theoretical dimensions of informal organizations.”
#' _Social Networks_, 34: 159-163.
#' \doi{10.1016/j.socnet.2011.10.006}
#' @examples
#' network_connectedness(ison_networkers)
#' 1 - network_reciprocity(ison_networkers)
#' network_efficiency(ison_networkers)
#' network_upperbound(ison_networkers)
NULL
#' @rdname hierarchy
#' @export
network_connectedness <- function(.data){
dists <- igraph::distances(manynet::as_igraph(.data))
make_network_measure(1 - sum(dists==Inf)/sum(dists!=0),
.data)
}
#' @rdname hierarchy
#' @export
network_efficiency <- function(.data) {
degs <- node_indegree(.data, normalized = FALSE)
out <- (manynet::network_nodes(.data)-1)/sum(degs)
make_network_measure(out, .data)
}
#' @rdname hierarchy
#' @export
network_upperbound <- function(.data) {
dists <- igraph::distances(.data, mode = "in")
dists[is.infinite(dists)] <- 0
dists <- dists[order(rowSums(dists)), order(rowSums(dists))]
if (max(colSums(dists > 0)) / (manynet::network_nodes(.data)-1) == 1){
out <- 1
} else {
out <- apply(utils::combn(2:nrow(dists), 2), 2,
function(x){
ubs <- dists[x,]>0
any(ubs[1,]*ubs[2,]==1)
})
out <- sum(out)/length(out)
}
make_network_measure(out, .data)
}