similarity: Similarity between the networks at each pair of time points

View source: R/similarity.R

similarityR Documentation

Similarity between the networks at each pair of time points

Description

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

Usage

similarity(
  dn,
  method = c("jaccard", "overlap", "hamming", "cosine", "pearson"),
  sessions = c("bounded", "collapse", "separate"),
  start = NULL,
  end = NULL,
  step = NULL,
  window = NULL,
  plot = FALSE
)

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. Unlike centrality_series(), "separate" adds no session column 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 raises dynet_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, so plot = TRUE saves the wrapping plot() call without changing what comes back. Use plot() 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)
similarity(dn, method = "cosine")

Dynet documentation built on Oct. 7, 2026, 5:08 p.m.