Skip to content

Commit

Permalink
node_brokerage_census() and network_brokerage_census() now treat two-…
Browse files Browse the repository at this point in the history
…mode networks correctly (closed #35)
  • Loading branch information
jhollway committed Jan 25, 2024
1 parent 3346fb1 commit fd7ab47
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

2024-01-24

## Package

- Completed significant documentation updates

## Measures

- `over_*()` now reverts future plan on exit

## Motifs

- `node_brokerage_census()` and `network_brokerage_census()` now treat two-mode networks correctly (closed #35)

## Models

- `test_random()` now reverts future plan on exit
Expand Down
36 changes: 29 additions & 7 deletions R/motif_census.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,29 @@ NULL
#' Gould, R.V. and Fernandez, R.M. 1989.
#' “Structures of Mediation: A Formal Approach to Brokerage in Transaction Networks.”
#' _Sociological Methodology_, 19: 89-126.
#'
#' Jasny, Lorien, and Mark Lubell. 2015.
#' “Two-Mode Brokerage in Policy Networks.”
#' _Social Networks_ 41:36–47.
#' \doi{10.1016/j.socnet.2014.11.005}.
#' @examples
#' node_brokerage_census(manynet::ison_networkers, "Discipline")
#' @export
node_brokerage_census <- function(.data, membership, standardized = FALSE){
out <- sna::brokerage(manynet::as_network(.data),
manynet::node_attribute(.data, membership))
out <- if(standardized) out$z.nli else out$raw.nli
colnames(out) <- c("Coordinator", "Itinerant", "Gatekeeper",
"Representative", "Liaison", "Total")
if(!manynet::is_twomode(.data)){
out <- sna::brokerage(manynet::as_network(.data),
manynet::node_attribute(.data, membership))
out <- if(standardized) out$z.nli else out$raw.nli
colnames(out) <- c("Coordinator", "Itinerant", "Gatekeeper",
"Representative", "Liaison", "Total")

Check warning on line 346 in R/motif_census.R

View check run for this annotation

Codecov / codecov/patch

R/motif_census.R#L341-L346

Added lines #L341 - L346 were not covered by tests
} else {
out <- suppressWarnings(sna::brokerage(manynet::as_network(manynet::to_mode1(.data)),
manynet::node_attribute(.data, membership)))
out <- if(standardized) out$z.nli else out$raw.nli
out <- out[,-4]
colnames(out) <- c("Coordinator", "Itinerant", "Gatekeeper",
"Liaison", "Total")

Check warning on line 353 in R/motif_census.R

View check run for this annotation

Codecov / codecov/patch

R/motif_census.R#L348-L353

Added lines #L348 - L353 were not covered by tests
}
make_node_motif(out, .data)

Check warning on line 355 in R/motif_census.R

View check run for this annotation

Codecov / codecov/patch

R/motif_census.R#L355

Added line #L355 was not covered by tests
}

Expand All @@ -346,10 +360,18 @@ node_brokerage_census <- function(.data, membership, standardized = FALSE){
#' network_brokerage_census(manynet::ison_networkers, "Discipline")
#' @export
network_brokerage_census <- function(.data, membership, standardized = FALSE){
out <- sna::brokerage(manynet::as_network(.data),
if(!manynet::is_twomode(.data)){
out <- sna::brokerage(manynet::as_network(.data),
manynet::node_attribute(.data, membership))
out <- if(standardized) out$z.gli else out$raw.gli
names(out) <- c("Coordinator", "Itinerant", "Gatekeeper",
"Representative", "Liaison", "Total")

Check warning on line 368 in R/motif_census.R

View check run for this annotation

Codecov / codecov/patch

R/motif_census.R#L363-L368

Added lines #L363 - L368 were not covered by tests
make_network_motif(out, .data)
} else {
out <- suppressWarnings(sna::brokerage(manynet::as_network(manynet::to_mode1(.data)),
manynet::node_attribute(.data, membership)))
out <- if(standardized) out$z.gli else out$raw.gli
names(out) <- c("Coordinator", "Itinerant", "Gatekeeper",
"Representative", "Liaison", "Total")

Check warning on line 374 in R/motif_census.R

View check run for this annotation

Codecov / codecov/patch

R/motif_census.R#L370-L374

Added lines #L370 - L374 were not covered by tests
}
make_network_motif(out, .data)

Check warning on line 376 in R/motif_census.R

View check run for this annotation

Codecov / codecov/patch

R/motif_census.R#L376

Added line #L376 was not covered by tests
}
5 changes: 5 additions & 0 deletions man/brokerage_census.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd7ab47

Please sign in to comment.