Metrics API Reference

This page documents the duration, persistence, and aggregation functions in TSNA.jl.

Duration Metrics

TSNA.t_edge_duration — Function
t_edge_duration(dnet::DynamicNetwork; mode=:total, aggregate=:all,
                active_default=true, missing=:error)

Edge activity durations, after tsna::edgeDuration. With the defaults this is tsna::edgeDuration(nd): a vector with the total active time of each edge.

Each edge's spells are merged (adjacent or overlapping spells are one lifetime). With an observation window (get_observation_period) they are clipped to it, so an open-ended spell contributes the time up to the window end, and edges with no spell overlapping the window are left out. Without a window nothing is clipped, as in tsna: an open-ended spell, and an edge with no spell record, last Inf. An edge with no spell record is active throughout when active_default=true (R's default).

  • mode=:total (tsna subject = "edges"): one entry per edge, the sum of its clipped spell durations; edges in the order of edges(dnet.network).
  • mode=:spell (tsna subject = "spells"): one entry per merged, clipped spell, by edge then onset.

aggregate is :all (the vector, default), :mean, :median or :total. The durations are observed, not corrected for censoring: a spell cut by the window end is right-censored, so the mean of a sample with open spells underestimates the mean tie lifetime (no Kaplan–Meier estimator is offered). On Date/DateTime axes durations are in seconds; an unbounded duration is Inf on every axis.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
activate!(dnet, 5.0, 8.0; edge=(1, 2))      # adjacent: one lifetime [0, 8)
activate!(dnet, 2.0, Inf; edge=(2, 3))      # open-ended: clipped at 10
t_edge_duration(dnet)                       # [8.0, 8.0]
t_edge_duration(dnet; aggregate=:mean)      # 8.0
nowin = DynamicNetwork(3)                   # no window: nothing is clipped
activate!(nowin, 2.0, 6.0; edge=(1, 2))
activate!(nowin, 6.0, Inf; edge=(2, 3))
t_edge_duration(nowin)                      # [4.0, Inf], as tsna::edgeDuration
source
TSNA.t_vertex_duration — Function
t_vertex_duration(dnet::DynamicNetwork; mode=:total, aggregate=:all,
                  active_default=true, missing=:error)

Vertex activity durations, after tsna::vertexDuration (see t_edge_duration for the merging, clipping and keyword conventions): with the defaults, one entry per vertex active in the window, the total time it is active there (vertices in ID order; a vertex with no spell record is active throughout). mode=:spell gives one entry per merged, clipped spell. Without a window nothing is clipped, and open spells last Inf, as in tsna.

With a window, finite spells are clipped to it as edge spells are; tsna's vertexDuration replaces only infinite bounds by the window and keeps finite spells that reach outside it, so the two differ for such vertices.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 1.0, Inf; vertex=1)
deactivate!(dnet, -Inf, Inf; vertex=3)      # never present
t_vertex_duration(dnet)                     # [9.0, 10.0]
source

Formation and Dissolution Events

TSNA.t_edge_formation — Function
t_edge_formation(dnet::DynamicNetwork, onset, terminus; include_censored=false,
                 missing=:error) -> Int

The number of edge formation events — onsets of merged edge spells — in [onset, terminus). Spells are merged per edge first (a tie active over two adjacent waves forms once) and clipped to the observation window, if one is set; an onset that is left-censored (stored onset_censored, before the window start, or -Inf) is not a formation unless include_censored=true, as in tsna's include.censored = FALSE. Without a window, as in tsna, only an infinite onset is censored, and with include_censored=true it sits at -Inf, outside any finite query.

tsna::tEdgeFormation(nd, start, end, time.interval) returns the series of counts at each t in seq(start, end, time.interval) of onsets equal to t; on integer-valued spells that is [t_edge_formation(dnet, t, t + 1) for t in start:end]. Its default range, the closed range of the change times, is what t_turnover covers on a network without a window.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=20.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
activate!(dnet, 5.0, 9.0; edge=(1, 2))     # persists: no new formation
activate!(dnet, 12.0, 15.0; edge=(1, 2))   # re-forms
add_spell!(dnet, Spell(0.0, 3.0; onset_censored=true); edge=(2, 3))
t_edge_formation(dnet, 0.0, 20.0)                          # 2
t_edge_formation(dnet, 0.0, 20.0; include_censored=true)   # 3
source
TSNA.t_edge_dissolution — Function
t_edge_dissolution(dnet::DynamicNetwork, onset, terminus; include_censored=false,
                   missing=:error) -> Int

The number of edge dissolution events — termini of merged edge spells — in [onset, terminus), with the conventions of t_edge_formation: a right-censored terminus (stored terminus_censored, after the window end, or Inf) is not a dissolution unless include_censored=true.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=20.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
activate!(dnet, 5.0, 9.0; edge=(1, 2))     # one lifetime [0, 9)
activate!(dnet, 4.0, Inf; edge=(2, 3))     # still active at the window end
t_edge_dissolution(dnet, 0.0, 20.0)        # 1
source

Persistence and Turnover

TSNA.t_edge_persistence — Function
t_edge_persistence(dnet::DynamicNetwork, window_size; missing=:error) -> Float64

Proportion of edges that persist (survive) across consecutive time windows, after the temporal-correlation measure of Nicosia et al.: the observation period is divided into windows of length window_size; for each consecutive pair of windows the edges active at the start of the first window are checked for activity at the start of the second, and the pooled proportion persisted / total is returned.

Values near 1 indicate a stable network (little edge turnover); values near 0 indicate almost complete edge replacement per window. Returns NaN when there are fewer than two windows or no active edges to track. Not a tsna function. Without an observation window the windows start at every window_size step of the closed range [first, last] of the change times (see t_turnover).

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=30.0)
activate!(dnet, 0.0, 30.0; edge=(1, 2))
activate!(dnet, 0.0, 15.0; edge=(2, 3))
t_edge_persistence(dnet, 10.0)      # 0.75: 2/2 then 1/2 survive
source
TSNA.t_turnover — Function
t_turnover(dnet::DynamicNetwork, window_size; include_censored=false, missing=:error)
    -> Vector{NamedTuple}

Formation and dissolution event counts and rates per window of length window_size across the observation period, with the event conventions of t_edge_formation/t_edge_dissolution (spells merged per edge, censored bounds not counted). Every element has the same shape: (window_start, window_end, n_formations, n_dissolutions, formation_rate, dissolution_rate), with rates per unit time (per second on calendar axes).

With an observation window the windows tile [start, end), the last one cut at the window end. Without one they start at first, first + window_size, … up to and including the last change time — the closed range of get_change_times that tsna::tEdgeFormation(nd) and tEdgeDissolution(nd) cover by default — so events at the last change time are counted. Without a window, window_size = 1 on integer-valued spells gives tsna's default series. (With a window the counts per window agree with tsna's, but tsna's default grid is still the range of the change times, not the window.) A network with neither a window nor a finite change time raises an ArgumentError.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=20.0)
activate!(dnet, 2.0, 12.0; edge=(1, 2))
activate!(dnet, 5.0, 8.0; edge=(2, 3))
w = t_turnover(dnet, 10.0)
[(x.n_formations, x.n_dissolutions) for x in w]   # [(2, 1), (0, 1)]
source
TSNA.tie_decay — Function
tie_decay(dnet::DynamicNetwork; method=:exponential, rate=1.0, at=nothing,
          missing=:error) -> Dict

Tie weights decayed by the time since each edge was last active at at (by default the window end, or the last change time when no window is set): exp(-rate·Δ) (:exponential) or max(0, 1 - rate·Δ) (:linear), where Δ is the time from the end of the edge's most recent spell to at (0 for currently active ties, including edges with no spell record, which are active by default). Edges whose activity lies entirely after at get no weight. Not a tsna function.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 5.0; edge=(2, 3))
w = tie_decay(dnet; rate=0.1)
w[(1, 2)], round(w[(2, 3)]; digits=3)   # (1.0, 0.607)
source
TSNA.tied_duration — Function
tied_duration(dnet::DynamicNetwork; mode=:duration, neighborhood=:out,
              active_default=true, missing=:error) -> Vector{Float64}

For each vertex, the total time its ties are active in the observation window (mode=:duration) or the number of its tie spells there (mode=:counts): tsna::tiedDuration. neighborhood is :out (ties the vertex sends, the default), :in or :combined; undirected networks always use :combined. Edge spells are merged and clipped to the window as in t_edge_duration; vertices with no ties score 0.

Without a window, tsna's tiedDuration clips to the range [first, last] of the change times (get_change_times), so a tie still active after the last change time counts only up to it, and a spell that starts at the last change time does not count. TSNA does the same. A network with no finite change time at all raises an ArgumentError (tsna would use the placeholder range (0, 1)); set a window with set_observation_period! to choose the range.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 4.0; edge=(1, 2))
activate!(dnet, 2.0, Inf; edge=(1, 3))
tied_duration(dnet)                            # [12.0, 0.0, 0.0]
tied_duration(dnet; neighborhood=:in)          # [0.0, 4.0, 8.0]
source
TSNA.t_edge_density — Function
t_edge_density(dnet::DynamicNetwork; mode=:duration, agg_unit=:edge,
               active_default=true, missing=:error) -> Float64

tsna::tEdgeDensity over the observation window of length L:

  • mode=:duration, agg_unit=:edge (default): the fraction of the time the edges of the base network are active, Σ durations / (n_edges · L).
  • mode=:duration, agg_unit=:dyad: the same total divided by the number of dyads times L — the time-averaged density. The dyads are those of the base network, as R's network.dyadcount counts them: n(n−1) directed and n(n−1)/2 undirected, plus n when the network allows loops; n₁·n₂ on a two-mode network (2n₁n₂ if it is directed).
  • mode=:event, agg_unit=:edge: the number of edge spells per edge per unit time, n_spells / (n_edges · L). (tsna 0.3.6 computes n_spells / (n_edges · end − start), which is this value only when the window starts at 0; the intended formula is used here.)

Without a window, L and the clipping range are those of tsna's tEdgeDensity: the range [first, last] of the change times. A network with no finite change time raises an ArgumentError (tsna would divide by the placeholder range (0, 1)). A range of length zero gives NaN, as in tsna, and an infinite window raises an ArgumentError.

Returns 0 for a network with no edges, as tsna does. mode=:event with agg_unit=:dyad is not implemented in tsna either and is refused. Under missing=:face the masked dyads count as observed (R's network.dyadcount would subtract the missing edges).

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(2, 3))
t_edge_density(dnet)                           # 0.75
t_edge_density(dnet; agg_unit=:dyad)           # 0.25
source

Aggregation

TSNA.t_aggregate — Function
t_aggregate(dnet::DynamicNetwork; method=:union, onset=window start,
            terminus=window end, report=false) -> Network

Collapse the dynamic network into a static one over [onset, terminus), by default the observation window. Without a window, and with neither onset nor terminus given, the whole time axis is collapsed (R's network.collapse default), and :weighted gives an open spell the weight Inf.

  • :union — edges active at some point in the window
  • :intersection — edges active throughout the window
  • :weighted — union, with each edge's total active time in the window (its spells merged and clipped) stored as its :weight attribute

This is DynamicNetworks.network_collapse (R's network.collapse, which needs the endpoints to be active too) with an aggregation rule, and it inherits its conversion invariants: vertex IDs are stable, so directedness, loops, two-mode metadata, static attributes and the missing-dyad mask all survive; spells, time-varying attributes and the observation window are dropped by nature. Pass report=true for (net, ::NetworkCore.ConversionReport).

Example

using TSNA, DynamicNetworks, NetworkCore
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 2.0, 6.0; edge=(2, 3))
ne(t_aggregate(dnet)), ne(t_aggregate(dnet; method=:intersection))   # (2, 1)
get_edge_attribute(t_aggregate(dnet; method=:weighted), :weight, 2, 3)   # 4.0
source