Terms
ERGMMulti.LayerEdges — Type
LayerEdges(layers=:) <: AbstractERGMTermEdge count within the selected layer(s). With a layer index this is the per-layer edges term (ergm.multi's L(~edges, ~A)); with : (or a vector) it pools the coefficient across layers — the edges statistic of the block-diagonal combined network, one coefficient for all selected layers. Dyad-independent; labelled as ergm.multi labels it, L(A)~edges for a layer named :A and L((A,B))~edges for a pool (see WithinLayer).
Example
using ERGMMulti, ERGM
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :friendship); add_layer!(m, :advice)
add_layer_edge!(m, :friendship, 1, 2); add_layer_edge!(m, :friendship, 2, 3)
add_layer_edge!(m, :advice, 1, 2)
compute(LayerEdges(1), m) # 2.0 — layer 1 only
compute(LayerEdges(), m) # 3.0 — pooled over all layers
compute(LayerEdges([1, 2]), m) # 3.0 — the same pool, spelled out
name(LayerEdges(2), m) # "L(advice)~edges"
name(LayerEdges(), m) # "L((friendship,advice))~edges"
name(LayerEdges(2)) # "L(2)~edges" — no network: layers by indexERGMMulti.LayerMutual — Type
LayerMutual(layers=:) <: AbstractERGMTermMutual (reciprocated) dyads within the selected layer(s). Directed multilayer networks only: requires_directed(LayerMutual()) == true, so on a MultilayerNetwork{false} model construction, compute and change_stat_layer all throw the same ArgumentError ERGM.jl raises for Mutual() on an undirected network (it used to return 0.0 silently). ergm.multi's L(~mutual, ~A); labelled L(A)~mutual.
Example
using ERGMMulti, ERGM
m = MultilayerNetwork(3; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 1); add_layer_edge!(m, :a, 2, 3)
compute(LayerMutual(1), m) # 1.0 — the (1,2) dyad is reciprocated
compute(LayerMutual(), m) # 1.0 — pooled; layer :b is empty
change_stat_layer(LayerMutual(1), m, 1, 3, 2) # 1.0 — 3→2 would reciprocate 2→3
u = MultilayerNetwork(3; directed=false); add_layer!(u, :a)
try
compute(LayerMutual(1), u) # refused, never a silent 0.0
catch e
occursin("only defined for directed networks", e.msg) # true
endERGMMulti.LayerTriangle — Type
LayerTriangle(layers=:) <: AbstractERGMTermTriangle count within the selected layer(s), using ERGM.jl's Triangle statistic per layer (ergm.multi's L(~triangle, ~A); labelled L(A)~triangle). Dyad-dependent, so a fit containing it carries the pseudo-likelihood caveat.
Example
using ERGMMulti, ERGM
m = MultilayerNetwork(4; directed=false)
add_layer!(m, :a); add_layer!(m, :b)
for (i, j) in ((1, 2), (2, 3), (1, 3), (3, 4))
add_layer_edge!(m, :a, i, j)
end
add_layer_edge!(m, :b, 1, 2)
compute(LayerTriangle(1), m) # 1.0
change_stat_layer(LayerTriangle(1), m, 1, 2, 4) # 1.0 — adding 2-4 closes {2,3,4}
change_stat_layer(LayerTriangle(1), m, 2, 2, 4) # 0.0 — layer 2 is not selectedERGMMulti.WithinLayer — Type
WithinLayer(term, layer) <: AbstractERGMTerm
WithinLayer(term, layers) # a vector of layer indices, or `:`Lift any ERGM.jl term into the layers of a multilayer network.
WithinLayer(term, l)with one layer index is the statistic (and its add-direction change statistic) oftermevaluated on layerl's network —ergm.multi'sL(~term, ~A).WithinLayer(term, [l1, l2, ...])(or:for every layer) pools the term across the selected layers: the statistic is the sum of the term's per-layer statistics, with one coefficient —ergm.multi'sL(~term, c(~A, ~B))(pinned against R inpooled_layer_terms.toml).WithinLayer(Triangle(), [1, 2])isLayerTriangle([1, 2]).
The wrapped term is validated against every selected layer when a MultiERGMModel is built (through the public ERGM.Extension.validate_formula): a vertex attribute the layer lacks, or has on only some vertices, an EdgeCov of the wrong size, and a direction requirement the layer does not meet (Kstar, GWDegree, Degree are undirected-only; Mutual, OStar, IStar, GWODegree, ... directed-only) raise ERGM.jl's own actionable errors instead of a silent 0.0. Attribute terms are then materialized per layer (ERGM.Extension.materialize), so their change statistics read a dense snapshot rather than a Dict per toggle, and a term that expands into several statistics (NodeFactor(:g) with several levels, Degree(0:2)) contributes one coefficient per statistic, as in ERGM.jl. A pooled expanding term must expand identically on every selected layer (the same attribute levels); otherwise the constructor refuses, naming the layers.
Refused, with an ArgumentError: an ERGM.Offset term (fix a multilayer coefficient with the offsets= keyword instead), an empty layer vector and a repeated layer index.
The coefficient label is ergm.multi's: "L(<layer>)~" * name(term, layer_network), with the layer named by layer_names(m) and the wrapped term's direction-aware ERGM.jl/R label. On layers named :a and :b, a directed layer's WithinLayer(GWESP(0.5), 1) is L(a)~gwesp.OTP.fixed.0.5, an undirected one L(a)~gwesp.fixed.0.5, and the pooled forms (WithinLayer(term, [1, 2]), WithinLayer(term, :), R's L(~term, c(~a, ~b))) are L((a,b))~gwesp.fixed.0.5. Without a network the layers are named by index (L(1)~…, L((1,2))~…, L((:))~…).
Example
using ERGMMulti, ERGM, NetworkCore
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 1)
add_layer_edge!(m, :b, 3, 4); add_layer_edge!(m, :b, 4, 3)
compute(WithinLayer(Mutual(), 1), m) # 1.0
compute(WithinLayer(Mutual(), [1, 2]), m) # 2.0 — pooled: one coefficient, both layers
compute(WithinLayer(Mutual(), :), m) # 2.0
name(WithinLayer(GWESP(0.5), 1), m) # "L(a)~gwesp.OTP.fixed.0.5"
name(WithinLayer(GWESP(0.5), [1, 2]), m) # "L((a,b))~gwesp.OTP.fixed.0.5"
try
MultiERGMModel([WithinLayer(Kstar(2), 1)], m) # undirected-only term
catch e
occursin("OStar(2)", e.msg) # true — ERGM.jl's own hint
endERGMMulti.InterlayerDependence — Type
InterlayerDependence(l1, l2) <: AbstractERGMTermCross-layer co-occurrence: the number of dyads (i, j) with an edge in both layers l1 and l2 (ordered dyads for directed networks). A positive coefficient means a tie in one layer predicts the same tie in the other. This is ergm.multi's L(~edges, ~A&B) — the only layer-logic conjunction implemented (see "Not implemented" in the README); labelled L(A&B)~edges, as in R. Dyad-dependent over the (layer, i, j) universe.
Example
using ERGMMulti, ERGM
m = MultilayerNetwork(3; directed=true)
add_layer!(m, :friendship); add_layer!(m, :advice)
add_layer_edge!(m, :friendship, 1, 2); add_layer_edge!(m, :friendship, 2, 3)
add_layer_edge!(m, :advice, 1, 2); add_layer_edge!(m, :advice, 3, 2)
compute(InterlayerDependence(1, 2), m) # 1.0 — only 1→2 is in both
change_stat_layer(InterlayerDependence(1, 2), m, 1, 3, 2) # 1.0 — 3→2 exists in :advice
name(InterlayerDependence(1, 2), m) # "L(friendship&advice)~edges"ERGMMulti.MultiplexMutual — Type
MultiplexMutual(l1, l2) <: AbstractERGMTermCross-layer reciprocity: the number of ordered dyads (i, j) with i→j in layer l1 and j→i in layer l2 (e.g. friendship reciprocated by advice). Directed networks only: requires_directed(MultiplexMutual(1, 2)) == true, and on a MultilayerNetwork{false} model construction, compute and change_stat_layer all throw ERGM.jl's directed-only ArgumentError (it used to return 0.0 silently). This is ergm.multi's mutualL(Ls = list(~A, ~B)); labelled L(A,B)~mutual, as in R.
Example
using ERGMMulti, ERGM
m = MultilayerNetwork(3; directed=true)
add_layer!(m, :friendship); add_layer!(m, :advice)
add_layer_edge!(m, :friendship, 1, 2) # 1 names 2 a friend ...
add_layer_edge!(m, :advice, 2, 1) # ... and 2 seeks 1's advice
compute(MultiplexMutual(1, 2), m) # 1.0
compute(InterlayerDependence(1, 2), m) # 0.0 — different dyads, no co-occurrence
u = MultilayerNetwork(3; directed=false); add_layer!(u, :a); add_layer!(u, :b)
try
MultiERGMModel([MultiplexMutual(1, 2)], u)
catch e
occursin("only defined for directed networks", e.msg) # true
endERGMMulti.CrossNetEdges — Type
CrossNetEdges <: AbstractERGMTermTotal edge count across the networks of a MultiNetwork (descriptive pooling over independent networks; it does not enter a fit).
Example
using ERGMMulti, ERGM, NetworkCore
a = network(4; directed=false); add_edge!(a, 1, 2)
b = network(6; directed=true); add_edge!(b, 1, 2); add_edge!(b, 3, 4)
compute(CrossNetEdges(), MultiNetwork([a, b], [:school1, :school2])) # 3.0ERGMMulti.Nestedness — Type
Nestedness(level) <: AbstractERGMTermDescriptive: the proportion of level-level edges whose endpoints share the same higher-level unit (0.0 when the level has no edge between nodes with a recorded membership). Never enters a fit; level must have a parent level.
Example
using ERGMMulti, ERGM, NetworkCore
people = network(4; directed=false)
add_edge!(people, 1, 2); add_edge!(people, 2, 3); add_edge!(people, 3, 4)
orgs = network(2; directed=false)
ml = MultilevelNetwork([people, orgs], [Dict(1 => 1, 2 => 1, 3 => 2, 4 => 2)])
compute(Nestedness(1), ml) # 0.666… — (1,2) and (3,4) are within-organisationERGMMulti.CrossLevelEdge — Type
CrossLevelEdge <: AbstractERGMTermDescriptive: the number of explicit cross-level edges (added with add_cross_level_edge!). Never enters a fit.
Example
using ERGMMulti, ERGM, NetworkCore
ml = MultilevelNetwork([network(3; directed=false), network(2; directed=false)],
[Dict(1 => 1, 2 => 1, 3 => 2)])
compute(CrossLevelEdge(), ml) # 0.0
add_cross_level_edge!(ml, 1, 3, 2, 1)
compute(CrossLevelEdge(), ml) # 1.0ERGMMulti.LevelHomophily — Type
LevelHomophily(level) <: AbstractERGMTermDescriptive: the number of level-level edges between nodes belonging to the same higher-level unit. Membership is looked up by the level's own node IDs (a missing membership excludes the edge). Never enters a fit; Nestedness is the same count as a proportion.
Example
using ERGMMulti, ERGM, NetworkCore
people = network(4; directed=false)
add_edge!(people, 1, 2); add_edge!(people, 2, 3); add_edge!(people, 3, 4)
orgs = network(2; directed=false)
ml = MultilevelNetwork([people, orgs], [Dict(1 => 1, 2 => 1, 3 => 2, 4 => 2)])
compute(LevelHomophily(1), ml) # 2.0 — (1,2) and (3,4); (2,3) crosses organisationsERGMMulti.change_stat_layer — Function
change_stat_layer(term, m::MultilayerNetwork, l, i, j) -> Float64Add-direction change statistic for adding edge (i,j) in layer l, holding every other (layer, dyad) fixed. Must not depend on the dyad's own current state (the multilayer analogue of ERGM.jl's change_stat convention; the tests verify every term against brute-force recomputation). The MPLE design has one row of these per within-layer dyad, and the Metropolis sampler evaluates them once per proposal.
Example
using ERGMMulti
m = MultilayerNetwork(3; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :b, 1, 2)
change_stat_layer(LayerEdges(1), m, 1, 1, 2) # 1.0 — an edge in layer 1
change_stat_layer(LayerEdges(1), m, 2, 1, 2) # 0.0 — layer 2 is not selected
change_stat_layer(InterlayerDependence(1, 2), m, 1, 1, 2) # 1.0 — 1→2 is already in layer 2
change_stat_layer(InterlayerDependence(1, 2), m, 1, 2, 1) # 0.0Coefficient labels
Coefficients carry the labels ergm.multi prints, with the layers named by layer_names(m). A within-layer statistic is labelled L(<layer>)~ followed by R's label for the term, resolved against the layer's network with ERGM.jl's two-argument name(term, net) generic: on layers named :A and :B, a directed layer's WithinLayer(GWESP(0.5), 1) prints as L(A)~gwesp.OTP.fixed.0.5, an undirected one as L(A)~gwesp.fixed.0.5, and the pooled WithinLayer(GWESP(0.5), [1, 2]) as L((A,B))~gwesp.fixed.0.5. The multilayer terms are L(A)~edges, L((A,B))~edges (pooled), L(A)~mutual, L(A)~triangle, L(A&B)~edges (InterlayerDependence) and L(A,B)~mutual (MultiplexMutual); an offset row is offset(L(A)~edges). Without a network (name(term)) the layers are named by index — L(1)~edges, which is also what R prints for an unnamed layer list. The labels are pinned against ergm.multi by test/fixtures/multilayer_labels.toml.
NetworkCore.name — Method
name(t::WithinLayer, m::MultilayerNetwork) -> StringThe coefficient label of a within-layer term on m: "L<layers>." followed by the wrapped term's label on that layer's network (name(term, net)), so it agrees with ERGM.jl and R on direction-dependent labels. A pooled term (WithinLayer(term, [1, 2]), WithinLayer(term, :)) is labelled L((A,B))~, as ergm.multi labels L(~term, c(~A, ~B)).