nearest_point: Calculate nearest point in convex hull

Description Usage Arguments Details Value See Also Examples

View source: R/nearest_point.R

Description

Given a citation matrix and a community structure, nearest_point calculates the point in the convex hull of community profiles that is nearest to a given journal profile.

Usage

1
2
3
nearest_point(idx, citations, communities, self = TRUE)

nearest_profile(idx = NULL, citations, communities, self = TRUE)

Arguments

idx

A journal name or index. Vectorised for nearest_profile()

citations

a matrix of citations (from columns to rows) or an igraph object

communities

A membership vector or igraph::communities object

self

logical. Include self-citations? If FALSE, they will not be counted.

Details

This function uses quadratic programming to calculate the closest point by Euclidean distance. The citations matrix should be arranged so that citations are directed from columns to rows. If idx is a name, it should correspond to a row name from citations.

The function nearest_profile is a shorthand way to calculate the profile corresponding to the nearest point.

Value

nearest_point returns the list generated by quadprog::solve.QP().

nearest_profile() returns a stochastic vector whose length is equal to the number of rows/vertices in citations. It is also vectorised, so if idx has length > 1, a matrix will be returned instead.

See Also

quadprog::solve.QP(), community_profile()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
counts <- citations[1:6, 1:6]
comms <- setNames(c(1, 2, 3, 2, 2, 4), colnames(counts))
nearest_point('AoS', counts, comms) # Inside hull (value == 0), because AoS is itself a community.
nearest_point('ANZS', counts, comms) # Outside hull, near to its own community.

# To which cluster should 'Biometrika' belong?
distances <- as.dist(1 - cor(citations + t(citations)))
clusters <- cutree(hclust(distances), h = 0.8)
result <- nearest_point('Bka', citations, clusters)
# Verify Euclidean distance is calculated correctly:
point <- community_profile(citations, clusters) %*% result$solution
result$value %==% sum((citations[, 'Bka'] / sum(citations[, 'Bka']) - point)^2)

Selbosh/scrooge documentation built on May 5, 2019, 8 p.m.