Terms API Reference
This page documents all ERGM terms available in ERGM.jl.
Structural Terms
Terms based purely on network structure.
ERGM.Edges — Type
Edges <: StructuralTermThe number of edges in the network (statnet edges, coefficient name "edges"). The most basic ERGM term, analogous to an intercept: alone it is the Bernoulli model, whose MLE is the logit of the density.
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(Edges(), net) # 20.0
round(coef(fit_ergm(net, Edges()))[1]; digits=4) # -1.6094 == log(20/100)ERGM.Mutual — Type
Mutual <: StructuralTermThe number of mutual (reciprocated) dyads (statnet mutual). Directed networks only: requires_directed(Mutual()) == true, so a model with it on an undirected network is refused.
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 2); add_edge!(net, 2, 1); add_edge!(net, 2, 3)
compute(Mutual(), net) # 1.0
change_stat(Mutual(), net, 3, 2) # 1.0 — 2→3 exists, so 3→2 would reciprocate itERGM.Triangle — Type
Triangle <: StructuralTermThe number of triangles in the network.
For undirected networks this is the usual triangle count. For directed networks it follows the statnet triangle definition: the number of transitive triples plus the number of cyclic triples (ttriple + ctriple). Dyad-dependent: an MPLE fit with it prints the pseudo-likelihood caveat; prefer method=:mcmle. GWESP is the usual well-behaved alternative.
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(Triangle(), net) # 3.0
change_stat(Triangle(), net, 6, 7) # 1.0 — Barbadori and Guadagni share MediciERGM.Kstar — Type
Kstar <: StructuralTerm
Kstar(k)The number of k-stars in the network (statnet's kstar(k), coefficient name "kstar<k>"). A k-star is a vertex together with k of its neighbours, so the statistic is Σᵥ C(deg(v), k).
Undirected networks only, as in R ergm (kstar "may not be used with networks with directed==TRUE"). On a directed network the model is refused at construction with an ArgumentError, and so are compute/change_stat; use OStar / IStar (statnet's ostar/istar) instead.
Fields
k::Int: Star size (number of spokes), at least 2
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(Kstar(2), net) # 47.0 — Σᵥ C(deg(v), 2)
name(Kstar(3)) # "kstar3"ERGM.OStar — Type
OStar <: StructuralTerm
OStar(k)The number of out-k-stars in a directed network (statnet's ostar(k), coefficient name "ostar<k>"): a vertex together with k of its out-neighbours, so the statistic is Σᵥ C(outdeg(v), k). Directed networks only — on an undirected network use Kstar.
Adding the arc i→j only changes i's out-degree, so the change statistic is C(outdeg⁻(i)+1, k) − C(outdeg⁻(i), k) with outdeg⁻ the out-degree in the baseline state without the arc — an O(1) computation.
Fields
k::Int: Star size (number of out-spokes), at least 2
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 2); add_edge!(net, 1, 3); add_edge!(net, 2, 3)
compute(OStar(2), net) # 1.0 — only vertex 1 has out-degree 2
compute(IStar(2), net) # 1.0 — only vertex 3 has in-degree 2
name(OStar(2)) # "ostar2"ERGM.IStar — Type
IStar <: StructuralTerm
IStar(k)The number of in-k-stars in a directed network (statnet's istar(k), coefficient name "istar<k>"): a vertex together with k of its in-neighbours, so the statistic is Σᵥ C(indeg(v), k). Directed networks only — on an undirected network use Kstar.
Adding the arc i→j only changes j's in-degree, so the change statistic is C(indeg⁻(j)+1, k) − C(indeg⁻(j), k) with indeg⁻ the in-degree in the baseline state without the arc — an O(1) computation.
Fields
k::Int: Star size (number of in-spokes), at least 2
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 3); add_edge!(net, 2, 3)
compute(IStar(2), net) # 1.0 — vertex 3 receives two arcs
compute(OStar(2), net) # 0.0
name(IStar(3)) # "istar3"ERGM.TwoPath — Type
TwoPath <: StructuralTermThe number of two-paths in the network.
For directed networks: pairs of edges (h → v, v → k) with h ≠ k (statnet's twopath/m2star). For undirected networks: the number of 2-stars, Σᵥ C(deg(v), 2) — the same statistic as Kstar(2).
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(TwoPath(), net) == compute(Kstar(2), net) # true (undirected)
compute(TwoPath(), net) # 47.0ERGM.GWESP — Type
GWESP <: StructuralTerm
GWESP(decay=0.5; type=:OTP)Geometrically Weighted Edgewise Shared Partners with fixed decay (statnet's gwesp(decay, fixed=TRUE)).
For undirected networks, shared partners of an edge (i,j) are the common neighbors of i and j; type is ignored.
For directed networks, type selects the shared-partner definition for each directed edge i→j, matching statnet's dgwesp types (the shared partner k is always distinct from i and j):
:OTP— outgoing two-path, k with i→k→j (statnet's default for directedgwesp; also the default here):ITP— incoming two-path, k with j→k→i:OSP— outgoing shared partner, k with i→k and j→k:ISP— incoming shared partner, k with k→i and k→j:union— k adjacent to both i and j in either direction. This is not a statnet type; it preserves this package's historical (pre-0.2) directed GWESP behavior and is named"gwesp.union.fixed.<decay>"so it can never be confused with statnet's OTP-based"gwesp.fixed.<decay>".
The decay must be non-negative; GWESP(0.0) is statnet's gwesp(0, fixed=TRUE) — the number of edges with at least one shared partner. Coefficient names follow R's labels exactly: an integer-valued decay prints without a decimal point ("gwesp.fixed.0", "gwesp.fixed.1"), a fractional one as is ("gwesp.fixed.0.5").
The label depends on the network's directedness, as in R. On an undirected network the coefficient is "gwesp.fixed.<decay>" (whatever type, which is ignored there). On a directed network R ergm 4.12.0 names every type — the default included — "gwesp.<type>.fixed.<decay>" (gwesp.OTP.fixed.0.5), and so does ERGM.jl wherever the network is known: ERGMModel/fit_ergm (fit.model.formula.terms.names), summary_stats and the two-argument name(term, net). The one-argument name(term), which cannot see a network, returns the undirected label for :OTP and "gwesp.<type>.fixed.<decay>" for the other types; :union is always "gwesp.union.fixed.<decay>".
fixed=false returns a different type. GWESP(decay; fixed=false) is R's spelling of gwesp(decay, fixed=FALSE), the curved term whose decay mcmle estimates, and it returns a CurvedGWESP, not a GWESP: the two are different terms (a fixed-decay statistic against a curved family), so GWESP(0.5; fixed=false) isa GWESP is false. The keyword is kept because it is R's; write CurvedGWESP(decay) where the type matters. With the default fixed=true the result is always a GWESP.
Fields
decay::Float64: Decay parameter, ≥ 0 (higher = less downweighting)type::Symbol: Directed shared-partner type (see above)
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(GWESP(0.5), net) # 8.3934... (statnet: summary(flomarriage ~ gwesp(0.5, fixed=TRUE)))
compute(GWESP(0.0), net) # 8.0 — edges with ≥ 1 shared partner
name(GWESP(0.0)) # "gwesp.fixed.0"
name(GWESP(0.5), net) # "gwesp.fixed.0.5" — undirected label
dnet = network(4; directed=true); add_edge!(dnet, 1, 2); add_edge!(dnet, 2, 3)
name(GWESP(0.5), dnet) # "gwesp.OTP.fixed.0.5" — R's directed label
GWESP(0.5; fixed=false) isa CurvedGWESP # true — the curved term, a different typeERGM.GWDSP — Type
GWDSP <: StructuralTerm
GWDSP(decay=0.5; type=:OTP)Geometrically Weighted Dyadwise Shared Partners with fixed decay (statnet's gwdsp(decay, fixed=TRUE)): the shared-partner analogue of GWESP summed over all dyads — tied or not — instead of over edges only.
For undirected networks the statistic sums eᵅ(1 − (1 − e⁻ᵅ)^dsp(i,j)) over all unordered dyads {i,j}, where dsp(i,j) is the number of common neighbors of i and j; type is ignored.
For directed networks, type selects the shared-partner definition, matching statnet's dgwdsp types (the shared partner k is always distinct from i and j). As in statnet's C implementation (ddsp), every directed type is summed over all ordered dyads (i, j), i ≠ j — including the symmetric :OSP/:ISP counts, so each unordered pair {i, j} contributes twice (R ergm 4.12.0 on samplike: gwdsp.OSP.fixed.0.5 = 316.085, gwdsp.ISP.fixed.0.5 = 229.136; pinned by the provenanced fixture):
:OTP— outgoing two-path, k with i→k→j (statnet's default for directed networks; also the default here). For dyadwise shared partners:OTPand:ITPyield the same statistic.:ITP— incoming two-path, k with j→k→i:OSP— outgoing shared partner, k with i→k and j→k (symmetric in i and j, hence counted for both (i, j) and (j, i)):ISP— incoming shared partner, k with k→i and k→j (likewise):union— k adjacent to both i and j in either direction, summed over unordered dyads. This is not a statnet type; it mirrorsGWESP's:unionand is named"gwdsp.union.fixed.<decay>".
The decay must be non-negative; GWDSP(0.0) is statnet's gwdsp(0, fixed=TRUE) — the number of dyads with at least one shared partner. Coefficient names follow R's labels ("gwdsp.fixed.0", "gwdsp.fixed.0.5"), and — exactly as for GWESP — the label is direction-aware wherever the network is known: "gwdsp.fixed.<decay>" on an undirected network, "gwdsp.<type>.fixed.<decay>" (gwdsp.OTP.fixed.0.5 for the default) on a directed one, in ERGMModel, summary_stats and name(term, net).
Fields
decay::Float64: Decay parameter, ≥ 0 (higher = less downweighting)type::Symbol: Directed shared-partner type (see above)
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(GWDSP(0.0), net) # 43.0 — dyads with ≥ 1 shared partner
name(GWDSP(0.0)) # "gwdsp.fixed.0"ERGM.GWDegree — Type
GWDegree <: StructuralTerm
GWDegree(decay=0.5)Geometrically Weighted Degree distribution with fixed decay (statnet's gwdegree(decay, fixed=TRUE), coefficient name "gwdeg.fixed.<decay>" — R's label, with an integer-valued decay printed without a decimal point).
Undirected networks only, as in R ergm (gwdegree "may not be used with networks with directed==TRUE"). On a directed network the model is refused at construction with an ArgumentError, and so are compute/change_stat; use GWODegree / GWIDegree instead.
The decay must be non-negative; GWDegree(0.0) is statnet's gwdegree(0, fixed=TRUE) — the number of non-isolated vertices.
Before 0.2 a directed network silently received the out-degree statistic under the label gwdegree.fixed.<decay>, and the undirected coefficient was labelled gwdegree.fixed.<decay> where R writes gwdeg.fixed.<decay>.
fixed=false returns a different type, as for GWESP: GWDegree(decay; fixed=false) (R's gwdegree(decay, fixed=FALSE)) returns a CurvedGWDegree, whose decay mcmle estimates, not a GWDegree.
Fields
decay::Float64: Decay parameter, ≥ 0
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(GWDegree(0.0), net) # 15.0 — every family but Pucci has a tie
name(GWDegree(0.5)) # "gwdeg.fixed.0.5"
name(GWDegree(1.0)) # "gwdeg.fixed.1"
GWDegree(0.5; fixed=false) isa CurvedGWDegree # true — the curved termERGM.GWIDegree — Type
GWIDegree <: StructuralTerm
GWIDegree(decay=0.5)Geometrically Weighted In-Degree distribution with fixed decay (statnet's gwidegree(decay, fixed=TRUE)). Only defined for directed networks; the coefficient is named "gwideg.fixed.<decay>" as in statnet (an integer-valued decay prints without a decimal point). The decay must be non-negative; GWIDegree(0.0) counts the vertices with in-degree ≥ 1.
Fields
decay::Float64: Decay parameter, ≥ 0
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 2); add_edge!(net, 1, 3); add_edge!(net, 2, 3)
compute(GWIDegree(0.0), net) # 2.0 — vertices 2 and 3 receive arcs
name(GWIDegree(0.5)) # "gwideg.fixed.0.5"ERGM.GWODegree — Type
GWODegree <: StructuralTerm
GWODegree(decay=0.5)Geometrically Weighted Out-Degree distribution with fixed decay (statnet's gwodegree(decay, fixed=TRUE)). Only defined for directed networks; the coefficient is named "gwodeg.fixed.<decay>" as in statnet (an integer-valued decay prints without a decimal point). The decay must be non-negative; GWODegree(0.0) counts the vertices with out-degree ≥ 1.
Fields
decay::Float64: Decay parameter, ≥ 0
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 2); add_edge!(net, 1, 3); add_edge!(net, 2, 3)
compute(GWODegree(0.0), net) # 2.0 — vertices 1 and 2 send arcs
name(GWODegree(1.0)) # "gwodeg.fixed.1"ERGM.Degree — Type
Degree <: StructuralTerm
Degree(d)
Degree(ds)The number of vertices with degree exactly d (statnet's degree(d), coefficient name "degree<d>"). Only defined for undirected networks, as in R ergm — use IDegree / ODegree for directed networks (the model is refused at construction otherwise, and so are compute/change_stat).
As in statnet, a vector (or range) of degrees is one term that expands into one statistic per degree when the model is built: Degree(0:2) in a term list becomes degree0, degree1, degree2 in the fit, exactly like a multi-level NodeFactor. The unexpanded multi-degree term is a specification, not a statistic — compute(Degree(0:2), net) throws; use summary_stats or build the model.
fit_ergm(net, [Edges(), Degree(0:2)]) # coefficients edges, degree0, degree1, degree2Fields
degrees::Vector{Int}: The degree(s) counted
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(Degree(0), net) # 1.0 — Pucci is isolated
summary_stats(net, [Degree(0:2)]) # (degree0 = 1.0, degree1 = 4.0, degree2 = 2.0)
name(Degree(1)) # "degree1"
Degree(0:2) == Degree([0, 1, 2]) # trueERGM.IDegree — Type
IDegree <: StructuralTerm
IDegree(d)
IDegree(ds)The number of vertices with in-degree exactly d (statnet's idegree(d), coefficient name "idegree<d>"). Only defined for directed networks.
As in statnet, a vector (or range) of degrees is one term that expands into one statistic per degree when the model is built: IDegree(0:2) becomes idegree0, idegree1, idegree2 (see Degree); the unexpanded multi-degree term is not a statistic and compute refuses it.
Fields
degrees::Vector{Int}: The in-degree(s) counted
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 2); add_edge!(net, 1, 3); add_edge!(net, 2, 3)
compute(IDegree(0), net) # 1.0 — vertex 1 receives nothing
summary_stats(net, [IDegree(0:2)]) # (idegree0 = 1.0, idegree1 = 1.0, idegree2 = 1.0)ERGM.ODegree — Type
ODegree <: StructuralTerm
ODegree(d)
ODegree(ds)The number of vertices with out-degree exactly d (statnet's odegree(d), coefficient name "odegree<d>"). Only defined for directed networks.
As in statnet, a vector (or range) of degrees is one term that expands into one statistic per degree when the model is built: ODegree(0:2) becomes odegree0, odegree1, odegree2 (see Degree); the unexpanded multi-degree term is not a statistic and compute refuses it.
Fields
degrees::Vector{Int}: The out-degree(s) counted
Example
using ERGM
net = network(3; directed=true)
add_edge!(net, 1, 2); add_edge!(net, 1, 3); add_edge!(net, 2, 3)
compute(ODegree(2), net) # 1.0 — vertex 1 sends two arcs
summary_stats(net, [ODegree(0:2)]) # (odegree0 = 1.0, odegree1 = 1.0, odegree2 = 1.0)ERGM.GWNSP — Type
GWNSP <: StructuralTerm
GWNSP(decay=0.5; type=:OTP)Geometrically weighted non-edgewise shared partners with fixed decay (statnet's gwnsp(decay, fixed=TRUE) / dgwnsp(decay, fixed=TRUE, type=)): the geometrically weighted count of shared partners over the dyads that are NOT ties, i.e. GWDSP(decay) − GWESP(decay) for the same shared-partner type (:OTP, :ITP, :OSP, :ISP on a directed network; ignored on an undirected one). Coefficient names follow R: "gwnsp.fixed.0.5" on an undirected network, "gwnsp.OTP.fixed.0.5" on a directed one (name(term, net)).
Fields
decay::Float64: Decay parameter, ≥ 0type::Symbol: Directed shared-partner type
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(GWNSP(0.5), net) # 36.1804... — R: summary(flomarriage ~ gwnsp(0.5, fixed=TRUE))
compute(GWNSP(0.0), net) # 35.0 — non-tied dyads with ≥ 1 shared partner
compute(GWNSP(0.5), net) ≈ compute(GWDSP(0.5), net) - compute(GWESP(0.5), net) # trueERGM.ESP — Type
ESP <: StructuralTerm
ESP(k; type=:OTP)
ESP(ks; type=:OTP)Edgewise shared partners (statnet's esp(d) / desp(d, type=)): the number of ties with exactly k shared partners. On an undirected network the shared partners of a tie {i,j} are the common neighbours of i and j; on a directed network type selects R's shared-partner configuration of the arc i→j, as for GWESP: :OTP (i→v→j, the default), :ITP (j→v→i), :OSP (i→v and j→v) or :ISP (v→i and v→j). R's fifth type, "RTP", is not implemented and is refused.
As in statnet, a vector (or range) of counts is one term that expands into one statistic per count when the model is built, like Degree: ESP(0:2) becomes esp0, esp1, esp2. The unexpanded term is a specification, not a statistic — compute(ESP(0:2), net) throws; use summary_stats or build the model. Coefficient names are R's: "esp<k>" on an undirected network and "esp.<type><k>" on a directed one (name(term, net); the one-argument name gives the undirected label for :OTP). The counts must be distinct and non-negative.
ESP(k) is the k-th term of the shared-partner distribution that GWESP weights geometrically: GWESP(α) = Σₖ eᵅ(1 − (1 − e⁻ᵅ)ᵏ)·ESP(k). Its attainable range is R's, (0, Inf): an observed count of 0 fixes the coefficient at -Inf (R's drop=TRUE).
Fields
ks::Vector{Int}: The shared-partner count(s)type::Symbol: Directed shared-partner type (ignored on an undirected network)
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(ESP(0), net) # 12.0 — R: summary(flomarriage ~ esp(0))
summary_stats(net, [ESP(0:2)]) # (esp0 = 12.0, esp1 = 7.0, esp2 = 1.0)
name(ESP(1)) # "esp1"
dnet = network(3; directed=true); add_edge!(dnet, 1, 2); add_edge!(dnet, 2, 3); add_edge!(dnet, 1, 3)
name(ESP(1), dnet) # "esp.OTP1" — R's directed label
compute(ESP(1), dnet) # 1.0 — the arc 1→3 has the two-path 1→2→3ERGM.Concurrent — Type
Concurrent <: StructuralTerm
Concurrent()The number of vertices with degree two or more — the number of actors with concurrent partnerships (statnet's concurrent, coefficient name "concurrent"; Morris & Kretzschmar's concurrency term of the tergm/msm models). Undirected networks only, as in R: the model is refused on a directed network, and so are compute/change_stat.
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(Concurrent(), net) # 11.0 — R: summary(flomarriage ~ concurrent)
name(Concurrent()) # "concurrent"ERGM.DegRange — Type
DegRange <: StructuralTerm
DegRange(from, to=Inf)The number of vertices whose degree d satisfies from ≤ d < to (statnet's degrange(from, to); coefficient name "deg<from>+" when to is infinite, "deg<from>to<to>" otherwise). Undirected networks only — use IDegRange / ODegRange on a directed one.
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(DegRange(2), net) # 11.0 — degree ≥ 2
compute(DegRange(1, 3), net) # 6.0 — degree 1 or 2
name(DegRange(1, 3)) # "deg1to3"ERGM.IDegRange — Type
IDegRange <: StructuralTerm
IDegRange(from, to=Inf)The number of vertices whose in-degree d satisfies from ≤ d < to (statnet's idegrange; "ideg<from>+" / "ideg<from>to<to>"). Directed networks only.
Example
using ERGM
net = network(4; directed=true); add_edges!(net, [(1, 3), (2, 3), (4, 3), (3, 1)])
compute(IDegRange(2), net) # 1.0 — vertex 3 receives three arcs
name(IDegRange(1, 2)) # "ideg1to2"ERGM.ODegRange — Type
ODegRange <: StructuralTerm
ODegRange(from, to=Inf)The number of vertices whose out-degree d satisfies from ≤ d < to (statnet's odegrange; "odeg<from>+" / "odeg<from>to<to>"). Directed networks only.
Example
using ERGM
net = network(4; directed=true); add_edges!(net, [(1, 2), (1, 3), (1, 4), (2, 1)])
compute(ODegRange(2), net) # 1.0 — vertex 1 sends three arcs
compute(ODegRange(1, 2), net) # 1.0 — vertex 2 sends oneERGM.MeanDeg — Type
MeanDeg <: StructuralTerm
MeanDeg()The mean vertex degree (statnet's meandeg, coefficient name "meandeg"): 2·edges/n on an undirected network and edges/n on a directed one (mean out-degree), so its coefficient is the edges coefficient on a size-invariant scale. Dyad-independent.
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(MeanDeg(), net) # 2.5 — 2·20/16ERGM.Density — Type
Density <: StructuralTerm
Density()The network density, edges / n_dyads (statnet's density, coefficient name "density"), with n_dyads = n(n−1)/2 undirected and n(n−1) directed. Dyad-independent.
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(Density(), net) # 0.1667 — 20/120ERGM.Sender — Type
Sender <: StructuralTerm
Sender(; nodes=nothing)
Sender(node::Integer)Sender (out-degree) effects (statnet's sender): one statistic per vertex k, the out-degree of k ("sender<k>"), whose coefficient is that vertex's propensity to send ties — the p1/p2 sender effect. By default every vertex but the first (R's nodes=-1, the base) gets one, so the edges term stays identifiable; nodes= names the vertices explicitly. Directed networks only. Dyad-independent.
Like a multi-level NodeFactor, the vertex set is resolved and expanded into one statistic per vertex when the model is built; Sender(k) is a single statistic.
Example
using ERGM
net = network(3; directed=true); add_edges!(net, [(1, 2), (1, 3), (3, 2)])
summary_stats(net, [Sender()]) # (sender2 = 0.0, sender3 = 1.0)
compute(Sender(1), net) # 2.0ERGM.Receiver — Type
Receiver <: StructuralTerm
Receiver(; nodes=nothing)
Receiver(node::Integer)Receiver (in-degree) effects (statnet's receiver): one statistic per vertex k, the in-degree of k ("receiver<k>") — the p1/p2 receiver effect. By default every vertex but the first; nodes= names them. Directed networks only. Dyad-independent. Expands like Sender.
Example
using ERGM
net = network(3; directed=true); add_edges!(net, [(1, 2), (1, 3), (3, 2)])
summary_stats(net, [Receiver()]) # (receiver2 = 2.0, receiver3 = 1.0)ERGM.TriadCensus — Type
TriadCensus <: StructuralTerm
TriadCensus()
TriadCensus(levels)The triad census (statnet's triadcensus(levels)): the number of triads of each type. On a directed network the 16 Holland–Leinhardt MAN types in R's order (003, 012, 102, 021D, 021U, 021C, 111D, 111U, 030T, 030C, 201, 120D, 120U, 120C, 210, 300); on an undirected one the 4 types 0–3 (number of ties in the triad). levels are R's 0-based type indices; the default drops type 0 (003 / 0), whose count is determined by the others, as R does. Coefficient names are "triadcensus.<type>".
Like Degree(0:2), a multi-level TriadCensus is one term that expands into one statistic per level when the model is built; a single level (TriadCensus(3)) is itself a statistic. The change statistic visits the n − 2 triads containing the toggled dyad.
Example
using ERGM
using ERGM: TriadCensus # public, not exported (Siena.jl exports a GOF TriadCensus)
net = load_dataset(:florentine_marriage)
summary_stats(net, [TriadCensus()]) # (triadcensus.1 = 195.0, triadcensus.2 = 38.0, triadcensus.3 = 3.0)
compute(TriadCensus(3), net) == compute(Triangle(), net) # trueERGM.TransitiveTies — Type
TransitiveTies <: StructuralTerm
TransitiveTies()The number of ties i→j that close at least one transitive two-path i→k→j (statnet's transitiveties, coefficient name "transitiveties") — the term of Goodreau's tergm tutorial and of many directed friendship models. It is GWESP(0; type=:OTP) under R's own name: ties with one or more outgoing-two-path shared partners. On an undirected network it is the number of ties with at least one shared partner.
Example
using ERGM
net = load_dataset(:sampson)
compute(TransitiveTies(), net) # 69.0 — R: summary(samplike ~ transitiveties)
compute(TransitiveTies(), net) == compute(GWESP(0.0), net) # trueERGM.CyclicalTies — Type
CyclicalTies <: StructuralTerm
CyclicalTies()The number of ties i→j that close at least one cyclical two-path j→k→i (statnet's cyclicalties, coefficient name "cyclicalties"): ties with one or more incoming-two-path shared partners, GWESP(0; type=:ITP) under R's name. On an undirected network it coincides with TransitiveTies, as in R.
Example
using ERGM
net = load_dataset(:sampson)
compute(CyclicalTies(), net) # 62.0 — R: summary(samplike ~ cyclicalties)
name(CyclicalTies()) # "cyclicalties"ERGM.CurvedGWESP — Type
CurvedGWESP <: StructuralTerm
CurvedGWESP(decay=0.5; type=:OTP)
GWESP(decay; fixed=false)Geometrically weighted edgewise shared partners with the decay estimated — statnet's gwesp(decay, fixed=FALSE). The term contributes two coefficients, named as R names them: "gwesp" (the coefficient of the statistic at the fitted decay) and "gwesp.decay"; on a directed network "gwesp.<type>" / "gwesp.<type>.decay". decay is the starting value (the MPLE start is the fixed-decay model's at this value). Fitted by mcmle only — a curved term is not a single statistic, so compute/change_stat, mple and the samplers refuse it; simulate and assess a curved model through its fitted result (simulate_ergm(fit), gof(fit)), which holds the statistic at the fitted decay.
Example
using ERGM
t = GWESP(0.25; fixed=false)
t isa CurvedGWESP # true
name(t) # "gwesp"
is_dyad_dependent(t) # trueERGM.CurvedGWDegree — Type
CurvedGWDegree <: StructuralTerm
CurvedGWDegree(decay=0.5)
GWDegree(decay; fixed=false)Geometrically weighted degree with the decay estimated — statnet's gwdegree(decay, fixed=FALSE) (undirected networks). Two coefficients, "gwdegree" and "gwdegree.decay", as in R; fitted by mcmle only (see CurvedGWESP).
Example
using ERGM
t = GWDegree(0.5; fixed=false)
t isa CurvedGWDegree # true
name(t) # "gwdegree"ERGM.Offset — Type
Offset <: AbstractERGMTerm
Offset(term, coef)A term whose coefficient is fixed at coef, not estimated — statnet's offset(term) with offset.coef = coef. The statistic is term's; the coefficient name is "offset(<name>)". A multi-statistic term (a multi-level NodeFactor, NodeMatch(attr; diff=true) levels, Degree(0:2), …) takes one coef per statistic, or one coef for all.
Two kinds of fixed coefficient:
- A finite offset — e.g.
Offset(Edges(), -log(n)), the network-size adjustment of egocentric and size-invariant models: the coefficient enters every likelihood, simulation and log-likelihood at its fixed value. - An infinite offset is a constraint on the sample space.
coef = -Infforbids every tie that would raise the statistic — a structural zero, e.g.Offset(NodeMix(:Grade, 7, 8), -Inf), or a same-sexOffset(NodeMatch(:sex; diff=true, level="F"), -Inf)in a heterosexual partnership network — andcoef = +Infforces every tie that would raise it (on a statistic a tie can lower, the roles swap). The pseudo-likelihood drops the dyads so fixed, the samplers never move against the constraint, and the log-likelihood is the conditional one given the constraint (R's convention). An observed network that violates the constraint has probability 0 under the model and is refused with anArgumentError(R fits it regardless). The statistic may be dyad-dependent (Offset(Triangle(), -Inf): no tie may close a triangle); anmcmlefit then reports no log-likelihood, AIC or BIC (NaN, said inshowandapproximations): such a constraint has no dyad-independent reference to bridge from.
Fits report an offset as R does: the fixed value, standard error 0, and a note that it is not estimated; dof and AIC/BIC count only the estimated coefficients (and, with an infinite offset, BIC's sample size is the dyads the offset leaves free — R's logLik nobs). Offsets work in mple (including se=:bootstrap), mcmle (including missing=:mle), simulate_ergm and gof.
Example
using ERGM
net = load_dataset(:faux_mesa_high)
fit = fit_ergm(net, [Offset(Edges(), -5.0), NodeMatch(:Grade)])
coef(fit)[1] # -5.0: fixed
name(Offset(Edges(), -5.0)) # "offset(edges)"
# Structural zeros: grade 7 has no tie to grades 8 and 9, and cannot have one
zero = fit_ergm(net, [Edges(), NodeMatch(:Grade), Offset(NodeMix(:Grade, 7, 8), -Inf),
Offset(NodeMix(:Grade, 7, 9), -Inf)])
round.(coef(zero)[1:2]; digits=3) # [-5.671, 2.468] — R ergm's fitNodal Attribute Terms
Terms incorporating vertex-level attributes.
ERGM.NodeFactor — Type
NodeFactor <: NodalTerm
NodeFactor(attr; levels=nothing, base=1, level=nothing)Main effect of a categorical vertex attribute (R ergm's nodefactor): for each included attribute level, the number of times a vertex with that level appears as an endpoint of an edge. As in statnet, an edge within the level counts twice, and one statistic is produced per included level (named "nodefactor.<attr>.<level>"); the levels are resolved from the network at model construction, where the term expands into its per-level statistics.
Which levels are included follows statnet:
- By default the first level is dropped (
base=1): the levels are the sorted distinct attribute values, and the lowest acts as the reference category. Including all levels would make the term collinear withEdges. basegives the indices (into the sorted levels) to drop;base=0keeps every level.levelsgives the included attribute values explicitly, in order, overridingbase.level=xconstructs a single-level term directly (one statistic, no expansion), equivalent tolevels=[x].
NodeFactor(attr) previously produced a single statistic counting the endpoint appearances of every vertex with the attribute — collinear with Edges by construction. It now matches statnet: one statistic per attribute level, with the first (sorted) level dropped as the reference. Pass base=0 to keep all levels.
Before expansion (e.g. compute on a term that has not been through model construction), a multi-level term evaluates to the sum of its per-level statistics.
Fields
attr::Symbol: Vertex attribute namelevel::Any: Single level counted (nothingfor a multi-level term)levels::Union{Nothing, Vector{Any}}: Explicit included levelsbase::Vector{Int}: Sorted-level indices dropped (default[1])
Example
using ERGM
net = load_dataset(:florentine_marriage)
rich = Dict(v => (w > 40 ? "rich" : "poor") for (v, w) in get_vertex_attribute(net, :wealth))
set_vertex_attribute!(net, :class, rich)
fit = fit_ergm(net, [Edges(), NodeFactor(:class)])
fit.model.formula.terms.names # ["edges", "nodefactor.class.rich"] — "poor" is the reference
compute(NodeFactor(:class; level="rich"), net) # 23.0 — endpoint appearances (R: nodefactor.class.rich 23)ERGM.NodeCov — Type
NodeCov <: NodalTerm
NodeCov(attr; transform=:none)Main effect of a continuous vertex attribute (R ergm's nodecov): the sum of the attribute values of both endpoints over the edges, named "nodecov.<attr>".
The attribute must be set on every vertex: as in statnet (which refuses NA attribute values), ERGMModel throws an ArgumentError naming the term, the attribute and the vertices without a value, and a direct compute/change_stat on incomplete data throws rather than zero-filling.
Fields
attr::Symbol: Vertex attribute nametransform::Symbol: Optional transform of each vertex's value before summing —:none(default),:log(log(x + 1)) or:sqrt. Any other symbol is anArgumentError(it used to fall back silently to:none).
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(NodeCov(:wealth), net) # 2168.0
name(NodeCov(:wealth; transform=:log)) # "nodecov.wealth"ERGM.NodeMatch — Type
NodeMatch <: NodalTerm
NodeMatch(attr; diff=false, level=nothing, levels=nothing)Homophily effect: the number of edges whose endpoints have matching values of the vertex attribute attr (R ergm's nodematch).
With diff=false (uniform homophily, the default) this is a single statistic counting all matched edges, named "nodematch.<attr>".
With diff=true (differential homophily, R's nodematch(attr, diff=TRUE)) there is one statistic per attribute level, each counting only the edges matched on that level and named "nodematch.<attr>.<level>". NodeMatch(attr; diff=true) is a specification that model construction expands into one statistic per level — every sorted level of the attribute, as R's default levels=NULL does, or the levels listed in levels= — exactly as NodeFactor and NodeMix expand. level=x builds the single statistic of level x directly. Before expansion (e.g. compute on the specification itself) the statistic is the sum over the included levels.
A level whose matched count is at its smallest attainable value (no within-level tie) has no finite estimate: the fit fixes its coefficient at -Inf and estimates the rest, as R's ergm() does — the Goodreau model of the statnet tutorial, edges + nodematch("Race", diff=TRUE) + … on faux.mesa.high, is typed as in R.
diff=true previously counted mismatched edges — a different model from R's nodematch(diff=TRUE) under the same keyword. That statistic is now available as NodeMismatch.
Fields
attr::Symbol: Vertex attribute namediff::Bool: Differential (per-level) homophily as in Rlevel::Any: The single level counted (nothingfor the uniform term or a multi-level specification)levels::Union{Nothing,Vector{Any}}: The included levels of a multi-level specification (nothing: every level)
Example
using ERGM
net = load_dataset(:florentine_marriage)
rich = Dict(v => (w > 40 ? "rich" : "poor") for (v, w) in get_vertex_attribute(net, :wealth))
set_vertex_attribute!(net, :class, rich)
compute(NodeMatch(:class), net) # 7.0 — within-class ties (R: nodematch.class 7)
summary_stats(net, [NodeMatch(:class; diff=true)]) # (nodematch.class.poor = 2.0, nodematch.class.rich = 5.0)
compute(NodeMatch(:class; diff=true, level="rich"), net) # 5.0
fit = fit_ergm(net, [Edges(), NodeMatch(:class; diff=true)])
fit.model.formula.terms.names # ["edges", "nodematch.class.poor", "nodematch.class.rich"]ERGM.NodeMismatch — Type
NodeMismatch <: NodalTerm
NodeMismatch(attr)Heterophily effect: the number of edges whose endpoints have different (non-missing) values of the vertex attribute attr. Named "nodemismatch.<attr>".
This is the statistic that NodeMatch(attr; diff=true) computed before 0.2; it has no R ergm equivalent under the nodematch name (R's diff=TRUE is per-level homophily — see NodeMatch).
Fields
attr::Symbol: Vertex attribute name
Example
using ERGM
net = load_dataset(:florentine_marriage)
rich = Dict(v => (w > 40 ? "rich" : "poor") for (v, w) in get_vertex_attribute(net, :wealth))
set_vertex_attribute!(net, :class, rich)
compute(NodeMismatch(:class), net) + compute(NodeMatch(:class), net) == 20.0 # trueERGM.NodeMix — Type
NodeMix <: NodalTerm
NodeMix(attr; levels=nothing, levels2=-1)
NodeMix(attr, l1, l2)Mixing-matrix cell counts for a categorical vertex attribute (R ergm's nodemix): one statistic per mixing cell, counting the edges whose endpoint levels fall in that cell, named "mix.<attr>.<l1>.<l2>".
The cells follow statnet's level ordering. With sorted levels u₁ < u₂ < …:
- undirected networks use the unordered cells
(uᵢ, uⱼ)withi ≤ j, in column-major order:(u₁,u₁), (u₁,u₂), (u₂,u₂), (u₁,u₃), … - directed networks use all ordered (tail-level, head-level) cells in column-major order:
(u₁,u₁), (u₂,u₁), …, (u₁,u₂), …
and statnet's reference handling: by default the first cell is dropped (levels2=-1), acting as the reference category. levels2 selects cells by index into the ordered cell list — all-negative values drop those cells, all-positive values keep exactly those cells (in the given order), and levels2=0 keeps every cell. levels restricts (and orders) the attribute levels used to build the cells.
Like NodeFactor, the cells are resolved from the network at model construction, where the term expands into its per-cell statistics; NodeMix(attr, l1, l2) constructs a single-cell term directly. Before expansion, a multi-cell term evaluates to the sum of its selected cells.
Fields
attr::Symbol: Vertex attribute namel1::Any,l2::Any: The cell's levels (nothingfor a multi-cell term); for directed networksl1is the tail (sender) level andl2the head (receiver) levellevels::Union{Nothing, Vector{Any}}: Levels used to build the cellslevels2::Vector{Int}: Cell selection (see above)
Example
using ERGM
net = load_dataset(:florentine_marriage)
rich = Dict(v => (w > 40 ? "rich" : "poor") for (v, w) in get_vertex_attribute(net, :wealth))
set_vertex_attribute!(net, :class, rich)
fit = fit_ergm(net, [Edges(), NodeMix(:class)])
fit.model.formula.terms.names # ["edges", "mix.class.poor.rich", "mix.class.rich.rich"]
compute(NodeMix(:class, "poor", "rich"), net) # 13.0 — cross-class ties (R: mix.class.poor.rich 13)ERGM.AbsDiff — Type
AbsDiff <: NodalTerm
AbsDiff(attr; pow=1)Absolute difference in a continuous attribute between edge endpoints (R ergm's absdiff): Σ_edges |xᵢ − xⱼ|^pow, named "absdiff.<attr>" for pow = 1 and "absdiff<pow>.<attr>" otherwise (absdiff2.wealth, absdiff0.5.wealth — R's labels, so two powers of one attribute in a formula print distinct names; pinned by the provenanced fixture).
The attribute must be set on every vertex: as in statnet, ERGMModel throws an ArgumentError naming the vertices without a value, and a direct compute/change_stat on incomplete data throws rather than zero-filling.
Fields
attr::Symbol: Vertex attribute namepow::Float64: Power to raise the difference to (default 1; anyRealis accepted and stored as aFloat64, so R'sabsdiff("wealth", pow=2)isAbsDiff(:wealth; pow=2))
Example
using ERGM
net = load_dataset(:florentine_marriage)
compute(AbsDiff(:wealth), net) # 1146.0
compute(AbsDiff(:wealth; pow=2), net) # 91570.0 (R: summary(flomarriage ~ absdiff("wealth", pow=2)))
name(AbsDiff(:wealth; pow=2)) # "absdiff2.wealth"Dyadic Terms
Terms based on dyad-level covariates.
ERGM.EdgeCov — Type
EdgeCov <: DyadicTermDyad-level covariate effect (statnet edgecov): the sum of the covariate over the edges present. Built from an n×n matrix (EdgeCov(M; name="edgecov"); undirected networks read the (min, max) entry) or from an edge attribute (EdgeCov(net, :attr)). Dyad-independent.
The matrix must be n×n for the network it is used on: ERGMModel/ fit_ergm, compute and change_stat all throw an ArgumentError naming the sizes otherwise (a matrix built for another network is the commonest edgecov slip, and a BoundsError would not say so).
Fields
covariate::Matrix{Float64}: n×n matrix of dyad covariatesname_str::String: Name for this term
Example
using ERGM
net = load_dataset(:florentine_marriage)
w = get_vertex_attribute(net, :wealth)
M = [Float64(abs(w[i] - w[j])) for i in 1:16, j in 1:16] # wealth gap per dyad
term = EdgeCov(M; name="edgecov.wealthgap")
compute(term, net) == compute(AbsDiff(:wealth), net) # true
name(term) # "edgecov.wealthgap"Term Traits
The public protocol by which a term — ERGM.jl's own or a third party's — declares what it needs and where it belongs. ERGM.jl acts on the declarations when an ERGMModel is constructed: a term whose declared vertex/edge attributes are absent from the network, or whose direction requirement the network does not meet, is rejected with an ArgumentError instead of silently contributing an all-zero design column.
ERGM.required_vertex_attributes — Function
required_vertex_attributes(term::AbstractERGMTerm) -> Tuple{Vararg{Symbol}}The vertex attributes the term needs on the network, as a tuple of symbols (empty for terms that read none — the default).
A term whose statistic reads a vertex attribute must declare it. ERGM.jl checks the declaration against list_vertex_attributes(net) when an ERGMModel is built and throws an ArgumentError if the attribute is absent, because the alternative is silent nonsense: get_vertex_attribute returns an empty Dict for an unknown attribute, so an undeclared attribute-based term would quietly evaluate to an all-zero design column and a meaningless coefficient.
Declared attributes are also what makes a term eligible for attribute materialization (dense typed snapshots; ERGM's own nodal terms only).
Example
struct Homophily <: AbstractERGMTerm
attr::Symbol
end
ERGM.required_vertex_attributes(t::Homophily) = (t.attr,)See also required_edge_attributes, requires_directed, is_dyad_dependent.
ERGM.required_edge_attributes — Function
required_edge_attributes(term::AbstractERGMTerm) -> Tuple{Vararg{Symbol}}The edge (dyad) attributes the term needs on the network, as a tuple of symbols (empty by default). Validated against list_edge_attributes(net) at model construction exactly like required_vertex_attributes.
Declare an edge attribute only when its absence is an error. A term that falls back to a default weight for edges without the attribute (as ERGMUserterms.WeightedEdges does) genuinely does not require it and must not declare it — otherwise a perfectly meaningful model would be rejected.
None of ERGM.jl's built-in terms declare one: EdgeCov snapshots the dyadic covariate into a matrix at construction time, so by the time the model is built the attribute is no longer needed.
Example
using ERGM
required_edge_attributes(EdgeCov(zeros(3, 3))) # ()
struct Weighted <: AbstractERGMTerm end
ERGM.required_edge_attributes(::Weighted) = (:weight,)
required_edge_attributes(Weighted()) # (:weight,)ERGM.requires_directed — Function
requires_directed(term::AbstractERGMTerm) -> BoolWhether the term is only defined for directed networks (false by default). Model construction rejects such a term on an undirected network with an ArgumentError, as R ergm does: there its statistic would be a structural zero or a silent duplicate of another term, not a model.
Built-in terms declaring true: Mutual, IStar, OStar, IDegree, ODegree, GWIDegree, GWODegree. TERGM.jl declares it for Delrecip.
See also requires_undirected.
Example
using ERGM
requires_directed(Mutual()) # true
requires_directed(Edges()) # false
try
ERGMModel(ERGMFormula([Mutual()]), load_dataset(:florentine_marriage))
catch e
e isa ArgumentError # true — refused on an undirected network
endERGM.requires_undirected — Function
requires_undirected(term::AbstractERGMTerm) -> BoolWhether the term is only defined for undirected networks (false by default). Model construction rejects such a term on a directed network with an ArgumentError, pointing at the in-/out- variant to use instead.
Built-in terms declaring true, exactly the terms R ergm refuses on a directed network: Degree (use IDegree/ODegree), Kstar (use IStar/OStar) and GWDegree (use GWIDegree/GWODegree). These three also refuse a directed network in compute/change_stat themselves, so a caller bypassing ERGMModel (a variant lifting a term to a layer or a panel) cannot silently receive the out-degree statistic under the undirected label, as happened before 0.2.
See also requires_directed.
Example
using ERGM
requires_undirected(Kstar(2)) # true
requires_undirected(OStar(2)) # false — the directed counterpartTwo further traits complete the protocol:
is_dyad_dependent— whether the change statistic reads other dyads (conservative defaulttrue); it drives the pseudo-likelihood caveat and the MCMLE bridge reference.NetworkCore.supports_missing— whether the term's statistic honours the missing-dyad mask, i.e. is invariant to the face value of a dyad marked withset_missing_dyad!(defaultfalse, the honest answer for every built-in term: they count masked dyads at face value, and the principled missing-data treatment lives in the estimator — seemple).
A third-party term declares them by adding methods:
using ERGM
using NetworkCore
struct RichClub <: AbstractERGMTerm
attr::Symbol
end
ERGM.name(t::RichClub) = "richclub.$(t.attr)"
# ... plus compute(t, net) and change_stat(t, net, i, j)
ERGM.required_vertex_attributes(t::RichClub) = (t.attr,)
ERGM.requires_directed(::RichClub) = true
ERGM.is_dyad_dependent(::RichClub) = true
NetworkCore.supports_missing(::RichClub) = falseERGMUserterms.validate_term exercises every one of these declarations against a network; ERGMUserterms.jl/examples/MyTermPackage is a complete package template built on them.