Compares the edge set at every time bin with the edge set at every other,
giving the pairwise similarity matrix as a tidy frame. This answers how
much the network at one moment resembles the network at another, which no
single-bin measure reports and which the formation and dissolution
quantities in events() only address between neighbouring bins.
Coefficients are computed by cograph::layer_similarity().
Arguments
- dn
A temporal network from
dynet().- method
One of
"jaccard"(the default),"overlap","hamming","cosine"or"pearson".- sessions
How to treat sessions when the layers are built:
"bounded"(the default) and"collapse"differ in whether a session wall gates a tie into its bin. Unlikecentrality_series(),"separate"adds nosessioncolumn here: layers are keyed on time alone, so two session-local bins sharing a time are compared as one layer.- start, end
First and last time to measure. Default to the observed range.
- step
How often to measure. Defaults to the interval the network was built with.
- window
How much time each measurement covers. Defaults to
step.window = "all"measures the whole observed period as a single bin and so leaves nothing to compare; it raisesdynet_empty_result, as does any other grid that yields fewer than two bins.- plot
Whether to draw the result as well as return it. Drawing is a side effect in the manner of
graphics::hist(): the verb still returns its tidy table, invisibly when it has drawn, soplot = TRUEsaves the wrappingplot()call without changing what comes back. Useplot()on the result when the figure needs arguments of its own.
Value
A dynet_similarity data frame with one row per ordered pair of
time bins and columns time, other, measure and value. Every bin
of the grid takes part, including a bin in which no tie is active. The
diagonal is included and is one for every coefficient except
"hamming", where identical layers differ in nothing and score zero.
"pearson" reaches one only to floating-point accuracy, so compare it
with a tolerance rather than with ==. The frame is returned invisibly
when plot = TRUE has drawn the figure.
A bin with no tie has an empty edge set, and the ratios are then 0/0:
"jaccard" is NA between two empty bins (and 0 between an empty and a
non-empty one), while "overlap", "cosine" and "pearson" are NA
wherever an empty bin takes part, its own diagonal cell included.
"pearson" is likewise NA for a complete layer, which has no variance.
"hamming" is always defined.
Details
Each bin is read as the vector of its eligible pairs: every ordered pair of
distinct vertices for a directed network, every unordered pair for an
undirected one. Loops are excluded, as in turnover() and
persistence(), and a pair is tied in a bin or it is not. On that domain
"hamming" is the number of pairs whose tie state differs, and
"pearson" is the graph correlation of sna::gcor() with its default
diag = FALSE; "hamming" likewise equals sna::hdist(). Counting the
structurally empty diagonal, or both triangles of a symmetric matrix,
would inflate the Hamming count twofold and bias the correlation.
The coefficients come from cograph, which is a hard dependency of Dynet;
a namespace that cannot be loaded raises dynet_needs_cograph.
See also
snapshots() for the networks being compared, events() for
formation and dissolution between neighbouring bins.
Examples
dn <- dynet(school_contacts)
similarity(dn)
#> # jaccard similarity across 22 time bins
#> # off-diagonal mean 0.079, range 0.000 to 0.636
#> time other measure value
#> 1 0 0 jaccard 1.00000000
#> 2 0 1 jaccard 0.28571429
#> 3 0 2 jaccard 0.00000000
#> 4 0 3 jaccard 0.00000000
#> 5 0 4 jaccard 0.00000000
#> 6 0 5 jaccard 0.08333333
#> 7 0 6 jaccard 0.08333333
#> 8 0 7 jaccard 0.03571429
#> 9 0 8 jaccard 0.12000000
#> 10 0 9 jaccard 0.08333333
#> # 474 more rows
similarity(dn, method = "cosine")
#> # cosine similarity across 22 time bins
#> # off-diagonal mean 0.144, range 0.000 to 0.783
#> time other measure value
#> 1 0 0 cosine 1.00000000
#> 2 0 1 cosine 0.44721360
#> 3 0 2 cosine 0.00000000
#> 4 0 3 cosine 0.00000000
#> 5 0 4 cosine 0.00000000
#> 6 0 5 cosine 0.15811388
#> 7 0 6 cosine 0.17616607
#> 8 0 7 cosine 0.07254763
#> 9 0 8 cosine 0.22360680
#> 10 0 9 cosine 0.15811388
#> # 474 more rows