Skip to content

Commit 69acb2a

Browse files
committed
Add new helper function "relations.to.authors'
Create a new helper function to be used by 'metrics.centrality' in order to compute the authors from the data.sources of the network's relations automatically. See se-sic#193
1 parent 8198517 commit 69acb2a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

util-networks-metrics.R

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ metrics.hierarchy = function(network) {
293293

294294

295295
## The column headers for a centrality data frame calculated by the function \code{metrics.centrality}
296-
CENTRALITY_COLUMN_NAMES = c("author.name", "centrality")
296+
CENTRALITY_COLUMN_NAMES = c("name", "centrality")
297297

298298
#' Calculate the centrality value for authors from a network and project data.
299299
#' Only considers authors from the network that are also present in the project data and the
@@ -312,7 +312,10 @@ CENTRALITY_COLUMN_NAMES = c("author.name", "centrality")
312312
#' vector are to be classified. Authors that appear in the vector but are not
313313
#' part of the classification result (i.e., they are not present in the
314314
#' underlying data) will be added to it afterwards (with a centrality value of
315-
#' \code{NA}). \code{NULL} means that no restriction is made. [default: NULL]
315+
#' \code{NA}). \code{NULL} means that the restriction is automatically
316+
#' calculated from the network's edge relations if and only if both network
317+
#' and data are present. In any other case \code{NULL} will not introduce any
318+
#' further restriction. [default: NULL]
316319
#' @return a data.frame with the columns \code{"author.name"} and \code{"centrality"} containing the centrality values
317320
#' for each respective author
318321
metrics.centrality = function(network,
@@ -323,7 +326,18 @@ metrics.centrality = function(network,
323326
restrict.classification.to.authors = NULL) {
324327
type = match.arg(type)
325328

326-
## Calculate the centrality tables
329+
## check whether the restrict parameter is set to default (\code{NULL})
330+
if (is.null(restrict.classification.to.authors)) {
331+
## now check whether both data and network are present
332+
if (!is.null(network) && !is.null(proj.data)) {
333+
## in this case calculate the restrict parameter based on the edge relation
334+
restrict.classification.to.authors = relations.to.authors(proj.data, network)
335+
}
336+
## else leave the parameter at \code{NULL} which still serves as a default value for the
337+
## \code{get.auther.class.by.type} function
338+
}
339+
340+
## calculate the centrality tables
327341
class = get.auther.class.by.type(network = network,
328342
proj.data = proj.data,
329343
type = type,
@@ -335,5 +349,8 @@ metrics.centrality = function(network,
335349
## set column names accordingly
336350
colnames(centrality) = CENTRALITY_COLUMN_NAMES
337351

352+
## order by centrality (desc) (with NA being at the bottom) and then by name (asc)
353+
centrality = centrality[order(-centrality$centrality, centrality$name), ]
354+
338355
return(centrality)
339356
}

0 commit comments

Comments
 (0)