Diagnostics API Reference

Prediction

Revel.event_diagnostics — Function
event_diagnostics(fit::RevelFit; cases=fit.cases) -> DataFrame

How the fitted model scored each event: one row per event with

  • event_index, time, sender, receiver, risk_set_size;
  • probability — the fitted probability of the observed dyad among its risk set;
  • rank — its rank by fitted rate (1 = the model's first choice; ties share the average rank);
  • n_above, n_tied — how many dyads the model rated above the observed one, and how many it rated equal to it (itself included): the rank under a random breaking of ties is uniform on n_above + 1 … n_above + n_tied;
  • reciprocal_rank — the expected 1/rank under that random tie-breaking;
  • rank_fraction — (rank − 1)/(risk set size − 1), from 0 (top) to 1;
  • deviance_residual — −2 log(probability), the deviance residual of Butts (2008) and Butts & Marcum (2017);
  • null_residual — 2 log(risk set size), the residual of the model with no effects, under which every dyad is equally likely;
  • surprise — −log₂(probability) in bits.

Events with a large deviance residual are the ones the model did not see coming; read against the sequence they show where a specification fails (a phase of the process, a group of actors), which a single fit index cannot.

cases selects the events to score (indices into fit.events, a mask or a predicate). Passing events that were held out of the fit gives out-of-sample prediction: fit on cases=1:k, score cases=(k+1):n. Each held-out event is predicted one step ahead from the true history before it — not by simulating the held-out segment, which is the procedure of Brandenberger (2019).

Example

using Revel, Random
stats = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
events = simulate_events(stats, [1.0, 0.5], 6, 200; rng=Xoshiro(1))
train = fit_revel(events, stats, 6; cases=1:150)
held_out = event_diagnostics(train; cases=151:200)
size(held_out, 1)                          # 50
all(0 .< held_out.probability .<= 1)       # true
source
Revel.prediction_summary — Function
prediction_summary(fit::RevelFit; ks=(1, 5, 10), cases=fit.cases) -> NamedTuple

Predictive fit of a relational event model, summarised over events:

  • n_events;
  • recall — for each k in ks, the share of events whose observed dyad was among the model's top k dyads (an integer k) or its top fraction k of the risk set (a k in (0, 1): 0.05 is the top 5 %). The default ks=(1, 5, 10) are ranks, not percentages. recall at 1 is the classification accuracy of Butts (2008); the recall of the top 5 % is the prediction measure of Meijerink-Bosman, Back, Geukes, Leenders & Mulder (2023), used in the remstats tutorials. Dyads the model rates equal to the observed one are credited as a random breaking of the tie would credit them (the expected recall), so an event tied with the whole risk set scores k/D, not 0. A fraction of a small risk set can hold fewer dyads than a larger integer k, and so give a lower recall;
  • mean_rank, median_rank, mean_reciprocal_rank (the mean expected 1/rank under random tie-breaking), mean_rank_fraction;
  • deviance and null_deviance — sums of the residuals of event_diagnostics;
  • pseudo_r2 — 1 − deviance/null_deviance, the share of the null deviance the effects account for (Perry & Wolfe 2013 report their models this way);
  • perplexity — 2^(mean surprise), the effective number of equally likely dyads the model leaves.

Computed on the fitted events these are in-sample; pass held-out cases for an honest comparison between specifications.

Example

using Revel, Random
stats = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
events = simulate_events(stats, [1.0, 0.5], 6, 200; rng=Xoshiro(1))
summary = prediction_summary(fit_revel(events, stats, 6); ks=(1, 3, 0.2))
summary.n_events                 # 200
0 < summary.pseudo_r2 < 1        # true
summary.recall                   # share of events in the top 1, top 3, top 20 %
source

Score processes and score tests

Revel.score_process_test — Function
score_process_test(fit::RevelFit; n_sim=1000, rng=Random.default_rng(),
                   return_process=false)

Check whether the model describes the whole event sequence equally well, with the cumulative score process of each effect — the cumulative sum, over events, of the difference between the observed statistic and its expectation under the fitted model (the martingale residuals of the model). Under a correctly specified model each process wanders around zero and returns to it; an effect that strengthens or fades over the sequence, a wrong memory kernel or functional form, or an omitted effect makes it drift.

This is the residual-based goodness of fit of Boschi & Wit (2026), in the form of the score-process test of Lin, Wei & Ying (1993) for the Cox model that a relational event model is: the supremum of the absolute process is compared with n_sim realisations of its null distribution, generated by the multiplier (Gaussian) resampling that accounts for the coefficients being estimated. (Of Boschi & Wit's proposals it implements the processes of the model's own statistics; the processes of auxiliary statistics and their Cauchy combination are not implemented.)

Returns a DataFrame with one row per effect — term, statistic (the supremum of the process standardised by 1/√I_kk, I being the observed information), p_value (resampling), p_kolmogorov, at_event (where the supremum occurs) — and a final GLOBAL row: the largest of the standardised suprema, with its p-value from the same resampling (the maximum over effects in every draw), which accounts for the correlation between the effects. Read p_value. p_kolmogorov refers the statistic to the supremum of a Brownian bridge, which holds in large samples only when information accrues at a constant rate along the sequence — it does not for cumulative statistics, whose information grows with the history — so treat it as a rough guide; its GLOBAL entry is the Bonferroni bound. With return_process=true the result is (table, process), process being the events × effects matrix of standardised processes for plotting.

Under tied event times each tied event enters the resampling as its own increment; with the Efron correction that is an approximation whose calibration has not been checked by simulation.

A rejection says the specification is not adequate over the sequence; it does not say which effect is at fault. The rows are indexed by effect, but drift in one effect, an omitted effect or a wrong memory leaks into the process of every effect correlated with it, so several rows reject together. at_event locates the drift, not its cause; fit_moving_window and score_test are the follow-ups. Defined for converged ordinal fits whose risk sets were enumerated (any riskset, cases or directed); refused for model=:timing and for fits with sampled controls.

Example

using Revel, Random
stats = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
events = simulate_events(stats, [1.0, 0.5], 6, 200; rng=Xoshiro(1))
test = score_process_test(fit_revel(events, stats, 6); n_sim=200, rng=Xoshiro(2))
test.term                          # ["log1p(inertia)", "log1p(reciprocity)", "GLOBAL"]
all(0 .<= test.p_value .<= 1)      # true
source
Revel.score_test — Function
score_test(fit::RevelFit, candidates) -> DataFrame

Rao score tests for effects that are not in the model: for each candidate statistic, would adding it improve the fit? The test needs only the fitted model — nothing is refitted — so a whole catalogue of candidate effects can be screened in one pass over the risk sets.

Each row gives the candidate's term, its score (the sum over events of observed minus expected statistic, at the fitted coefficients), the score's variance after adjusting for the effects already in the model, the chisq statistic (one degree of freedom), its p_value, direction — the sign the candidate's coefficient would take — and residual_share, the share of the candidate's information left after the fitted effects (1 − R²). A candidate that the fitted effects span to working precision has nothing left to test and gets NaN.

This is goodness-of-fit-driven effect discovery, and a way to apply the hierarchy principle: fit the lower-order terms (degree, repetition) and ask whether a triadic term still has something to explain, rather than reading a closure coefficient from a model that omits them. It does not settle the question: Juozaitienė & Wit (2024) show that "ghost" triadic effects can persist even next to degree terms when actor heterogeneity is not modelled, which this package cannot do (no random effects). Candidates are tested one at a time, not jointly; screening many of them calls for a multiplicity correction. Defined for converged ordinal fits whose risk sets were enumerated (any riskset, cases or directed); refused for model=:timing and for fits with sampled controls.

Tied event times. Under ties=:breslow the test is the Rao test of the Breslow likelihood. Under ties=:efron the score and the information are those of the exact partial likelihood of each tie block — the average over the orderings of the tied events, which Efron's correction approximates — because Efron's own information understates the variance of its score when the tied dyads carry much of the risk set's weight (7.6 % rejections at the 5 % level on true models with three tied events per tick among thirty dyads; the exact form is nominal). The orderings are enumerated, so a block of more than 7 tied events is refused, as is an Efron fit on a subset of cases with tied events: use score_process_test there, or ties=:breslow.

Example

using Revel, Random
truth = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
events = simulate_events(truth, [1.0, 1.0], 6, 300; rng=Xoshiro(1))
small = fit_revel(events, [Inertia(transform=:log1p)], 6)
screen = score_test(small, [Reciprocation(transform=:log1p), OTP(transform=:log1p)])
screen.term                        # ["log1p(reciprocity)", "log1p(otp)"]
screen.p_value[1] < 0.05           # true — reciprocity was left out
source

Simulation-based goodness of fit

NetworkCore.gof — Method
gof(fit::RevelFit; n_sim=100, rng=Random.default_rng(), auxiliary=nothing,
    refit=false, n_inner=20, threaded=true) -> NetworkCore.GOFResult

Simulation-based goodness of fit: simulate n_sim event sequences from the fitted model and compare auxiliary statistics of the observed sequence with their simulated distribution. The result is the ecosystem's shared NetworkCore.GOFResult — observed value, simulation envelope and Monte-Carlo p-value per statistic, and an overall p-value (p_overall) from the Mahalanobis distance of all the auxiliary statistics together, as in RSiena's sienaGOF — so it prints like every other model's gof.

An ordinal fit is simulated conditional on the observed event times (and event types and weights), so a memory kernel stated in clock units keeps its meaning; under ties=:breslow/:efron the events of one timestamp do not see each other, as in the fit. An interval-timing fit simulates its own waiting times from the fitted baseline, starting at the fit's t0 and conditional on the number of events (the censored tail after the last event is not simulated). A receiver-choice fit (riskset=:sender) is simulated conditional on the observed senders.

The default auxiliary statistics are statistics the model was not fitted to match in general: the share of events closing each of six configurations (mechanism_shares), the concentration of activity and popularity (Gini coefficients, distinct dyads per event), and the quartiles of the closing times of reciprocation and repetition measured in events (closing_times; a sequence in which nothing closes is censored at its length). An interval-timing fit adds the quartiles and mean of the waiting times. For an undirected fit they are the undirected counterparts — the shares of events repeating a pair and closing a shared partner, the concentration of degree, the quartiles of repetition closing times — computed with every pair written as (min, max), as the simulator writes it. Supply your own as auxiliary = [(name, labels, events -> values), …].

How to read it:

  • By default it is a plug-in parametric bootstrap: the sequences are simulated from the estimates, which were fitted to the observed sequence, and are not refitted. For auxiliaries close to what the model's statistics already fix, the observed value sits near the centre by construction, so the p-values are conservative and the check has little power against a missing effect.
  • refit=true removes that conservatism by treating every simulated sequence as the observed one was treated: 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. Residuals of sequences from the model are exchangeable with the observed residual, so the p-values are no longer conservative by construction: on true models the per-statistic p-values reject 3–5 % of the time at the 5 % level and p_overall 3–6 %, where the plug-in check rejects 1–2 % (what remains below 5 % is the discreteness of auxiliaries such as quartiles, whose ties a Monte-Carlo p-value counts against rejection). The reference values are reported re-centred on the observed fit's expectation. The cost is n_sim refits and (n_sim + 1) × n_inner further simulations, run on the available threads (threaded=false runs them serially); one seed per replicate is drawn from rng up front, so the result depends on rng only, not on the thread count. A replicate whose refit does not converge is left out, with a warning.
  • The per-statistic p-values are pointwise: with fifteen of them, a few small ones are expected by chance. p_overall is the one joint test.
  • Amati, Lomi & Snijders (2024) use deciles of internal times and a Mahalanobis test per set of statistics; the auxiliaries here are different statistics, and the joint test spans all of them.

Refused for a fit on a subset of cases (the model does not describe the other events), a time-varying risk set, a receiver-oriented risk set (riskset=:receiver; the simulator draws receivers given senders only) and a fit that did not converge.

Example

using Revel, Random
stats = [Inertia(transform=:log1p), Reciprocation(transform=:log1p)]
events = simulate_events(stats, [1.0, 0.5], 6, 150; rng=Xoshiro(1))
result = gof(fit_revel(events, stats, 6); n_sim=20, rng=Xoshiro(2))
n_simulations(result)                      # 20
[s.name for s in result.statistics]        # the three auxiliary families
calibrated = gof(fit_revel(events, stats, 6); n_sim=20, refit=true, n_inner=5,
                 rng=Xoshiro(2))           # 20 refits, 105 inner simulations
0 < calibrated.p_overall <= 1              # true
source

Sequence metrics

Revel.mechanism_shares — Function
mechanism_shares(events) -> NamedTuple

The share of events in a sequence that, when they happened, closed each of six configurations: repetition (the dyad had acted before), reciprocation (the reverse dyad had), transitive (an outgoing two-path s → k → r existed), cyclic (an incoming two-path r → k → s), shared_out (both had sent to a common third) and shared_in (both had received from one).

These are descriptive counts, not effects — every share rises with the density of the accumulated network — but they are the natural auxiliary statistics for simulation-based goodness of fit: a fitted model should reproduce them (gof uses them by default).

Example

using Revel
events = [Event(1, 2, 1.0), Event(2, 1, 2.0), Event(1, 2, 3.0), Event(2, 3, 4.0),
          Event(1, 3, 5.0)]
shares = mechanism_shares(events)
shares.repetition       # 0.2 — the third event repeats 1 → 2
shares.reciprocation    # 0.4 — the second and third events answer an earlier one
shares.transitive       # 0.2 — 1 → 3 closes 1 → 2 → 3
source
Revel.closing_times — Function
closing_times(events; mechanism=:reciprocation, reference=:last, clock=:time)
    -> Vector{Float64}

For every event that closes mechanism, the time elapsed since the configuration it closes came into being. mechanism is one of :repetition, :reciprocation, :transitive, :cyclic, :shared_out, :shared_in.

reference=:last measures from the most recent triggering event (how long did the answer take?); reference=:first from the earliest one. For the triadic mechanisms a two-path exists from the moment its second leg does, and the reference is taken over the third actors. clock=:order measures the gap in events instead of clock time.

This is in the spirit of the "internal time" of Amati, Lomi & Snijders (2024) but is not their definition: they consume an antecedent once it has been closed, count only the antecedents after the previous s → r event, and time a triad from the earlier of its two legs. (Their internal times are not implemented.)

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; the distribution of closing times does, and it also guides the choice of a memory kernel before any model is fitted.

Example

using Revel
events = [Event(1, 2, 1.0), Event(2, 1, 4.0), Event(1, 2, 5.0), Event(2, 1, 5.5)]
closing_times(events)                              # [3.0, 1.0, 0.5]
closing_times(events; mechanism=:repetition)       # [4.0, 1.5]
closing_times(events; clock=:order)                # [1.0, 1.0, 1.0]
source

Specification

Revel.statistic_collinearity — Function
statistic_collinearity(events, statistics, n_actors; kwargs...) -> NamedTuple
statistic_collinearity(fit::RevelFit) -> NamedTuple

How collinear the statistics of a specification are, within risk sets — only differences between the dyads of one risk set carry information:

  • names;
  • correlation — the within-risk-set correlation matrix;
  • vif — variance inflation factors, 1/(1 − R²) of each statistic regressed on the others; Inf for a statistic the others span exactly (and only for those: a duplicated statistic does not make every other VIF infinite);
  • condition_number — of the correlation matrix.

The first form weights every dyad of a risk set equally, which is how the likelihood sees the statistics at θ = 0 and needs no fit — the check to run while choosing a specification. The second weights them by the fitted probabilities, which is how the likelihood sees them at the estimate: its VIFs are I_jj (I⁻¹)_jj of the observed information I, the factor by which collinearity inflates each variance. Strong effects concentrate the probabilities on dyads where the statistics co-vary, so the second is usually the larger.

Endogenous statistics are built from the same history and overlap by construction (inertia and out-degree, the four triadic statistics, an interaction and its main effects), yet the literature offers no diagnostic for it. A VIF above about 10, or a condition number in the hundreds, says a coefficient is being estimated from little independent variation and will move when neighbouring terms enter or leave. A statistic that is constant within every risk set — a GlobalEffect, a sender covariate in a receiver-choice model — has no variation at all and is reported with NaN correlations and an infinite VIF.

Keywords are those of each_risk_set.

Example

using Revel, Random
events = simulate_events([Inertia(transform=:log1p)], [1.0], 6, 200; rng=Xoshiro(1))
check = statistic_collinearity(events, [Inertia(), OutdegreeSender(), OTP()], 6)
check.names                        # ["inertia", "outdegreeSender", "otp"]
size(check.correlation)            # (3, 3)
all(check.vif .>= 1)               # true
dup = statistic_collinearity(events, [Inertia(), Inertia(name="copy"), OTP()], 6)
dup.vif[3] < Inf                   # true — only the duplicated pair is infinite
fitted = statistic_collinearity(fit_revel(events, [Inertia(transform=:log1p), OTP()], 6))
fitted.names                       # ["log1p(inertia)", "otp"]
source
Revel.effect_catalogue — Function
effect_catalogue() -> DataFrame

The concordance between Revel's effects and the vocabulary of the other relational-event packages: one row per effect with the revel call, its family (endogenous, exogenous, interaction, hyperevent, memory, scaling), the configuration it measures, the name under which relevent, remstats, rem, goldfish and eventnet offer it (empty when a package does not), and the source that proposed it.

The same name does not mean the same number across packages — they differ in scaling, in the zero-history value, in how the legs of a two-path are combined and in the normalisation of the decay kernel — so each revel entry spells out the options that reproduce the other package's measurement.

How far each column is verified:

  • remstats — every statistic call in the column is pinned against remstats 4.1.0 by a golden fixture (141 statistic arrays), including a:b products, event(), consider_type = "separate", scaling = "prop"/"std", event weights and the window, interval and decay memories. One difference is deliberate: under memory = "decay" remstats evaluates the decay at the previous event's time, Revel at the time of the event being explained.
  • relevent — pinned against relevent::rem.dyad 1.2.1 itself (a golden fixture of its design statistics), except the three names marked †: FrPSndSnd, FrRecSnd and OSPSnd are given as relevent documents them, but relevent 1.2.1's output differs from that documentation, so Revel does not reproduce relevent's numbers there.
  • rem, goldfish, eventnet — follow those packages' documentation and have not been checked by running them.

Example

using Revel
cat = effect_catalogue()
names(cat)[1:4]                                   # ["revel", "family", "configuration", "relevent"]
cat[cat.relevent .== "NODSnd", :revel]            # ["OutdegreeSender(scaling=:prop, empty=1/(n-1))"]
cat[cat.goldfish .== "commonReceiver", :revel]    # ["OSP(combine=:count)"]
source