View source: R/link_prediction.R
| predict_links | R Documentation |
Computes link prediction scores for all node pairs using one or more
structural similarity methods. Accepts netobject, mcml,
cograph_network, or a raw weight matrix.
All methods are fully vectorized using matrix operations — no loops. Supports both weighted and binary adjacency, directed and undirected networks.
predict_links(
x,
methods = c("common_neighbors", "resource_allocation", "adamic_adar", "jaccard",
"preferential_attachment", "katz"),
weighted = TRUE,
top_n = NULL,
exclude_existing = TRUE,
include_self = FALSE,
katz_damping = NULL
)
x |
A |
methods |
Character vector. One or more of:
|
weighted |
Logical. If |
top_n |
Integer or NULL. Return only the top N predictions per method.
Default: |
exclude_existing |
Logical. If |
include_self |
Logical. If |
katz_damping |
Numeric or NULL. Attenuation factor for Katz index.
If NULL, auto-computed as |
Number of shared neighbors. For directed graphs,
sums shared out-neighbors and shared in-neighbors.
Vectorized as A %*% t(A) + t(A) %*% A.
Zhou et al. (2009). Like common neighbors but
weights each shared neighbor z by 1/degree(z).
Penalizes hubs, rewards rare shared connections.
Adamic & Adar (2003). Like resource allocation but
weights by 1/log(degree(z)). Less aggressive penalty than RA.
Ratio of shared neighbors to total neighbors. For directed graphs, computed on combined (out+in) neighbor sets.
Product of source out-degree and target in-degree. Captures the "rich-get-richer" effect.
Katz (1953). Weighted sum of all paths between nodes,
exponentially damped by path length. Computed via matrix inversion:
(I - beta * A)^{-1} - I. Captures global structure.
An object of class "net_link_prediction" containing:
Data frame with columns: from, to, method, score, rank. Sorted by score (descending) within each method.
Named list of score matrices (one per method).
Character vector of methods used.
Character vector of node names.
Logical.
Logical.
Integer.
Integer. Number of existing edges.
Liben-Nowell, D. & Kleinberg, J. (2007). The link-prediction problem for social networks. JASIST, 58(7), 1019–1031.
Zhou, T., Lu, L. & Zhang, Y.-C. (2009). Network topology and link prediction. European Physical Journal B, 71, 623–630.
Adamic, L. A. & Adar, E. (2003). Friends and neighbors on the Web. Social Networks, 25(3), 211–230.
Katz, L. (1953). A new status index derived from sociometric analysis. Psychometrika, 18(1), 39–43.
evaluate_links for prediction evaluation,
build_network for network estimation.
seqs <- data.frame(
V1 = sample(LETTERS[1:5], 50, TRUE),
V2 = sample(LETTERS[1:5], 50, TRUE),
V3 = sample(LETTERS[1:5], 50, TRUE)
)
net <- build_network(seqs, method = "relative")
pred <- predict_links(net)
print(pred)
summary(pred)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.