This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
edges = bind_rows( | |
data_frame(i = "A", j = c("A", "B", "C"), w = 2), | |
data_frame(i = "B", j = c("B", "A"), w = 1), | |
data_frame(i = "A", j = c("A", "C"), w = 1), | |
data_frame(i = "B", j = c("B", "C", "D", "E"), w = 3) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first author self-loops, with counts of co-authors | |
self = filter(edges, i == j) | |
# count number of texts per first author | |
n_au = table(self$i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# collapse directed ties | |
edges$ij = apply(edges[, 1:2 ], 1, paste0, collapse = "->") | |
# raw edge counts | |
raw = table(edges$ij) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Newman-Fowler weights | |
edges = aggregate(w ~ ij, function(x) sum(1 / x), data = edges) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# re-expand to edge list | |
edges = data_frame(i = gsub("(.*)->(.*)", "\\1", edges$ij), | |
j = gsub("(.*)->(.*)", "\\2", edges$ij), | |
raw = as.vector(raw[ edges$ij ]), # raw edge counts | |
nfw = edges$w) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gross-Kirkland-Shalizi weights | |
edges = left_join(edges, aggregate(w ~ i, function(x) sum(1 / x), data = self)) | |
edges$gsw = edges$nfw / edges$w |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sanity check | |
stopifnot(edges$gsw >= 0 & edges$gsw <= 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# final edge list: first author, co-author, edge weights | |
edges = select(edges, -w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment