Getting Started

Installation

Revel.jl requires Julia 1.12+ and is not yet registered. It finds its two sibling packages through [sources] paths, so clone them side by side:

git clone https://github.com/statistical-network-analysis-with-Julia/NetworkCore.jl
git clone https://github.com/statistical-network-analysis-with-Julia/REM.jl
git clone https://github.com/statistical-network-analysis-with-Julia/Revel.jl
cd Revel.jl
julia --project -e 'using Pkg; Pkg.instantiate()'

Events

An event is a sender, a receiver and a time, optionally with a type and a weight. Revel re-exports Event from REM.jl. Actors are numbered 1:n, and the clock must be numeric.

using Revel

events = [Event(1, 2, 1.0), Event(2, 1, 2.5), Event(1, 3, 3.0),
          Event(3, 1, 4.2; eventtype=:reply, weight=2.0)]
4-element Vector{Event{Float64}}:
 Event(1 → 2 @ 1.0)
 Event(2 → 1 @ 2.5)
 Event(1 → 3 @ 3.0)
 Event(3 → 1 @ 4.2)

Statistics

A statistic answers one question about a candidate event s → r, given the events that came before it. compute evaluates it against a history at a time t, reading the events of the history at or before t — so one history of a whole sequence can be evaluated at any point of it. The history must be in time order.

history = build_history(events)

compute(Inertia(), history, 1, 2, 5.0)          # past 1 → 2 events: 1.0
compute(Reciprocation(), history, 1, 3, 5.0)    # past 3 → 1 events: 1.0
compute(OutdegreeSender(), history, 1, 2, 5.0)  # events sent by 1: 2.0
compute(OutdegreeSender(), history, 1, 2, 2.0)  # at t = 2 only the first event: 1.0
1.0

The configuration effects (dyad, degree, two-path, three-path) take the same measurement keywords, which select how the past is remembered:

compute(Inertia(memory=HalfLife(1.0)), history, 1, 2, 5.0)   # 0.5^4 = 0.0625
compute(Inertia(memory=Window(2.0)), history, 1, 2, 5.0)     # 0.0 — too long ago
compute(Reciprocation(types=:reply), history, 1, 3, 5.0)     # 1.0
compute(Reciprocation(weighted=true), history, 1, 3, 5.0)    # 2.0
2.0

A first model

Simulate a sequence in which actors repeat themselves and answer one another, and recover the coefficients:

using Random

stats = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
sequence = simulate_events(stats, [0.8, 0.6], 8, 1000; rng=Xoshiro(1))

fit = fit_revel(sequence, stats, 8)
fit
Revel relational event model
  model:     ordinal (event order)
  events:    1000, directed
  actors:    8
  risk set:  full
  estimator: Revel.fit_obpm (full risk set, streamed)

Ordinal relational event model (full risk set)
==============================================
N actors: 8
N events: 1000
Log-likelihood: -2450.0758
Converged: true

                    Estimate  Std.Error  z value  Pr(>|z|)
log1p(inertia)        0.7736     0.0883   8.7619    <1e-16 ***
log1p(reciprocity)    0.6861     0.0879   7.8089   5.8e-15 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

fit_revel returns a RevelFit, which answers the StatsAPI verbs:

coef(fit)
stderror(fit)
confint(fit)
aic(fit), bic(fit)
(4904.151543264126, 4913.967053822091)

and says exactly what was done:

using NetworkCore

NetworkCore.is_exact(fit)          # true — the full risk set, no ties
NetworkCore.fit_metadata(fit)
ResultMetadata
  estimand:       relational_event
  objective:      likelihood (exact for this model)
  standard errors: hessian
  tied events:    none

Checking the model

prediction_summary(fit)                         # how highly were the events ranked?
score_test(fit, [OTP(transform=:log1p)])        # is a closure effect missing?
score_process_test(fit; n_sim=200, rng=Xoshiro(2))   # does the model hold over the sequence?
gof(fit; n_sim=50, rng=Xoshiro(3))              # does it reproduce the sequence?
Goodness-of-fit assessment: relational event model (ordinal)
============================================================
Based on 50 simulated networks
Overall p-value: 0.5294

Goodness-of-fit for mechanism shares

                 Obs  2.5%  Mean  97.5%  MC p-value
repetition     0.948  0.95  0.95   0.96      0.0784
reciprocation  0.954  0.94  0.95   0.96      0.7059
transitive     0.959  0.93  0.96   0.97      0.9412
cyclic         0.968  0.93  0.96   0.97      0.5490
shared_out     0.952  0.93  0.95   0.98      0.4706
shared_in      0.966  0.93  0.96   0.98      0.8235

Goodness-of-fit for degree concentration

                             Obs  2.5%  Mean  97.5%  MC p-value
gini(outdegree)          0.47925  0.22  0.45   0.64      0.9804
gini(indegree)           0.47875  0.22  0.45   0.63      1.0000
distinct dyads / events    0.052  0.04  0.05   0.05      0.0784

Goodness-of-fit for closing times (events)

                     Obs  2.5%   Mean  97.5%  MC p-value
reciprocation q25      2  1.00   2.52   6.00      1.0000
reciprocation q50      4  2.00   6.26  15.32      0.8235
reciprocation q75  19.75  5.00  18.36  37.66      0.9020
repetition q25         2  1.00   2.54   6.00      1.0000
repetition q50         4  2.00   6.24  13.77      0.7843
repetition q75        19  5.00  18.36  37.10      0.9804

Where next