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. 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.
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