Statistics API Reference
This page documents all statistics available in REM.jl.
Base Types and Interface
Abstract Types
REM.AbstractStatistic — Type
AbstractStatisticAbstract base type for all REM statistics.
All statistics must implement:
compute(stat::AbstractStatistic, state::EventNetworkState, sender::Int, receiver::Int) -> Float64name(stat::AbstractStatistic) -> String
Both are the shared generics of NetworkCore.jl (import REM: compute, name, or import NetworkCore: compute, name, before adding methods — never a local function of the same name). A statistic that reads the state's event log should also say so with needs_history (the default for a foreign statistic is true).
Example
using REM
import REM: compute, name
# "Did the receiver send the previous event?" — reads the state's event log
struct ReplyToLast <: AbstractStatistic end
name(::ReplyToLast) = "reply_to_last"
compute(::ReplyToLast, state::EventNetworkState, s::Int, r::Int) =
isempty(state.event_history) ? 0.0 : Float64(state.event_history[end][1] == r)
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 2.0), Event(1, 3, 3.0)];
actors=ActorSet(1:3))
compute_statistics(seq, [ReplyToLast(), Repetition()]).reply_to_last # [0.0, 1.0, 1.0]REM.DyadStatistic — Type
DyadStatistic <: AbstractStatisticStatistics that depend on the history of events between the focal dyad (sender, receiver). Examples: repetition, reciprocity, inertia.
Example
using REM
Repetition() isa DyadStatistic, Reciprocity() isa DyadStatistic # (true, true)
needs_history(Repetition()) # falseREM.DegreeStatistic — Type
DegreeStatistic <: AbstractStatisticStatistics that depend on the degree (activity/popularity) of actors. Examples: sender activity, receiver popularity.
Example
using REM
SenderActivity() isa DegreeStatistic, LogDegree() isa DegreeStatistic # (true, true)REM.TriangleStatistic — Type
TriangleStatistic <: AbstractStatisticStatistics that measure triadic closure effects. Examples: transitive closure, cyclic closure, shared partners.
Example
using REM
TransitiveClosure() isa TriangleStatistic # true
GeometricWeightedTriads() isa TriangleStatistic # trueREM.FourCycleStatistic — Type
FourCycleStatistic <: AbstractStatisticStatistics that measure four-cycle (local clustering) effects.
Example
using REM
FourCycle() isa FourCycleStatistic, GeometricWeightedFourCycles() isa FourCycleStatisticREM.NodeStatistic — Type
NodeStatistic <: AbstractStatisticStatistics based on node-level attributes. Examples: homophily, attribute matching.
Example
using REM
gender = NodeAttribute(:gender, Dict(1 => "M", 2 => "F"))
AttributeMatch(gender) isa NodeStatistic # trueREM.InteractionStatistic — Type
InteractionStatistic <: AbstractStatisticStatistics that capture interaction effects between attributes. REM ships no concrete subtype; it is the slot for a user-defined product of two attribute effects (needs_history is false for it, as for every REM family).
Example
using REM
import REM: compute, name
struct SameTeamSenior <: InteractionStatistic
team::NodeAttribute{String}
age::NodeAttribute{Float64}
end
name(::SameTeamSenior) = "same_team_senior"
compute(x::SameTeamSenior, ::EventNetworkState, s::Int, r::Int) =
Float64(x.team[s] == x.team[r]) * (x.age[s] - x.age[r])
needs_history(SameTeamSenior(NodeAttribute(:t, "a"), NodeAttribute(:a, 0.0))) # falseInterface Functions
NetworkCore.compute — Function
compute(stat::AbstractStatistic, state::EventNetworkState, sender::Int, receiver::Int) -> Float64Compute the statistic value for a potential event from sender to receiver, read off state as it stands now (before the candidate event). This is the main interface that all statistics must implement — as a method of the shared NetworkCore.compute generic (the same compute ERGM.jl's terms answer to, with a different signature), which is why using ERGM, REM leaves it usable.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 2, 2.0), Event(2, 3, 3.0)];
actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(Repetition(), state, 1, 2) # 2.0
compute(Reciprocity(), state, 2, 1) # 2.0
compute(TransitiveClosure(), state, 1, 3) # 1.0 — min(w(1,2), w(2,3)) = min(2, 1)NetworkCore.name — Function
name(stat::AbstractStatistic) -> StringReturn the statistic's name — the column it gets in the observations frame and the row it gets in the coefficient table. Every REM statistic accepts a name= keyword to override its default (two variants of one statistic in one model need distinct names). A method of the shared NetworkCore.name generic.
Example
using REM
name(Repetition()) # "repetition"
name(Repetition(directed=false)) # "undirected_repetition"
name(TransitiveClosure(name="closure_min")) # "closure_min"REM.needs_history — Function
needs_history(stat::AbstractStatistic) -> BoolWhether stat reads the per-event log state.event_history of an EventNetworkState. generate_observations, compute_statistics and fit_rem build their state with keep_history = any(needs_history, stats), so the O(events) log is retained only when a statistic in the set consumes it.
The default is true — a statistic REM does not know about (one defined in Revel.jl or by a user) is assumed to need the log until it says otherwise — and every statistic REM ships returns false (they read the incremental counts, degrees, last-event times and adjacency). A package whose statistics never touch the log can declare it: REM.needs_history(::MyStat) = false (import REM: needs_history first).
Example
using REM
needs_history(Repetition()) # false — reads the dyad count
needs_history(TransitiveClosure()) # false — reads the adjacency sets
struct LastSenderRepeats <: AbstractStatistic end # reads the log: default true
needs_history(LastSenderRepeats()) # trueStatisticSet
REM.StatisticSet — Type
StatisticSetA collection of statistics to compute together.
Statistics are stored as a tuple so that compute_all compiles to statically dispatched calls per statistic instead of dynamic dispatch through an abstractly-typed vector (which would dominate the observation-generation/likelihood inner loop). Construct from a tuple or a vector of statistics; generate_observations, compute_statistics, and fit_rem convert vectors to a StatisticSet internally.
Example
using REM
ss = StatisticSet([Repetition(), Reciprocity(), TransitiveClosure()])
length(ss), ss.names # (3, ["repetition", "reciprocity", "transitive_closure"])
ss[1] # Repetition()
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute_all(ss, state, 1, 2) # [1.0, 1.0, 0.0]NetworkCore.compute_all — Function
compute_all(ss::StatisticSet, state::EventNetworkState, sender::Int, receiver::Int) -> Vector{Float64}Compute all statistics in the set for a potential event, in the set's order (one fresh Vector{Float64}; see compute_all! for the in-place form). A method of the shared NetworkCore.compute_all generic.
Example
using REM
ss = StatisticSet([Repetition(), Reciprocity()])
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 2.0), Event(1, 2, 3.0)];
actors=ActorSet(1:2))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute_all(ss, state, 1, 2) # [2.0, 1.0]
compute_all([Repetition(), Reciprocity()], state, 2, 1) # [1.0, 2.0] (vector form)compute_all(stats::Vector{<:AbstractStatistic}, state::EventNetworkState, sender::Int, receiver::Int) -> Vector{Float64}Compute all statistics for a potential event.
REM.compute_all! — Function
compute_all!(dest, ss::StatisticSet, state::EventNetworkState, sender::Int, receiver::Int) -> destIn-place version of compute_all for use in sampling loops. The per-statistic calls are unrolled at compile time (a generated function over the tuple), so the loop is statically dispatched and allocation-free for a set of any length — map over a tuple longer than 32 falls back to a generic path that allocates.
Example
using REM
ss = StatisticSet([Repetition(), Reciprocity()])
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 2.0)]; actors=ActorSet(1:2))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
dest = Vector{Float64}(undef, length(ss))
compute_all!(dest, ss, state, 1, 2) # [1.0, 1.0], written into destDyad Statistics
Statistics based on the history of events between the focal sender-receiver pair.
REM.Repetition — Type
Repetition <: DyadStatisticMeasures the tendency for repeated events from sender to receiver. Returns the (weighted) count of past events from sender to receiver.
Fields
directed::Bool: If true, count only events from s→r. If false, count events in both directions.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 2.0), Event(1, 2, 3.0)]; actors=ActorSet(1:2))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(Repetition(), state, 1, 2) # 2.0
compute(Repetition(directed=false), state, 1, 2) # 3.0REM.Reciprocity — Type
Reciprocity <: DyadStatisticMeasures the tendency for reciprocal events. Returns the (weighted) count of past events from receiver to sender.
Fields
stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(2, 1, 1.0), Event(2, 1, 2.0)]; actors=ActorSet(1:2))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(Reciprocity(), state, 1, 2) # 2.0 — two past 2→1 eventsREM.InertiaStatistic — Type
InertiaStatistic <: DyadStatisticMeasures inertia - the tendency for events to persist in a direction. Combines repetition and reciprocity effects.
Returns: repetitionweight * repetition + reciprocityweight * reciprocity
Fields
repetition_weight::Float64: Weight for repetition component.reciprocity_weight::Float64: Weight for reciprocity component.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 2, 2.0), Event(2, 1, 3.0)]; actors=ActorSet(1:2))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(InertiaStatistic(), state, 1, 2) # 2 + 1 = 3.0
compute(InertiaStatistic(reciprocity_weight=0.5), state, 1, 2) # 2 + 0.5 = 2.5REM.RecencyStatistic — Type
RecencyStatistic <: DyadStatisticRecency: how recently the last event occurred on the focal dyad, as a decreasing transform of the elapsed time Δ = current_time − t_last; 0.0 when the dyad has no prior event. Elapsed time is in the clock's units for numeric time and in seconds for Date/DateTime time.
At Δ = 0 — an event tied with the last one on the dyad (ties=:ordered lets a dyad act twice at one timestamp), or a hand-built state read at its last event's time — the transforms differ by design: :exp_decay is well-defined there and returns exp(0) = 1, "just happened" (not 0, "never happened"); :inverse and :inverse_log are singular at 0 and return 0.0, a deliberate cap: an event tied with the last one on the dyad is treated as having no usable recency. Pass transform=:exp_decay if tied same-dyad events are a feature of your data.
RecencyStatistic(; directed=true, transform=:inverse, decay=1.0, name="recency_<transform>")Fields
directed::Bool: If true, the lasts → revent; if false, the last event in either direction betweensandr(the later of the two).transform::Symbol: the transform ofΔ::inverse—1 / Δ:inverse_log—1 / log(1 + Δ)(called:logbefore 0.2.0, which misdescribed it: it is not a log transform, and:logis now refused with a pointer here):exp_decay—exp(−decay · Δ)
decay::Float64: Decay parameter for the:exp_decaytransform.stat_name::String: Name for this statistic.
Unlike the state-level decay/window (which weight every count), this is a statistic of its own: it reads the dyad's last-event time, which no window expires.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 3.0)]; actors=ActorSet(1:2))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
state.current_time = 5.0
compute(RecencyStatistic(), state, 1, 2) # 1 / 4 = 0.25
compute(RecencyStatistic(directed=false), state, 1, 2) # last in either direction: 1 / 2
compute(RecencyStatistic(transform=:inverse_log), state, 1, 2) # 1 / log(5)
compute(RecencyStatistic(transform=:exp_decay, decay=0.5), state, 1, 2) # exp(-2)REM.DyadCovariate — Type
DyadCovariate <: DyadStatisticA statistic based on a pre-specified dyad-level covariate matrix.
Fields
values::Dict{Tuple{Int,Int}, Float64}: Mapping from dyad to covariate value.default::Float64: Default value for dyads not in the dict.stat_name::String: Name for this statistic.
Example
using REM
dist = DyadCovariate(Dict((1, 2) => 10.0, (2, 1) => 12.0); default=100.0, name="distance")
state = EventNetworkState{Float64}()
compute(dist, state, 1, 2) # 10.0
compute(dist, state, 3, 1) # 100.0 (the default)Degree Statistics
Statistics based on actor activity (out-degree) and popularity (in-degree).
REM.SenderActivity — Type
SenderActivity <: DegreeStatisticMeasures the sender's past activity (out-degree). Returns the (weighted) number of past events sent by the sender.
Fields
stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 3, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(SenderActivity(), state, 1, 3) # 2.0REM.ReceiverActivity — Type
ReceiverActivity <: DegreeStatisticMeasures the receiver's past activity (out-degree). Returns the (weighted) number of past events sent by the receiver.
Fields
stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 3, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(ReceiverActivity(), state, 2, 1) # 2.0 — receiver 1 has sent twiceREM.SenderPopularity — Type
SenderPopularity <: DegreeStatisticMeasures the sender's past popularity (in-degree). Returns the (weighted) number of past events received by the sender.
Fields
stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(2, 1, 1.0), Event(3, 1, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(SenderPopularity(), state, 1, 2) # 2.0 — sender 1 has received twiceREM.ReceiverPopularity — Type
ReceiverPopularity <: DegreeStatisticMeasures the receiver's past popularity (in-degree). Returns the (weighted) number of past events received by the receiver.
Fields
stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(2, 1, 1.0), Event(3, 1, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(ReceiverPopularity(), state, 2, 1) # 2.0REM.TotalDegree — Type
TotalDegree <: DegreeStatisticMeasures the total degree (in + out) of an actor.
Fields
role::Symbol: Which actor's degree to compute (:sender or :receiver).stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(3, 1, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(TotalDegree(role=:sender), state, 1, 2) # 1 out + 1 in = 2.0
compute(TotalDegree(role=:receiver), state, 3, 2) # actor 2: 0 out + 1 in = 1.0REM.DegreeDifference — Type
DegreeDifference <: DegreeStatisticMeasures the difference in degree between sender and receiver.
Fields
degree_type::Symbol: Type of degree to compare (:out, :in, or :total).absolute::Bool: If true, return absolute difference.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 3, 2.0), Event(2, 1, 3.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(DegreeDifference(), state, 1, 2) # out: 2 − 1 = 1.0
compute(DegreeDifference(degree_type=:in), state, 1, 2) # in: 1 − 1 = 0.0
compute(DegreeDifference(degree_type=:total, absolute=true), state, 2, 1) # |2 − 3| = 1.0REM.LogDegree — Type
LogDegree <: DegreeStatisticMeasures the log-transformed degree of an actor. Uses log(1 + degree) to handle zero degrees.
Fields
role::Symbol: Which actor's degree to compute (:sender or :receiver).degree_type::Symbol: Type of degree (:out, :in, or :total).stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 3, 2.0)]; actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(LogDegree(), state, 1, 2) # log(1 + 2) ≈ 1.0986Triangle Statistics
Statistics capturing triadic closure effects in directed networks.
REM.TransitiveClosure — Type
TransitiveClosure <: TriangleStatisticTransitive closure: tendency for s → r when there is a k with s → k → r.
TransitiveClosure(; weighted=true, aggregation=:min, name="transitive_closure")eventnet's definition (the default): Σ_{k ≠ s,r} aggregation(w(s,k), w(k,r)), with w the decayed, event-weighted dyad counts. weighted=false returns the number of distinct k with s → k and k → r ever observed.
Fields
weighted::Bool(defaulttrue): eventnet's weighted form — sum over the closing third partieskofaggregationapplied to the two dyad weights of the two-path (decayed counts, event weights included).falsecounts the distinct third parties instead (adjacency only; the pre-0.2 definition).aggregation::Symbol(default:min)::min,:max,:sumor:product. Ignored whenweighted = false.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(1, 2, 2.0), Event(2, 3, 3.0)];
actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(TransitiveClosure(), state, 1, 3) # min(2, 1) = 1.0
compute(TransitiveClosure(aggregation=:sum), state, 1, 3) # 2 + 1 = 3.0
compute(TransitiveClosure(weighted=false), state, 1, 3) # one third party: 1.0REM.CyclicClosure — Type
CyclicClosure <: TriangleStatisticCyclic closure: tendency for s → r when there is a k with r → k → s.
CyclicClosure(; weighted=true, aggregation=:min, name="cyclic_closure")eventnet's definition (the default): Σ_{k ≠ s,r} aggregation(w(r,k), w(k,s)). weighted=false returns the number of distinct k with r → k and k → s.
Fields
weighted::Bool(defaulttrue): eventnet's weighted form — sum over the closing third partieskofaggregationapplied to the two dyad weights of the two-path (decayed counts, event weights included).falsecounts the distinct third parties instead (adjacency only; the pre-0.2 definition).aggregation::Symbol(default:min)::min,:max,:sumor:product. Ignored whenweighted = false.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(3, 2, 1.0), Event(2, 1, 2.0), Event(2, 1, 3.0)];
actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(CyclicClosure(), state, 1, 3) # 3→2→1 closes 1→3: min(1, 2) = 1.0
compute(CyclicClosure(aggregation=:max), state, 1, 3) # 2.0REM.SharedSender — Type
SharedSender <: TriangleStatisticShared sender: tendency for s → r when there is a k with k → s and k → r (an in-star; eventnet's "shared sender" / two-in-star statistic).
SharedSender(; weighted=true, aggregation=:min, name="shared_sender")eventnet's definition (the default): Σ_{k ≠ s,r} aggregation(w(k,s), w(k,r)). weighted=false returns the number of distinct k who sent to both.
Fields
weighted::Bool(defaulttrue): eventnet's weighted form — sum over the closing third partieskofaggregationapplied to the two dyad weights of the two-path (decayed counts, event weights included).falsecounts the distinct third parties instead (adjacency only; the pre-0.2 definition).aggregation::Symbol(default:min)::min,:max,:sumor:product. Ignored whenweighted = false.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(3, 1, 1.0), Event(3, 2, 2.0), Event(3, 2, 3.0)];
actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(SharedSender(), state, 1, 2) # min(1, 2) = 1.0
compute(SharedSender(aggregation=:product), state, 1, 2) # 2.0REM.SharedReceiver — Type
SharedReceiver <: TriangleStatisticShared receiver: tendency for s → r when there is a k with s → k and r → k (an out-star; eventnet's "shared receiver" / two-out-star statistic).
SharedReceiver(; weighted=true, aggregation=:min, name="shared_receiver")eventnet's definition (the default): Σ_{k ≠ s,r} aggregation(w(s,k), w(r,k)). weighted=false returns the number of distinct k who received from both.
Fields
weighted::Bool(defaulttrue): eventnet's weighted form — sum over the closing third partieskofaggregationapplied to the two dyad weights of the two-path (decayed counts, event weights included).falsecounts the distinct third parties instead (adjacency only; the pre-0.2 definition).aggregation::Symbol(default:min)::min,:max,:sumor:product. Ignored whenweighted = false.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 3, 1.0), Event(2, 3, 2.0), Event(2, 3, 3.0)];
actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(SharedReceiver(), state, 1, 2) # min(1, 2) = 1.0
compute(SharedReceiver(weighted=false), state, 1, 2) # 1.0 (one shared receiver)REM.CommonNeighbors — Type
CommonNeighbors <: TriangleStatisticCommon neighbours regardless of direction: the undirected (SYM) form of the closure statistics — k ∉ {s, r} is a common neighbour when it has had an event with s in either direction and one with r in either direction.
CommonNeighbors(; weighted=true, aggregation=:min, name="common_neighbors")eventnet's weighted form (the default): Σ_k aggregation(u(s,k), u(k,r)) with u the undirected decayed, event-weighted counts (events in either direction added together — what get_undirected_count returns). weighted=false returns the number of distinct common neighbours.
Fields
weighted::Bool(defaulttrue): the weighted form above;falsecounts distinct common neighbours (adjacency only).aggregation::Symbol(default:min)::min,:max,:sumor:product.stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 3, 1.0), Event(3, 1, 2.0), Event(3, 2, 3.0)];
actors=ActorSet(1:3))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(CommonNeighbors(), state, 1, 2) # min(u(1,3) = 2, u(3,2) = 1) = 1.0
compute(CommonNeighbors(aggregation=:sum), state, 1, 2) # 3.0
compute(CommonNeighbors(weighted=false), state, 1, 2) # 1.0REM.GeometricWeightedTriads — Type
GeometricWeightedTriads <: TriangleStatisticGeometrically weighted shared-partner statistic (the relational-event analogue of ERGM's GWESP): with n the number of distinct third parties closing the chosen pattern,
exp(α) · (1 − (1 − exp(−α))^n)so each additional shared partner adds less than the one before (0 for n = 0, 1 for n = 1, 1 + (1 − e^{−α}) for n = 2, ...). n is the count of third parties — the weighted=false value of the corresponding closure statistic — not a weighted sum; use the closure statistics with aggregation= for eventnet's weighted forms.
Fields
closure_type::Symbol::transitive(s→k→r),:cyclic(r→k→s),:shared_sender(k→s, k→r) or:shared_receiver(s→k, r→k).alpha::Float64: Decay parameter (higher = less down-weighting).stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(2, 4, 2.0), Event(1, 3, 3.0), Event(3, 4, 4.0)];
actors=ActorSet(1:4))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
gw = GeometricWeightedTriads(closure_type=:transitive, alpha=0.5)
compute(gw, state, 1, 4) # two two-paths (via 2 and 3): e^0.5 (1 − (1 − e^-0.5)^2) ≈ 1.393Four-Cycle Statistics
Statistics capturing higher-order clustering through four-node structures.
REM.FourCycle — Type
FourCycle <: FourCycleStatisticMeasures four-cycle closure: tendency for s→r when there exist j, k such that s→j, k→j, and k→r (or variants).
FourCycle(; cycle_type=:out_out, weighted=true, aggregation=:min, name="")This captures local clustering where sender and receiver share connections to a common pair of intermediaries. Both intermediaries are distinct from each other and from s and r.
Fields
cycle_type::Symbol: Type of four-cycle configuration.:out_out: s→j←k→r (shared out-neighbor pattern):in_in: s←j→k←r (shared in-neighbor pattern):out_in: s→j→k→r (two-path through intermediaries):in_out: s←j←k←r (reverse chain):mixed: the sum of the four
weighted::Bool(defaulttrue): sum over the closing three-paths(j, k)ofaggregationapplied to the three dyad weights (decayed counts, event weights included).falsecounts the distinct three-paths instead (adjacency only; the pre-0.2 definition).aggregation::Symbol(default:min)::min,:max,:sumor:productover the three weights. Ignored whenweighted = false.stat_name::String: Name for this statistic.
Example
using REM
# s = 1 → j = 2 ← k = 3 → r = 4, with 3→2 observed twice
seq = EventSequence([Event(1, 2, 1.0), Event(3, 2, 2.0), Event(3, 2, 3.0), Event(3, 4, 4.0)];
actors=ActorSet(1:4))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
compute(FourCycle(cycle_type=:out_out), state, 1, 4) # min(1, 2, 1) = 1.0
compute(FourCycle(cycle_type=:out_out, aggregation=:sum), state, 1, 4) # 4.0
compute(FourCycle(cycle_type=:out_out, weighted=false), state, 1, 4) # one three-path: 1.0REM.GeometricWeightedFourCycles — Type
GeometricWeightedFourCycles <: FourCycleStatisticGeometrically weighted four-cycle statistic: with n the number of distinct closing three-paths (the weighted=false value of the corresponding FourCycle),
exp(α) · (1 − (1 − exp(−α))^n)so each additional four-cycle adds less than the one before.
Fields
cycle_type::Symbol: Type of four-cycle configuration (as forFourCycle).alpha::Float64: Decay parameter (higher = less down-weighting).stat_name::String: Name for this statistic.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(3, 2, 2.0), Event(3, 4, 3.0)];
actors=ActorSet(1:4))
state = EventNetworkState(seq)
for e in seq; update!(state, e); end
gw = GeometricWeightedFourCycles(cycle_type=:out_out, alpha=0.5)
compute(gw, state, 1, 4) # one three-path (1→2←3→4): 1.0Node Attribute Statistics
Statistics incorporating actor-level attributes for homophily and covariate effects.
REM.AttributeMatch — Type
AttributeMatch <: NodeStatisticMeasures homophily: tendency for events between actors with matching attributes. Returns 1.0 if sender and receiver have the same attribute value, 0.0 otherwise.
Fields
attribute::NodeAttribute: The attribute to match on.stat_name::String: Name for this statistic.
Example
using REM
gender = NodeAttribute(:gender, Dict(1 => "M", 2 => "M", 3 => "F"))
state = EventNetworkState{Float64}()
compute(AttributeMatch(gender), state, 1, 2) # 1.0
compute(AttributeMatch(gender), state, 1, 3) # 0.0REM.ActorMix — Type
ActorMix <: NodeStatisticMeasures mixing patterns: indicator for specific sender-receiver attribute combinations. Returns 1.0 if sender has value sender_value and receiver has receiver_value.
Not called NodeMix because ERGM.jl exports a different NodeMix (a cross-sectional mixing-matrix term), and two distinct exported types sharing a name leave the binding undefined in any session that loads both packages.
Fields
attribute::NodeAttribute: The attribute to check.sender_value: Required sender attribute value.receiver_value: Required receiver attribute value.stat_name::String: Name for this statistic.
Example
using REM
gender = NodeAttribute(:gender, Dict(1 => "M", 2 => "F"))
state = EventNetworkState{Float64}()
compute(ActorMix(gender, "M", "F"), state, 1, 2) # 1.0
compute(ActorMix(gender, "M", "F"), state, 2, 1) # 0.0REM.NodeDifference — Type
NodeDifference <: NodeStatisticMeasures the difference in a numeric attribute between sender and receiver.
Fields
attribute::NodeAttribute{T}: The numeric attribute.absolute::Bool: If true, return absolute difference.stat_name::String: Name for this statistic.
Example
using REM
age = NodeAttribute(:age, Dict(1 => 25.0, 2 => 30.0))
state = EventNetworkState{Float64}()
compute(NodeDifference(age), state, 1, 2) # -5.0
compute(NodeDifference(age; absolute=true), state, 1, 2) # 5.0REM.NodeSum — Type
NodeSum <: NodeStatisticMeasures the sum of a numeric attribute for sender and receiver.
Fields
attribute::NodeAttribute{T}: The numeric attribute.stat_name::String: Name for this statistic.
Example
using REM
age = NodeAttribute(:age, Dict(1 => 25.0, 2 => 30.0))
compute(NodeSum(age), EventNetworkState{Float64}(), 1, 2) # 55.0REM.NodeProduct — Type
NodeProduct <: NodeStatisticMeasures the product of a numeric attribute for sender and receiver.
Fields
attribute::NodeAttribute{T}: The numeric attribute.stat_name::String: Name for this statistic.
Example
using REM
icr = NodeAttribute(:icr, Dict(1 => 1.0, 2 => 0.0, 3 => 1.0))
compute(NodeProduct(icr), EventNetworkState{Float64}(), 1, 3) # 1.0 (both have it)
compute(NodeProduct(icr), EventNetworkState{Float64}(), 1, 2) # 0.0REM.SenderAttribute — Type
SenderAttribute <: NodeStatisticReturns the sender's attribute value (as a main effect).
Fields
attribute::NodeAttribute{T}: The numeric attribute.stat_name::String: Name for this statistic.
Example
using REM
age = NodeAttribute(:age, Dict(1 => 25.0, 2 => 30.0))
compute(SenderAttribute(age), EventNetworkState{Float64}(), 1, 2) # 25.0REM.ReceiverAttribute — Type
ReceiverAttribute <: NodeStatisticReturns the receiver's attribute value (as a main effect).
Fields
attribute::NodeAttribute{T}: The numeric attribute.stat_name::String: Name for this statistic.
Example
using REM
age = NodeAttribute(:age, Dict(1 => 25.0, 2 => 30.0))
compute(ReceiverAttribute(age), EventNetworkState{Float64}(), 1, 2) # 30.0REM.SenderCategorical — Type
SenderCategorical <: NodeStatisticReturns 1.0 if sender has a specific categorical attribute value.
Fields
attribute::NodeAttribute: The categorical attribute.value: The value to match.stat_name::String: Name for this statistic.
Example
using REM
gender = NodeAttribute(:gender, Dict(1 => "M", 2 => "F"))
compute(SenderCategorical(gender, "M"), EventNetworkState{Float64}(), 1, 2) # 1.0
compute(SenderCategorical(gender, "M"), EventNetworkState{Float64}(), 2, 1) # 0.0REM.ReceiverCategorical — Type
ReceiverCategorical <: NodeStatisticReturns 1.0 if receiver has a specific categorical attribute value.
Fields
attribute::NodeAttribute: The categorical attribute.value: The value to match.stat_name::String: Name for this statistic.
Example
using REM
gender = NodeAttribute(:gender, Dict(1 => "M", 2 => "F"))
compute(ReceiverCategorical(gender, "F"), EventNetworkState{Float64}(), 1, 2) # 1.0Typed Statistics and Time-Varying Covariates
OfType restricts any state-reading statistic to the history of one event type; TimeVaryingCovariate is an exogenous covariate evaluated at the time of the event being explained.
REM.OfType — Type
OfType(stat, eventtype::Symbol; name="<name(stat)>.<eventtype>")stat computed on the events of one event type only: OfType(Repetition(), :fight) is the count of past fights from sender to receiver, whatever else the dyad has done. It wraps any statistic that reads the network state (dyad, degree, triadic and four-cycle statistics, recency), under either memory model.
This is how event types enter a REM.jl model (eventnet's type-filtered attributes; remstats' consider_type): the candidate events of all types compete in one risk set, and typed statistics let the history of each type have its own effect. Fit a multi-type sequence with eventtypes=:pool (every event is a case; untyped statistics count all types) or with cases_of=:fight (only the fights are cases, every event still builds the history) — see fit_rem.
The typed counts live in a sub-state of the EventNetworkState (state.by_type[eventtype]), which fit_rem, generate_observations and compute_statistics create for the types their statistics name; a hand-built state needs EventNetworkState(seq; types=[...]).
Example
using REM
seq = EventSequence([Event(1, 2, 1.0; eventtype=:fight), Event(1, 2, 2.0; eventtype=:help),
Event(2, 1, 3.0; eventtype=:help), Event(1, 2, 4.0; eventtype=:fight)];
actors=ActorSet(1:3))
stats = [OfType(Repetition(), :fight), OfType(Reciprocity(), :help), Repetition()]
df = compute_statistics(seq, stats; eventtypes=:pool)
df[!, "repetition.fight"] # [0.0, 1.0, 0.0, 1.0] — past fights 1→2 (resp. 2→1)
df[!, "reciprocity.help"] # [0.0, 0.0, 1.0, 1.0] — past helps the other way
df.repetition # [0.0, 1.0, 0.0, 2.0] — all types togetherREM.TimeVaryingCovariate — Type
TimeVaryingCovariate(f; name="covariate")An exogenous covariate that changes over time: f(sender, receiver, time) is evaluated for every candidate dyad at the time of the event being explained (the state's clock), and must return a number. A policy that starts at a known date, an actor's rank over time, a dyad's distance that changes when someone moves — anything known from outside the event stream.
f is called once per row of the design, so keep it cheap and allocation-free (index into arrays captured in a let block rather than searching). It must not depend on the events themselves: that is what the endogenous statistics are for.
Example
using REM
seq = EventSequence([Event(1, 2, 1.0), Event(2, 1, 2.0), Event(1, 3, 3.0), Event(3, 1, 4.0)];
actors=ActorSet(1:3))
# actor 1 becomes a coordinator at t = 2.5: its calls count from then on
coordinator = TimeVaryingCovariate((s, r, t) -> s == 1 && t >= 2.5; name="sender_coordinator")
compute_statistics(seq, [coordinator]).sender_coordinator # [0.0, 0.0, 1.0, 0.0]