Covariates and Interactions API Reference

Covariates

Revel.Covariate — Type
Covariate(values; name="x", categorical=false)
Covariate(times, values; name="x", categorical=false)

An actor-level covariate, indexed by actor ID.

The one-argument form is constant over time. The two-argument form is time-varying, piecewise constant: values[:, k] is in force from times[k] until times[k+1] (and values[:, 1] before times[1]), the structure of remstats' and goldfish's changing attributes.

Non-numeric values (strings, symbols) are treated as categories: they work with MatchEffect and the matching filters, and the numeric effects refuse them. categorical=true treats numbers as category labels too (team numbers, say). An actor without a value is an ArgumentError, never a silent zero, and so is a missing value: an unobserved attribute is not a category.

Example

using Revel
role = Covariate([:staff, :lead, :staff]; name="role")
load = Covariate([0.0, 10.0], [1.0 3.0; 2.0 2.0; 0.5 0.5]; name="load")
covariate_value(load, 1, 5.0)     # 1.0
covariate_value(load, 1, 12.0)    # 3.0
covariate_value(role, 2, 0.0)     # 2.0 — the code of :lead
Covariate([1, 1, 2]; name="team", categorical=true).categorical   # true
source
Revel.covariate_value — Function
covariate_value(x::Covariate, actor, time) -> Float64

The value of x for actor at time (the category code for a categorical covariate). Throws an ArgumentError for an actor the covariate does not cover.

Example

using Revel
x = Covariate([0.0, 5.0], [1.0 2.0; 3.0 4.0])
covariate_value(x, 2, 4.9), covariate_value(x, 2, 5.0)    # (3.0, 4.0)
source
Revel.CovariateEffect — Type
CovariateEffect(form, x, y=x; transform=identity, name=nothing)

An exogenous effect built from actor covariates. form selects how the sender's value xᵢ and the receiver's value xⱼ (or yⱼ) enter:

formvaluenamed constructor
:sendxᵢSendEffect
:receivexⱼReceiveEffect
:same1 if xᵢ == xⱼMatchEffect
:absdiffabs(xᵢ - xⱼ)DiffEffect
:differencexᵢ - xⱼDiffEffect(x; absolute=false)
:similarity-abs(xᵢ - xⱼ)SimEffect
:average(xᵢ + xⱼ)/2AverageEffect
:minimum / :maximummin / maxMinimumEffect, MaximumEffect
:sumxᵢ + xⱼSumEffect
:productxᵢ · yⱼProductEffect

Every form accepts a time-varying Covariate.

Example

using Revel
age = [30.0, 45.0, 52.0]
h = build_history(Event{Float64}[])
compute(CovariateEffect(:absdiff, age), h, 1, 3, 0.0)    # 22.0
compute(CovariateEffect(:average, age), h, 1, 3, 0.0)    # 41.0
source
Revel.SendEffect — Function
SendEffect(x; transform=identity, name=nothing)

The sender's covariate value: do actors with more of x send more? (remstats send(); goldfish ego(); relevent CovSnd.) In an ordinal model it is identified only while the risk set contains several senders — it drops out of a receiver-choice model and of any model stratified by sender (Perry & Wolfe 2013).

Example

using Revel
h = build_history(Event{Float64}[])
compute(SendEffect([0.0, 1.0, 1.0]; name="senior"), h, 2, 1, 0.0)    # 1.0
source
Revel.ReceiveEffect — Function
ReceiveEffect(x; transform=identity, name=nothing)

The receiver's covariate value: are actors with more of x addressed more? (remstats receive(); goldfish alter(); relevent CovRec.)

Example

using Revel
h = build_history(Event{Float64}[])
compute(ReceiveEffect([0.0, 1.0, 1.0]), h, 2, 1, 0.0)    # 0.0
source
Revel.MatchEffect — Function
MatchEffect(x; transform=identity, name=nothing)

Homophily on a category: 1 when sender and receiver have the same value of x (remstats same(); goldfish same()). x may be categorical.

Example

using Revel
dept = Covariate(["ops", "legal", "ops"]; name="dept")
h = build_history(Event{Float64}[])
compute(MatchEffect(dept), h, 1, 3, 0.0), compute(MatchEffect(dept), h, 1, 2, 0.0)   # (1.0, 0.0)
source
Revel.DiffEffect — Function
DiffEffect(x; absolute=true, transform=identity, name=nothing)

The difference between the sender's and the receiver's values: absolute by default (heterophily — remstats difference(); goldfish diff()), or signed xᵢ - xⱼ with absolute=false (hierarchy: does the higher-status actor address the lower?).

Example

using Revel
rank = [3.0, 1.0]
h = build_history(Event{Float64}[])
compute(DiffEffect(rank), h, 2, 1, 0.0)                    # 2.0
compute(DiffEffect(rank; absolute=false), h, 2, 1, 0.0)    # -2.0
source
Revel.SimEffect — Function
SimEffect(x; transform=identity, name=nothing)

Homophily on a numeric covariate: -abs(xᵢ - xⱼ) (goldfish sim()), the mirror image of DiffEffect.

Example

using Revel
h = build_history(Event{Float64}[])
compute(SimEffect([3.0, 1.0]), h, 1, 2, 0.0)    # -2.0
source
Revel.AverageEffect — Function
AverageEffect(x; transform=identity, name=nothing)

The mean of the two actors' values (remstats average()), a symmetric form that suits undirected events; half of relevent's CovInt.

Example

using Revel
h = build_history(Event{Float64}[])
compute(AverageEffect([3.0, 1.0]), h, 1, 2, 0.0)    # 2.0
source
Revel.MinimumEffect — Function
MinimumEffect(x; transform=identity, name=nothing)

The smaller of the two actors' values (remstats minimum()): the effect of a trait both must have — the "weakest link" form used by Meijerink-Bosman et al. (2023) for personality traits.

Example

using Revel
h = build_history(Event{Float64}[])
compute(MinimumEffect([3.0, 1.0]), h, 1, 2, 0.0)    # 1.0
source
Revel.MaximumEffect — Function
MaximumEffect(x; transform=identity, name=nothing)

The larger of the two actors' values (remstats maximum()): the effect of a trait either may have.

Example

using Revel
h = build_history(Event{Float64}[])
compute(MaximumEffect([3.0, 1.0]), h, 1, 2, 0.0)    # 3.0
source
Revel.SumEffect — Function
SumEffect(x; transform=identity, name=nothing)

The sum of the two actors' values under one coefficient — relevent's CovInt, where "Int" means "both roles", not a statistical interaction. It is collinear with SendEffect(x) plus ReceiveEffect(x).

Example

using Revel
h = build_history(Event{Float64}[])
compute(SumEffect([3.0, 1.0]), h, 1, 2, 0.0)    # 4.0
source
Revel.ProductEffect — Function
ProductEffect(x, y=x; transform=identity, name=nothing)

The sender's value of x times the receiver's value of y (Perry & Wolfe 2013; goldfish egoAlterInt; remstats send("x"):receive("y")). Under a sender-stratified or receiver-choice model this is the only way a sender trait can enter.

Example

using Revel
senior = [1.0, 0.0, 1.0]; legal = [0.0, 1.0, 1.0]
h = build_history(Event{Float64}[])
compute(ProductEffect(senior, legal), h, 1, 2, 0.0)    # 1.0 — senior → legal
source
Revel.TieEffect — Type
TieEffect(matrix; transform=identity, name="tie")
TieEffect(times, matrices; transform=identity, name="tie")

An exogenous dyadic covariate matrix[sender, receiver]: a pre-existing tie (friendship, a reporting line, co-membership), a distance, an alliance (remstats tie(); goldfish tie(); relevent CovEvent). The two-argument form is time-varying — matrices[k] is in force from times[k]. transform=:indicator gives goldfish's presence form I(x > 0).

Example

using Revel
friends = [0 1 0; 1 0 0; 0 0 0]
h = build_history(Event{Float64}[])
compute(TieEffect(friends; name="friend"), h, 1, 2, 0.0)    # 1.0
later = TieEffect([0.0, 10.0], [friends, zeros(3, 3)])
compute(later, h, 1, 2, 11.0)                                # 0.0
source
Revel.GlobalEffect — Type
GlobalEffect(f; name="global")
GlobalEffect(times, values; name="global")

A covariate of time alone — time of day, a weekday, a period after a shock: f(t), or the piecewise-constant values[k] from times[k].

A global covariate is the same for every dyad in a risk set, so its main effect is not identified by the ordinary ordinal (partial) likelihood, which does not depend on its coefficient: fit_revel refuses a model that holds one outside an Interaction. Its use there is as a moderator: Interaction(GlobalEffect(…), Reciprocation()) asks whether reciprocity is stronger in some periods, and that product is identified ("effectively dyadic", Lembo, Juozaitienė, Vinciotti & Wit 2026). This is the product-term counterpart of fitting separate models per period with fit_stratified.

Lembo et al. (2026) also recover the main effects of global covariates, with a partial likelihood whose controls are drawn at shifted times (a time-shifted nested case-control design); that estimator is not implemented here. The interval-timing model identifies them too, but a GlobalEffect changes between events and is refused there.

Example

using Revel
weekend = GlobalEffect(t -> mod(floor(t), 7) >= 5 ? 1.0 : 0.0; name="weekend")
h = build_history([Event(2, 1, 1.0)])
moderated = Interaction(weekend, Reciprocation())
compute(moderated, h, 1, 2, 5.5)    # 1.0 — a weekend, one past 2 → 1 event
compute(moderated, h, 1, 2, 2.5)    # 0.0
source
Revel.TertiusEffect — Type
TertiusEffect(x; role=:receiver, direction=:in, aggregate=:mean,
              tie_weighted=false, difference=false, exclude_other=true,
              empty=0.0, transform=identity, name=nothing, layer=nothing,
              memory=…, …)

An aggregate of covariate x over the network neighbours of one endpoint of the candidate dyad — goldfish's tertius, generalised by Haunss & Hollway (2023): "tertius effects summarize attributes of third nodes to any dyad". By default it is the mean of x over the actors who have sent to the receiver: is an actor addressed more when those already addressing it score high on x?

  • role — whose neighbours: the candidate's :receiver (goldfish type="alter") or :sender (type="ego").
  • direction — :in (actors who sent to that endpoint) or :out (actors it sent to).
  • aggregate — :mean, :sum, :max, :min, :sd (the weighted population standard deviation) or :range for a numeric covariate; :entropy for a categorical one — the Shannon entropy −Σ p_c log p_c of the neighbours' categories, the diversity measure of the "tertius party diversity" effect of Haunss & Hollway (2023).
  • tie_weighted — weight each neighbour by the layer weight of its tie.
  • difference=true — return abs(x[sender] - aggregate), goldfish's tertiusDiff: homophily at path distance two, the only way to express homophily in a two-mode network, where the sender and the receiver carry no common attribute.
  • exclude_other — leave the dyad's other endpoint out of the neighbourhood.
  • empty — the value when the endpoint has no neighbours (goldfish imputes the covariate's mean; pass it here to do the same).

This is an interaction built into the statistic: an actor covariate read through a history-defined network. It is not equivalent to a product term.

Example

using Revel
power = [1.0, 5.0, 3.0, 0.0]
h = build_history([Event(2, 4, 1.0), Event(3, 4, 2.0)])
compute(TertiusEffect(power), h, 1, 4, 3.0)                       # 4.0 — mean of 5 and 3
compute(TertiusEffect(power; aggregate=:max), h, 1, 4, 3.0)       # 5.0
compute(TertiusEffect(power; difference=true), h, 1, 4, 3.0)      # 3.0 — abs(1 − 4)
party = [:a, :green, :red, :a]
compute(TertiusEffect(party; aggregate=:entropy), h, 1, 4, 3.0)   # log(2) — two parties, one each
source
Revel.MatchedDegree — Type
MatchedDegree(x; role=:receiver, similarity=nothing, transform=identity,
              name=nothing, layer=nothing, memory=…, …)

A degree restricted to third actors who resemble the candidate's other endpoint on covariate x — the attribute-filtered statistic of Brandenberger's rem package.

  • role=:receiver (default): the weight of past events to the receiver from actors k with x[k] == x[sender]. This is the partisan-influence statistic of Malang, Brandenberger & Leifeld (2019, H1a) — does an actor join a target once others of its own kind (party family, department) have? They note that it cannot tell influence from the other diffusion mechanisms that produce the same pattern.
  • role=:sender: the weight of past events from the sender to actors k with x[k] == x[receiver] — does the sender already deal with the receiver's kind?

The candidate's own dyad is excluded, so the statistic is not confounded with inertia. similarity=(a, b) -> Real replaces the equality match with a graded weight; it receives the covariate's values (the categories themselves, for a categorical covariate). A filter of this kind answers "do same-kind actors' past events raise the rate?", which a product term IndegreeReceiver × x does not.

Example

using Revel
party = [1, 1, 2, 9]        # actor 4 is the target
h = build_history([Event(2, 4, 1.0), Event(3, 4, 2.0), Event(2, 4, 3.0)])
compute(MatchedDegree(party), h, 1, 4, 4.0)    # 2.0 — the two events by party-mate 2
compute(IndegreeReceiver(), h, 1, 4, 4.0)      # 3.0 — every event to 4
source

Interactions and wrappers

Revel.Interaction — Type
Interaction(stats...; name=nothing)

The product of two or more statistics: the explicit product-term interaction (remstats a:b; remulate interact()). Interaction(Inertia(), SendEffect(x)) moderates an endogenous effect by a covariate and Interaction(OutdegreeSender(), IndegreeReceiver()) is an endogenous × endogenous term. The parts may be any statistic with the history interface (PShift, a user's own, …); a REM.jl statistic has only REM's interface, so an interaction holding one works in REM.fit_rem but not in fit_revel.

The advice that recurs in the applied literature, though few papers state it: include the main effects alongside the product, scale cumulative statistics before interacting them (see Standardized and the transform=:log1p keyword), and centre a covariate first (see Transformed) so the main effects stay interpretable.

Example

using Revel
female = [1.0, 0.0, 1.0]
h = build_history([Event(2, 1, 1.0), Event(2, 1, 2.0)])
recip_by_sender = Interaction(Reciprocation(), SendEffect(female; name="female"))
name(recip_by_sender)                        # "reciprocity:female"
compute(recip_by_sender, h, 1, 2, 3.0)       # 2.0 × 1.0
compute(recip_by_sender, h, 2, 1, 3.0)       # 0.0
source
Revel.Transformed — Type
Transformed(stat, f; name=nothing)

f applied to the value of another statistic — a scaling (log1p, sqrt), a centring (x -> x - 3.2), a dichotomisation. It wraps any statistic of the ecosystem, including those that have no transform= keyword of their own.

Centring before forming a product term is the use the review singles out as undocumented in the REM literature: Interaction(Inertia(), Transformed(SendEffect(age), x -> x - 40)) leaves the inertia main effect meaning "inertia for a 40-year-old sender".

Example

using Revel
h = build_history([Event(1, 2, 1.0), Event(1, 2, 2.0), Event(1, 2, 3.0)])
compute(Transformed(Inertia(), log1p), h, 1, 2, 4.0)                        # log(4)
compute(Transformed(SendEffect([30.0, 50.0]), x -> x - 40), h, 2, 1, 4.0)   # 10.0
source
Revel.Standardized — Type
Standardized(stat, n_actors; directed=true, corrected=false, name=nothing)
Standardized(stat, dyads; corrected=false, name=nothing)

stat z-scored at every event time: its value minus the mean over a fixed set of dyads, divided by their standard deviation. The set is every dyad among actors 1:n_actors (unordered pairs with directed=false), or the explicit vector dyads of (sender, receiver) — a two-mode risk set, say. A statistic that is constant across the set standardises to 0.

The set must be the model's risk set, and the fitters check it: riskset=:full with the same n_actors and directed, or riskset=dyads with the same dyads. Risk sets that change from event to event (:active is fixed, but :sender, :receiver and function risk sets are not) are refused, because remstats' scaling = "std" — the construction this reproduces — standardises over the risk set of each event.

corrected=false divides by the population standard deviation (denominator D, the number of dyads); corrected=true by the sample one (denominator D − 1), which is what remstats computes. The two differ by the constant factor sqrt((D − 1)/D), so they rescale the coefficient and nothing else.

Cumulative statistics grow without bound over an event sequence, which makes their coefficients hard to compare across effects and can set off a feedback loop in simulation ("process explosion"); per-time-point standardisation is one remedy in the literature (Vieira, Leenders & Mulder 2024), a log1p transform another. It is a different model, not a rescaling: the mean cancels within a risk set but the standard deviation σ_t does not, so a coefficient θ on the standardised statistic is an effect of θ/σ_t per raw unit, which shrinks as the history accumulates and σ_t grows. Fitting Standardized(Inertia(), n) to data generated by a constant raw inertia effect therefore misfits, and the score-process test detects it.

The moments are computed once per event time, from one extra evaluation of every dyad of the set.

Example

using Revel
h = build_history([Event(1, 2, 1.0), Event(1, 2, 2.0)])
z = Standardized(Inertia(), 3)
compute(z, h, 1, 2, 3.0)    # ≈ 2.24 — the only dyad with a history
compute(z, h, 2, 3, 3.0)    # ≈ -0.45
two_mode = Standardized(Inertia(), two_mode_dyads(1:2, 3:4))
compute(two_mode, h, 1, 3, 3.0)   # 0.0 — no dyad of the set has a history
source
Revel.split_by_type — Function
split_by_type(constructor, types; kwargs...) -> Vector

One copy of an effect per past event type: constructor(; types=ty, kwargs...) for each ty in types. This is the type-split interaction — signed inertia and reciprocity in Brandes, Lerner & Snijders (2009), remstats consider_type = "separate", one attribute per event type in eventnet — the oldest and best-supported way of conditioning an endogenous effect in the literature.

It conditions on the type of the past events only. Whether the coefficient also differs by the type of the event being explained is a second, independent axis (remstats consider_type = "interact"), which needs a risk set of dyad × type and is not implemented here; fit separate models per outcome type with fit_stratified instead.

Example

using Revel
effects = split_by_type(Reciprocation, [:praise, :criticism])
name.(effects)     # ["reciprocity[types=praise]", "reciprocity[types=criticism]"]
h = build_history([Event(2, 1, 1.0; eventtype=:praise)])
[compute(e, h, 1, 2, 2.0) for e in effects]    # [1.0, 0.0]
source