Goodness of Fit

The reviews agree that goodness of fit is the least settled part of relational event modelling: "there exists no general consensus regarding a formal testing paradigm" (Bianchi, Filippi-Mazzola, Lomi & Wit 2024). The literature offers three families of proposals. Revel implements all three, because they answer different questions.

QuestionToolAfter
How highly did the model rank what happened?event_diagnostics, prediction_summaryButts 2008; Meijerink-Bosman et al. 2023
Does the model hold over the whole sequence?score_process_testBoschi & Wit 2026; Lin, Wei & Ying 1993
Is an effect missing?score_testRao's score test
Does the model reproduce the sequence?gofafter Amati, Lomi & Snijders 2024
How fast does a mechanism operate?closing_times, mechanism_sharesafter Amati et al. 2024
Can the statistics be told apart?statistic_collinearity—
using Revel, Random

truth = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
events = simulate_events(truth, [1.0, 1.0], 6, 400; rng=Xoshiro(1))
fit = fit_revel(events, truth, 6)
small = fit_revel(events, truth[1:1], 6)       # reciprocity left out
Revel relational event model
  model:     ordinal (event order)
  events:    400, directed
  actors:    6
  risk set:  full
  estimator: Revel.fit_obpm (full risk set, streamed)

Ordinal relational event model (full risk set)
==============================================
N actors: 6
N events: 400
Log-likelihood: -400.5657
Converged: true

                Estimate  Std.Error  z value  Pr(>|z|)
log1p(inertia)    1.9809     0.1196  16.5575    <1e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Prediction

Each event is scored by the probability the model gave it and by its rank among the dyads that could have acted:

diagnostics = event_diagnostics(fit)
first(diagnostics, 3)
3×14 DataFrame
Rowevent_indextimesenderreceiverrisk_set_sizeprobabilityrankn_aboven_tiedreciprocal_rankrank_fractiondeviance_residualnull_residualsurprise
Int64Float64Int64Int64Int64Float64Float64Int64Int64Float64Float64Float64Float64Float64
111.014300.033333315.50300.1331660.56.802396.802394.90689
222.031300.030917816.52280.08910670.5344836.952856.802395.01542
333.046300.028828717.54260.07352510.5689667.092776.802395.11635

deviance_residual is the deviance residual of Butts (2008) and Butts & Marcum (2017); read against the sequence, the large ones show where a specification fails. The summary:

s = prediction_summary(fit; ks=(1, 5, 0.1))
s.recall         # share of events in the model's top 1 and top 5 dyads, and top 10 %
s.pseudo_r2      # share of the null deviance accounted for
s.perplexity     # effective number of equally likely dyads left
2.6162816568570606

An integer k is a number of dyads and a fraction is a share of the risk set: the default ks=(1, 5, 10) are ranks, and 0.05 is the top-5 % recall of Meijerink-Bosman et al. (2023) and the remstats tutorials. Here the risk set has 30 dyads, so the top 10 % is 3 of them — fewer than the top 5, which is why that recall is the lower. Dyads the model rates equal to the observed one are credited as a random breaking of the tie would credit them, so early events, tied with the whole risk set, count k/D and not zero.

In-sample prediction rewards every added term. For a comparison between specifications, hold events out; each held-out event is then predicted one step ahead, from the true history before it:

train_full = fit_revel(events, truth, 6; cases=1:300)
train_small = fit_revel(events, truth[1:1], 6; cases=1:300)
prediction_summary(train_full; cases=301:400).deviance <
    prediction_summary(train_small; cases=301:400).deviance     # true
true

Score processes

The score of a relational event model is a sum over events of observed statistic minus its expectation under the fitted model. Accumulated along the sequence it is a process that, under a correctly specified model, wanders around zero and returns to it. A coefficient that strengthens or fades makes it drift.

score_process_test(fit; n_sim=500, rng=Xoshiro(2))
3×5 DataFrame
Rowtermstatisticp_valuep_kolmogorovat_event
StringFloat64Float64Float64Int64
1log1p(inertia)0.9771290.1956090.29532785
2log1p(reciprocity)0.6539040.574850.78594238
3GLOBAL0.9771290.2634730.59065485

p_value compares the supremum of the standardised process with its null distribution, generated by the multiplier resampling of Lin, Wei & Ying (1993), which accounts for the coefficients being estimated; read it. p_kolmogorov refers the same statistic to a Brownian bridge, which holds only when information accrues at a constant rate along the sequence — it does not for cumulative statistics — so it is a rough guide. The GLOBAL row is the largest standardised supremum, with its p-value from the same resampling of the maximum, so it accounts for the correlation between the effects.

The rows are indexed by effect but are not an attribution: the statistics are correlated, so drift in one effect — or an omitted effect, or a wrong memory kernel — makes the rows of correlated effects reject too. Read a rejection as "this specification is not adequate over the sequence", and at_event as where it drifts, not why. An effect that switches on half-way through is detected, and the supremum falls near the change:

late = GlobalEffect(t -> t > 200 ? 1.0 : 0.0; name="late")
shifting = [Inertia(transform=:log1p),
            Interaction(late, Inertia(transform=:log1p); name="late_inertia")]
changing = simulate_events(shifting, [0.0, 2.0], 6, 400; rng=Xoshiro(3))
drift = score_process_test(fit_revel(changing, shifting[1:1], 6); n_sim=500, rng=Xoshiro(4))
drift.p_value[1], drift.at_event[1]
(0.001996007984031936, 196)

return_process=true also returns the processes for plotting. The follow-ups are fit_moving_window, which shows how each coefficient moves, and score_test, which asks whether an effect is missing.

Score tests for omitted effects

Would adding an effect improve the fit? The score test answers from the fitted model alone — no refit — so a whole list of candidates can be screened in one pass over the risk sets:

score_test(small, [Reciprocation(transform=:log1p), OTP(transform=:log1p),
                   ISP(transform=:log1p), RecencyRank(:send)])
4×7 DataFrame
Rowtermscorevariancechisqp_valuedirectionresidual_share
StringFloat64Float64Float64Float64Int64Float64
1log1p(reciprocity)22.605716.06431.81151.69888e-810.205896
2log1p(otp)-6.3255245.30370.8831980.347327-10.983043
3log1p(isp)0.1313944.439020.003889220.95027310.999086
4rrankSend-3.421174.775982.450680.117474-10.599954

This applies the literature's hierarchy principle: fit the lower-order terms, then ask whether a triadic term still has something to explain. It does not settle the question — Juozaitienė & Wit (2024) show that "ghost" triadic effects can survive next to degree terms when actor heterogeneity is not modelled, and the package has no random effects. Candidates are tested one at a time; screening many calls for a multiplicity correction. residual_share says how much of a candidate's information the fitted effects leave; a candidate they span to working precision gets NaN.

Simulation

gof(small; n_sim=100, rng=Xoshiro(5))
Goodness-of-fit assessment: relational event model (ordinal)
============================================================
Based on 100 simulated networks
Overall p-value: 0.0495

Goodness-of-fit for mechanism shares

                  Obs  2.5%  Mean  97.5%  MC p-value
repetition      0.955  0.96  0.97   0.98      0.0396
reciprocation  0.9675  0.00  0.37   0.97      0.1188
transitive     0.9175  0.00  0.34   0.95      0.2970
cyclic           0.93  0.00  0.39   0.96      0.4356
shared_out     0.8825  0.00  0.33   0.95      0.6139
shared_in      0.9425  0.00  0.36   0.96      0.2178

Goodness-of-fit for degree concentration

                              Obs  2.5%  Mean  97.5%  MC p-value
gini(outdegree)          0.640833  0.64  0.77   0.82      0.0990
gini(indegree)           0.636667  0.63  0.78   0.82      0.0792
distinct dyads / events     0.045  0.01  0.03   0.04      0.0396

Goodness-of-fit for closing times (events)

                   Obs  2.5%    Mean   97.5%  MC p-value
reciprocation q25    1  3.36   68.99  400.00      0.0396
reciprocation q50    2  6.21  106.78  400.00      0.0396
reciprocation q75    3  8.00  151.70  400.00      0.0198
repetition q25       1  1.00    1.00    1.00      1.0000
repetition q50       1  1.00    1.03    1.76      1.0000
repetition q75       3  1.00    1.24    3.52      0.1386

gof simulates sequences from the fitted model and compares auxiliary statistics of the observed sequence with their simulated distribution, in the ecosystem's shared GOFResult (whose printout says "networks"; here they are event sequences). An ordinal fit is simulated conditional on the observed event times, so a memory kernel in clock units keeps its meaning.

The default auxiliary statistics are the shares of events closing six configurations, the concentration of activity and popularity, and the quartiles of the closing times of reciprocation and repetition (a simulated sequence in which nothing closes is censored at its length, as "slower than anything observed"). Read the overall p-value first: it is the Monte-Carlo p-value of the Mahalanobis distance of all fifteen statistics together, the one joint test. The per-statistic p-values are pointwise, so a few small ones among fifteen are expected by chance.

In the example the model without reciprocity is rejected overall (p ≈ 0.05), and the statistics that give it away are the reciprocation closing times — the data answer within two or three events, the simulations take a hundred. The mechanism shares say little here: with six actors and four hundred events almost every event closes some configuration, and simulations from the misspecified model lock into a few dyads, so the envelopes run from 0 to 1.

By default gof is a plug-in check: it simulates from the estimates without refitting them, so for auxiliaries close to what the model's statistics fix, the observed value sits near the centre by construction. Its p-values are conservative and its power against a specific omission is low — score_test found the missing reciprocity with p far below 0.001 on the same data.

refit=true removes the conservatism. Every simulated sequence is treated as the observed one was: the model is refitted to it, n_inner sequences are simulated from the refit, and the sequence's auxiliaries are taken as residuals from their mean — as the observed auxiliaries are from the mean under the observed fit. On true models the per-statistic p-values then reject 3–5 % of the time at the 5 % level and p_overall 3–6 %, against 1–2 % for the plug-in check. It costs n_sim refits and (n_sim + 1) × n_inner further simulations, run on the available threads; the result depends on rng only.

calibrated = gof(small; n_sim=40, refit=true, n_inner=10, rng=Xoshiro(5))
calibrated.p_overall
0.07317073170731707

Use gof for what the model was not built to reproduce. Supply your own auxiliaries:

busiest = ("busiest sender", ["share of events"],
           ev -> [maximum(count(e -> e.sender == a, ev) for a in 1:6) / length(ev)])
gof(fit; n_sim=50, rng=Xoshiro(6), auxiliary=[busiest])
Goodness-of-fit assessment: relational event model (ordinal)
============================================================
Based on 50 simulated networks
Overall p-value: 0.3137

Goodness-of-fit for busiest sender

                 Obs  2.5%  Mean  97.5%  MC p-value
share of events  0.5  0.36  0.47   0.51      0.4314

How fast a mechanism operates

A closure effect that operates within minutes and one that operates over months are different mechanisms, and the statistic alone does not tell them apart.

using Statistics

mechanism_shares(events)
quantile(closing_times(events; mechanism=:reciprocation), [0.25, 0.5, 0.75])
quantile(closing_times(events; mechanism=:transitive, clock=:order), [0.25, 0.5, 0.75])
3-element Vector{Float64}:
  54.5
 146.0
 235.5

Looked at before fitting, the closing times also suggest a memory kernel.

Collinearity

Endogenous statistics are built from the same history and overlap by construction — inertia is part of out-degree, the four triadic statistics share their legs, a product contains its parts. None of the reviews offers a diagnostic. statistic_collinearity measures the overlap the way the likelihood sees it, within risk sets:

check = statistic_collinearity(events, [Inertia(), OutdegreeSender(), OTP(), ITP()], 6)
check.vif
check.condition_number
2.7074110963665707

What each tool cannot do

  • The prediction measures are relative: they compare specifications, and say nothing about whether the best of them is adequate.
  • The score-process and score tests are defined for converged ordinal fits whose risk sets were enumerated (any riskset, cases or directed), not for timing fits or fits with sampled controls. They assume the fitted effects are the right ones apart from the departure tested.
  • Simulation-based fit depends on the auxiliary statistics chosen, and is not available for a fit on a subset of cases, a time-varying risk set or riskset=:receiver. An interval-timing fit is simulated from its t0 and conditional on the number of events.
  • Amati, Lomi & Snijders (2024) define internal times that consume an antecedent once it is closed, use their deciles, and test each set of statistics with a Mahalanobis distance; closing_times and gof follow the idea, not those definitions.
  • None of them detects unobserved actor heterogeneity, which the package cannot model (no random effects).