Terms API Reference
This page documents all count-specific ERGM terms available in ERGMCount.jl.
Basic Terms
SumTerm
ERGMCount.SumTerm — Type
SumTerm(; pow=1) <: AbstractERGMTermSum of edge values: ∑{i,j} y{ij} — R's sum. This is the natural sufficient statistic for the Poisson reference. SumTerm(pow=p) is R's sum(pow=p), ∑{i,j} y{ij}^p (labelled sum<p> as R prints it: sum2, sum0.5); p must be positive, and a non-integer power is refused on a network or support with negative counts (R returns NaN there). Dyad-independent; pinned against ergm 4.12 by test/fixtures/count_terms.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 2)
compute(SumTerm(), net) # 5.0
name(SumTerm()) # "sum"
compute(SumTerm(pow=2), net) # 13.0
name(SumTerm(pow=2)) # "sum2"NonzeroTerm
ERGMCount.NonzeroTerm — Type
NonzeroTerm <: AbstractERGMTermNumber of non-zero dyads: ∑{i,j} I(y{ij} ≠ 0) — R's nonzero. An edge whose :weight is 0 is a zero dyad (R stores no such edge), and a negative count (admissible under DiscUnif2Reference(a < 0, b)) is non-zero.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 0) # a zero-valued tie
compute(NonzeroTerm(), net) # 1.0 — the 0-valued edge is a zero dyad
name(NonzeroTerm()) # "nonzero"GreaterthannTerm
ERGMCount.GreaterthannTerm — Type
GreaterthannTerm <: AbstractERGMTermNumber of dyads with value > n: ∑{i,j} I(y{ij} > n) — R's greaterthan(n). The zero-valued dyads count when n < 0 (as SmallerthanTerm counts them), so GreaterthannTerm(-1) is the number of dyads.
Fields
threshold::Int: Threshold value n
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true) # 6 dyads
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 1)
compute(GreaterthannTerm(2), net) # 1.0
compute(GreaterthannTerm(-1), net) # 6.0 — every dyad, the zeros included
name(GreaterthannTerm(2)) # "greaterthan.2"CountAtleastnTerm
ERGMCount.CountAtleastnTerm — Type
CountAtleastnTerm <: AbstractERGMTermNumber of dyads with value >= n: ∑{i,j} I(y{ij} ≥ n) — R's atleast(n). The zero-valued dyads count when n ≤ 0, so CountAtleastnTerm(0) is the number of dyads.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true) # 6 dyads
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 1)
compute(CountAtleastnTerm(3), net) # 1.0
compute(CountAtleastnTerm(1), net) # 2.0
compute(CountAtleastnTerm(0), net) # 6.0 — every dyad
name(CountAtleastnTerm(3)) # "atleast.3"SmallerthanTerm
ERGMCount.SmallerthanTerm — Type
SmallerthanTerm(threshold) <: AbstractERGMTermergm's valued smallerthan(threshold): the number of dyads whose value is below the threshold, ∑{(i,j)} I(y{ij} < threshold) — zero-valued dyads included, so on a sparse network it is close to the number of dyads. R label smallerthan.<threshold>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_terms.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true) # 6 dyads
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
compute(SmallerthanTerm(2), net) # 5.0 — every dyad but (1,2)
name(SmallerthanTerm(2)) # "smallerthan.2"EqualToTerm
ERGMCount.EqualToTerm — Type
EqualToTerm(value; tolerance=0) <: AbstractERGMTermergm's valued equalto(value, tolerance): the number of dyads whose value lies within tolerance of value inclusive, ∑{(i,j)} I(|y{ij} − value| ≤ tolerance) — zero-valued dyads included. R label equalto.<value>.pm.<tolerance>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_terms.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
compute(EqualToTerm(3), net) # 1.0
compute(EqualToTerm(0), net) # 5.0 — the empty dyads
name(EqualToTerm(3)) # "equalto.3.pm.0"InIntervalTerm
ERGMCount.InIntervalTerm — Type
InIntervalTerm(lower, upper; open=(true, true)) <: AbstractERGMTermergm's valued ininterval(lower, upper, open): the number of dyads whose value lies between lower and upper, zero-valued dyads included. open says whether each end is exclusive — R's default (true, true) is the open interval (lower, upper); (false, false) is [lower, upper]. The bounds may be -Inf/Inf. R label ininterval(lower,upper) with the brackets following open (ininterval[1,3], ininterval(1,3], ...); dyad-independent; pinned against ergm 4.12 by test/fixtures/count_terms.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 1), (2, 3, 2), (3, 1, 3))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(InIntervalTerm(1, 3), net) # 1.0 — only the 2
compute(InIntervalTerm(1, 3; open=(false, false)), net) # 3.0
name(InIntervalTerm(1, 3; open=(false, true))) # "ininterval[1,3)"Covariate Terms
CountNodeMatchTerm
ERGMCount.CountNodeMatchTerm — Type
CountNodeMatchTerm(attr; level=nothing, form=:sum) <: AbstractERGMTermergm's valued nodematch(attr, form=...): the sum of the counts (form=:sum) or the number of non-zero dyads (form=:nonzero) between two actors with the same value of the vertex attribute attr. With level=v, only pairs that both have value v count — one statistic of R's nodematch(attr, diff=TRUE), which has one per level; write one term per level. R labels nodematch.sum.<attr> and nodematch.sum.<attr>.<level> (nodematch.nonzero.… for form=:nonzero); dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
set_vertex_attribute!(net, :g, ["a", "a", "b"])
for (i, j, w) in ((1, 2, 3), (2, 1, 1), (2, 3, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountNodeMatchTerm(:g), net) # 4.0 — the 1↔2 counts
compute(CountNodeMatchTerm(:g; form=:nonzero), net) # 2.0
name(CountNodeMatchTerm(:g; level="a")) # "nodematch.sum.g.a"CountNodeFactorTerm
ERGMCount.CountNodeFactorTerm — Type
CountNodeFactorTerm(attr, level; form=:sum) <: AbstractERGMTermergm's valued nodefactor(attr, form=...), one level: the sum over dyads of the count (form=:sum) or of 1[count ≠ 0] (form=:nonzero), times the number of the dyad's two actors whose attr equals level. R's nodefactor has one statistic per level except the first (its default levels=-1); write one term per level. R label nodefactor.sum.<attr>.<level>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
set_vertex_attribute!(net, :g, ["a", "b", "b"])
for (i, j, w) in ((1, 2, 3), (2, 3, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountNodeFactorTerm(:g, "b"), net) # 7.0 — 3·1 + 2·2
name(CountNodeFactorTerm(:g, "b")) # "nodefactor.sum.g.b"CountAbsDiffTerm
ERGMCount.CountAbsDiffTerm — Type
CountAbsDiffTerm(attr; form=:sum) <: AbstractERGMTermergm's valued absdiff(attr, form=...): the sum over dyads of the count (form=:sum) or of 1[count ≠ 0] (form=:nonzero), times |x_i − x_j| for the numeric vertex attribute attr (R's default pow=1). R label absdiff.sum.<attr>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=false)
set_vertex_attribute!(net, :x, [1.0, 3.0, 2.5])
for (i, j, w) in ((1, 2, 2), (2, 3, 4))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountAbsDiffTerm(:x), net) # 6.0 — 2·2 + 4·0.5
name(CountAbsDiffTerm(:x)) # "absdiff.sum.x"CountNodeCovTerm
ERGMCount.CountNodeCovTerm — Type
CountNodeCovTerm(attr; form=:sum) <: AbstractERGMTermergm's valued nodecov(attr, form=...): the sum over dyads of the count (form=:sum) or of 1[count ≠ 0] (form=:nonzero), times x_i + x_j for the numeric vertex attribute attr. R label nodecov.sum.<attr>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml. CountNodeOCovTerm and CountNodeICovTerm are its sender and receiver halves.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=false)
set_vertex_attribute!(net, :x, [1.0, 3.0, 2.5])
for (i, j, w) in ((1, 2, 2), (2, 3, 4))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountNodeCovTerm(:x), net) # 30.0 — 2·4 + 4·5.5
name(CountNodeCovTerm(:x)) # "nodecov.sum.x"ERGMCount.CountNodeOCovTerm — Type
CountNodeOCovTerm(attr; form=:sum) <: AbstractERGMTermergm's valued nodeocov(attr, form=...): the sum over dyads i→j of the count (or 1[count ≠ 0]) times the SENDER's x_i. Directed networks only (refused on an undirected one). R label nodeocov.sum.<attr>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
set_vertex_attribute!(net, :x, [1.0, 3.0, 2.5])
for (i, j, w) in ((1, 2, 2), (2, 3, 4))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountNodeOCovTerm(:x), net) # 14.0 — 2·1 + 4·3
name(CountNodeOCovTerm(:x)) # "nodeocov.sum.x"ERGMCount.CountNodeICovTerm — Type
CountNodeICovTerm(attr; form=:sum) <: AbstractERGMTermergm's valued nodeicov(attr, form=...): the sum over dyads i→j of the count (or 1[count ≠ 0]) times the RECEIVER's x_j. Directed networks only (refused on an undirected one). R label nodeicov.sum.<attr>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
set_vertex_attribute!(net, :x, [1.0, 3.0, 2.5])
for (i, j, w) in ((1, 2, 2), (2, 3, 4))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountNodeICovTerm(:x), net) # 16.0 — 2·3 + 4·2.5
name(CountNodeICovTerm(:x)) # "nodeicov.sum.x"CountEdgeCovTerm
ERGMCount.CountEdgeCovTerm — Type
CountEdgeCovTerm(W; name="W", form=:sum) <: AbstractERGMTermergm's valued edgecov(x, form=...): the sum over dyads of the count (form=:sum) or of 1[count ≠ 0] (form=:nonzero), times the dyadic covariate W[i, j] (an n×n numeric matrix; on an undirected network the entry W[min(i,j), max(i,j)], R's upper triangle). R labels the statistic by the covariate's name, edgecov.sum.<name> — pass name as R would print it (the network attribute's name for edgecov("w")). Dyad-independent; pinned against ergm 4.12 by test/fixtures/count_covariates.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 2), (2, 3, 4))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
W = [0.0 0.5 1.0; 2.0 0.0 0.25; 1.0 1.0 0.0]
compute(CountEdgeCovTerm(W; name="dist"), net) # 2.0 — 2·0.5 + 4·0.25
name(CountEdgeCovTerm(W; name="dist")) # "edgecov.sum.dist"Structural Terms
CountMutualTerm
ERGMCount.CountMutualTerm — Type
CountMutualTerm(form=:min; threshold=0) <: AbstractERGMTermValued reciprocity, ergm's valued mutual(form=, threshold=): ∑{i<j} m(y{ij}, y_{ji}) over the unordered pairs of a directed network, where form picks m:
form | m(a, b) | R label |
|---|---|---|
:min (default) | min(a, b) | mutual.min |
:nabsdiff | -abs(a - b) | mutual.nabsdiff |
:geometric | sqrt(a * b) | mutual.geom.mean |
:product | a * b | mutual.product |
:threshold | (a >= threshold) * (b >= threshold) — binary mutuality after thresholding | mutual.<threshold> |
The coefficient labels are the ones summary()/coef() print in R. The :min, :nabsdiff, :geometric and :product statistics are pinned against ergm 4.12 by test/fixtures/count_terms.toml; :threshold follows the documented definition (an empty network has every pair mutual when threshold <= 0, as R's emptynwstats records) but is not pinned, because ergm 4.12's own mutual(form="threshold") fails at C model initialisation (the error is frozen in the fixture). Every form is dyad-dependent (it reads the reciprocal dyad) and requires a directed network; an undirected CountERGMModel refuses the term.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 1, 2), (2, 3, 2), (1, 3, 1))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CountMutualTerm(), net) # 2.0 — min(3, 2)
compute(CountMutualTerm(:nabsdiff), net) # -4.0 — -(|3-2| + |2-0| + |1-0|)
compute(CountMutualTerm(:threshold; threshold=2), net) # 1.0
name(CountMutualTerm(:geometric)) # "mutual.geom.mean"TransitiveWeightsTerm
ERGMCount.TransitiveWeightsTerm — Type
TransitiveWeightsTerm() <: AbstractERGMTermergm's valued transitiveweights("min", "max", "min") (Krivitsky 2012, eq. 13, with the default triple): every dyad's value capped by the strongest two-path closing it,
∑{(i,j)} min( y{ij}, maxk min(y{ik}, y_{kj}) ),
summed over every ordered pair of a directed network and over every unordered pair of an undirected one, exactly as R's C code does (R label transitiveweights.min.max.min; pinned against ergm 4.12 on zach and on a directed count network by test/fixtures/count_terms.toml). The non-default triples (twopath="geomean", combine="sum", affect="geomean") are not implemented. Dyad-dependent: changing dyad (i, j) moves its own term and the terms of the pairs (i, l), l ∈ out(j), and (k, j), k ∈ in(i), whose strongest two-path may run through it.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 3, 2), (1, 3, 1))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(TransitiveWeightsTerm(), net) # 1.0 — pair (1,3): min(1, min(3, 2))
name(TransitiveWeightsTerm()) # "transitiveweights.min.max.min"CyclicalWeightsTerm
ERGMCount.CyclicalWeightsTerm — Type
CyclicalWeightsTerm() <: AbstractERGMTermergm's valued cyclicalweights("min", "max", "min") with the default triple: every dyad's value capped by the strongest two-path that closes a directed 3-cycle through it,
∑{(i,j)} min( y{ij}, maxk min(y{jk}, y_{ki}) ),
over every ordered pair of a directed network (R label cyclicalweights.min.max.min, pinned against ergm 4.12 by test/fixtures/count_terms.toml). On an undirected network the cycle and the transitive two-path coincide, so the statistic equals TransitiveWeightsTerm there — as in R, which allows the term on undirected networks. The non-default triples are not implemented.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 3, 2), (3, 1, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CyclicalWeightsTerm(), net) # 6.0 — each of the three dyads capped at 2
name(CyclicalWeightsTerm()) # "cyclicalweights.min.max.min"TransitiveTiesTerm
ERGMCount.TransitiveTiesTerm — Type
TransitiveTiesTerm <: AbstractERGMTermTriadic-minimum transitivity over ordered distinct triples: ∑{i≠j≠k} min(y{ij}, y{jk}, y{ik})
This statistic has no R counterpart and is not validated against R. It is not ergm's transitiveweights (that is TransitiveWeightsTerm, pinned by the count_terms fixture) and not the binary transitiveties; it sums the triple-wise minimum over every ordered triple, so on an undirected network each unordered triangle contributes six times. Use it as a simple valued transitivity when parity with R does not matter.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 3, 2), (1, 3, 1), (2, 1, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(TransitiveTiesTerm(), net) # 2.0 — triples (1,2,3) and (2,1,3)
name(TransitiveTiesTerm()) # "transitiveties.count"CyclicalTiesTerm
ERGMCount.CyclicalTiesTerm — Type
CyclicalTiesTerm <: AbstractERGMTermWeighted cyclicality: (1/3) ∑{i≠j≠k} min(y{ij}, y{jk}, y{ki}) (each directed 3-cycle counted once). Directed networks only.
This statistic has no R counterpart and is not validated against R. It is not ergm's cyclicalweights (that is CyclicalWeightsTerm, pinned by the count_terms fixture) and not the binary cyclicalties.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 3, 2), (3, 1, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
compute(CyclicalTiesTerm(), net) # 2.0 — the cycle 1→2→3→1, min(3, 2, 2)
name(CyclicalTiesTerm()) # "cyclicalties.count"Terms added from ergm / ergm.count
AtmostTerm
ERGMCount.AtmostTerm — Type
AtmostTerm(threshold) <: AbstractERGMTermNumber of dyads with value <= threshold: ∑{i,j} I(y{ij} ≤ threshold) — R's atmost(threshold). The zero-valued dyads count when threshold ≥ 0. R label atmost.<threshold>; dyad-independent; pinned against ergm 4.12 by test/fixtures/count_terms.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true) # 6 dyads
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 1)
compute(AtmostTerm(1), net) # 5.0 — the four empty dyads and (2,3)
compute(AtmostTerm(0), net) # 4.0
name(AtmostTerm(1)) # "atmost.1"CMPTerm
ERGMCount.CMPTerm — Type
CMPTerm() <: AbstractERGMTermergm.count's CMP term: ∑{i,j} log(y{ij}!). Added to a Poisson-reference model it turns each dyad's law into the Conway–Maxwell–Poisson family (a coefficient θ multiplies the reference 1/y! by (y!)^θ: under-dispersion for θ < 0, over-dispersion for 0 < θ < 1, the geometric law at θ = 1). In ergm.count this is a term, not a reference measure, and so it is here. R label CMP; dyad-independent; refused on negative counts (R returns Inf); pinned against ergm.count 4.1.3 by test/fixtures/count_terms.toml.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 2)
compute(CMPTerm(), net) ≈ log(6) + log(2) # true: log 3! + log 2!
name(CMPTerm()) # "CMP"Degree / Strength Terms
NodeOSumTerm
ERGMCount.NodeOSumTerm — Type
NodeOSumTerm <: AbstractERGMTermSum of squared out-strengths, ∑i (∑j y_{ij})²: measures activity heterogeneity. Directed networks only (0 for undirected, and a CountERGMModel refuses it there; use NodeSumTerm instead). No R counterpart (ergm's nodeocovar is a covariance, not this sum) — label nodeOSum, not validated against R.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 1, 3); set_edge_attribute!(net, :weight, 1, 3, 1)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 2)
compute(NodeOSumTerm(), net) # 20.0 — out-strengths (4, 2, 0): 16 + 4
name(NodeOSumTerm()) # "nodeOSum"NodeISumTerm
ERGMCount.NodeISumTerm — Type
NodeISumTerm <: AbstractERGMTermSum of squared in-strengths, ∑j (∑i y_{ij})²: measures popularity heterogeneity. Directed networks only (0 for undirected, and a CountERGMModel refuses it there; use NodeSumTerm instead). No R counterpart — label nodeISum, not validated against R.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 1, 3); set_edge_attribute!(net, :weight, 1, 3, 1)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 2)
compute(NodeISumTerm(), net) # 18.0 — in-strengths (0, 3, 3): 9 + 9
name(NodeISumTerm()) # "nodeISum"NodeSumTerm
ERGMCount.NodeSumTerm — Type
NodeSumTerm <: AbstractERGMTermSum of squared total (in + out) strengths, ∑i (∑j y{ij} + ∑j y_{ji})²; on an undirected network the strength of a vertex is the sum of its edge values. Defined on both directednesses. No R counterpart (ergm's nodecovar is a covariance) — label nodeSum, not validated against R.
Example
using NetworkCore, ERGMCount
using ERGM: compute, name
net = network(3; directed=false)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 2, 3); set_edge_attribute!(net, :weight, 2, 3, 1)
compute(NodeSumTerm(), net) # 26.0 — strengths (3, 4, 1): 9 + 16 + 1
name(NodeSumTerm()) # "nodeSum"Interface Functions
Count terms implement the shared ERGM.jl term interface (compute, name) plus the count-specific change statistic change_stat_count, which replaces the binary change_stat for dyads that move between arbitrary count values. The estimator and the Gibbs sampler consume the change statistics one dyad at a time over the whole count support, through the support profile change_stats_support!; its fallback calls change_stat_count per value, so a custom term needs only the latter.
compute
<!– skip-check –>
compute(term::AbstractERGMTerm, net) -> Float64Compute the full-network value of the term statistic. This is the shared ERGM.jl term interface (its docstring lives in the ERGM.jl manual); every count term in this package implements a method that reads the :weight edge attribute through the same dyad-value view the estimator uses: an edge whose :weight is 0 is a zero dyad (so nonzero does not count it, exactly as R's valued terms), and the threshold terms (greaterthan, atleast, smallerthan, equalto, ininterval) count the zero-valued dyads whenever 0 meets the threshold — GreaterthannTerm(-1) and CountAtleastnTerm(0) are the number of dyads. A CountERGMModel refuses a network with edges but no :weight at all, and one where only some edges carry a :weight (a bare edge is a data gap, not a count of 1); TransitiveWeightsTerm, CyclicalWeightsTerm and CountMutualTerm(:geometric) refuse a network with a negative count, as ergm does.
changestatcount
ERGMCount.change_stat_count — Function
change_stat_count(term, net, weights, i, j, old, new) -> Float64Change in compute(term, net) when dyad (i,j) moves from count old to count new, holding all other dyads fixed. weights is the :weight edge-attribute dictionary; hot loops should pass the typed snapshot get_edge_attribute(net, :weight, Int) (a Dict{Tuple{T,T},Int}) rather than the untyped get_edge_attribute(net, :weight) Dict.
Example
using NetworkCore, ERGMCount
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 3)
add_edge!(net, 1, 3); set_edge_attribute!(net, :weight, 1, 3, 1)
w = get_edge_attribute(net, :weight, Int)
change_stat_count(SumTerm(), net, w, 1, 2, 3, 5) # 2.0
change_stat_count(NonzeroTerm(), net, w, 1, 2, 3, 0) # -1.0
change_stat_count(NodeOSumTerm(), net, w, 1, 2, 3, 5) # 20.0 — (1+5)² − (1+3)²changestatssupport!
ERGMCount.change_stats_support! — Function
change_stats_support!(dest, term, net, weights, i, j, old, support) -> destFill dest[s] = change_stat_count(term, net, weights, i, j, old, support[s]) for every s in eachindex(support): the change-statistic profile of dyad (i, j) over its conditional support, moving from count old. dest must have length(support) elements; nothing is allocated.
The fallback evaluates change_stat_count once per support value, so any term that implements change_stat_count has a profile. Terms whose change statistic shares work across values specialise it: NodeOSumTerm, NodeISumTerm and NodeSumTerm compute the strength excluding the dyad once and fill (s + y)^2 - (s + old)^2; TransitiveTiesTerm and CyclicalTiesTerm collect the third-vertex minima c_k once and accumulate Σ_k [min(y, c_k) - min(old, c_k)] for every y in one pass, and TransitiveWeightsTerm/CyclicalWeightsTerm register one clamp ramp per affected pair (one two-path search each, not one per support value). Every specialisation is held equal to the per-value fallback by the test suite, so change_stat_count remains the definition. ERGMCount declares this function public; a custom count term needs only change_stat_count.
Example
using NetworkCore, ERGMCount
net = network(4; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 2)
add_edge!(net, 1, 3); set_edge_attribute!(net, :weight, 1, 3, 1)
weights = get_edge_attribute(net, :weight, Int)
dest = zeros(4)
ERGMCount.change_stats_support!(dest, NodeOSumTerm(), net, weights, 1, 2, 0, 0:3)
dest == [change_stat_count(NodeOSumTerm(), net, weights, 1, 2, 0, y) for y in 0:3] # truename
<!– skip-check –>
name(term::AbstractERGMTerm) -> StringReturn the term's coefficient label, the string R prints for the same term (e.g. "sum", "mutual.min", "transitiveweights.min.max.min"), used to label coefficients in fitted results. This is the shared ERGM.jl term interface (its docstring lives in the ERGM.jl manual); every count term implements a method.
dyad_value
ERGMCount.dyad_value — Function
dyad_value(net, weights, i, j) -> IntThe count value of dyad (i,j): 0 when the edge is absent, its :weight attribute when present. weights is the :weight attribute dictionary — pass the typed snapshot get_edge_attribute(net, :weight, Int) — keyed by (i, j) on a directed network and minmax(i, j) on an undirected one.
An edge without a :weight entry reads as 1 here, but no such network reaches a fit or a simulation: CountERGMModel (hence fit_ergm_count, count_mple) and simulate_count_ergm refuse a network with an edge that carries no :weight, whether none of the edges does (R's response="w" migration mistake: pass weight=:w) or only some do (a weight column with gaps), naming the first such edge.
Example
using NetworkCore, ERGMCount
net = network(3; directed=false)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 4)
w = get_edge_attribute(net, :weight, Int)
dyad_value(net, w, 1, 2) # 4
dyad_value(net, w, 2, 1) # 4 — the undirected key is minmax(2, 1)
dyad_value(net, w, 1, 3) # 0 — no edge