View source: R/cluster-metrics.R
| layer_similarity | R Documentation |
Computes similarity between two network layers.
layer_similarity(
A1,
A2,
method = c("jaccard", "overlap", "hamming", "cosine", "pearson")
)
lsim(A1, A2, method = c("jaccard", "overlap", "hamming", "cosine", "pearson"))
A1 |
First adjacency matrix |
A2 |
Second adjacency matrix |
method |
Comparison method: "jaccard" (default), "overlap", "hamming", "cosine" or "pearson" |
"jaccard", "overlap" and "hamming" compare edge
presence (A > 0) and therefore ignore weights;
"cosine" and "pearson" are computed on the raw cell values.
The two matrices must have identical dimensions.
A single numeric value. All methods except "hamming" return a
similarity (higher = more alike); "hamming" returns a
distance - the number of matrix cells whose edge presence differs
between the two layers - so lower means more alike and the value is not
bounded by 1. NA is returned when the denominator is undefined
("jaccard" with no edges in either layer, "overlap" with an
empty layer, "cosine" with an all-zero layer).
A1 <- matrix(c(0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0), 4, 4)
A2 <- matrix(c(0,1,0,0, 1,0,1,0, 0,1,0,1, 0,0,1,0), 4, 4)
layer_similarity(A1, A2, "jaccard") # Edge overlap
layer_similarity(A1, A2, "cosine") # Weight similarity
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.