Types API Reference
This page documents the core data types in ERGMCount.jl.
Reference Measures
AbstractReferenceMeasure
ERGMCount.AbstractReferenceMeasure — Type
AbstractReferenceMeasureBase type for reference measures in count ERGMs.
PoissonReference
ERGMCount.PoissonReference — Type
PoissonReference(lambda=1.0)Poisson reference measure for count ERGMs. h(yij) = λ^yij / y_ij!
With this reference and a SumTerm coefficient θ, each dyad is conditionally Poisson(λ·e^θ) (Krivitsky 2012). lambda must be positive (an ArgumentError otherwise: log(λ) enters every conditional).
Fields
lambda::Float64: Rate parameter (default 1.0)
Example
using ERGMCount
ref = PoissonReference() # λ = 1: h(y) = 1/y!
log_reference(ref, 3) ≈ -log(6) # true
PoissonReference(2.0).lambda # 2.0
is_truncating(ref) # true — the support is unboundedGeometricReference
ERGMCount.GeometricReference — Type
GeometricReferenceGeometric reference measure for count ERGMs: the counting measure h(y_ij) = 1 on {0, 1, 2, …}, as in ergm.count/Krivitsky (2012). The geometric shape of the dyad distribution comes from a negative SumTerm coefficient, not from the reference itself, so this measure has no free parameter.
Example
using ERGMCount
ref = GeometricReference()
log_reference(ref, 5) # 0.0 — the counting measure
is_truncating(ref) # true — 0:max_val truncates it
ERGMCount._support(ref, 20) # 0:20BinomialReference
ERGMCount.BinomialReference — Type
BinomialReferenceBinomial reference measure for count ERGMs (for bounded counts): h(yij) = C(trials, yij), matching ergm.count's Binomial(trials). The success probability is absorbed into the estimated SumTerm coefficient rather than parameterizing the reference.
Fields
trials::Int: Number of trials (maximum count value)
Example
using ERGMCount
ref = BinomialReference(4)
log_reference(ref, 2) ≈ log(6) # true — C(4, 2) = 6
log_reference(ref, 5) # -Inf — outside the support 0:4
is_truncating(ref) # false — the bound is the model'sDiscUnifReference
ERGMCount.DiscUnifReference — Type
DiscUnifReferenceDiscrete uniform reference measure on {0, 1, ..., max}. h(y_ij) = 1/(max+1)
Fields
max::Int: Maximum value
Example
using ERGMCount
ref = DiscUnifReference(3)
log_reference(ref, 2) ≈ -log(4) # true — every value of 0:3 has weight 1/4
ERGMCount._support(ref, 30) # 0:3 — `max_val` is not consulted
is_truncating(ref) # falseDiscUnif2Reference
ERGMCount.DiscUnif2Reference — Type
DiscUnif2Reference(a, b)Discrete uniform reference on {a, a+1, ..., b}, ergm.count's DiscUnif(a, b): h(y) = 1/(b − a + 1) on the support a:b, which is part of the model (see is_truncating). a may be negative, as in R: a dyad's count is then any integer in a:b, the estimator enumerates that support, the Gibbs sampler draws from it (an edge is stored for every non-zero count, negative ones included) and NonzeroTerm counts the dyads with y ≠ 0. a may also be positive, in which case the value 0 is impossible and a network with an absent edge is refused by the fit.
Example
using NetworkCore, ERGMCount
ref = DiscUnif2Reference(-2, 2)
log_reference(ref, -1) # -log(5)
ERGMCount._support(ref, 30) # -2:2 — `max_val` is not consulted
is_truncating(ref) # falseReference Measure Traits
A reference measure with unbounded support (Poisson, geometric) must be truncated to be normalizable, so the fitted model is exact only if the mass beyond the truncation point is negligible. is_truncating declares which measures are affected and BOUNDARY_MASS_TOL is the tolerance above which the boundary mass is reported as an approximation.
ERGMCount.is_truncating — Function
is_truncating(ref::AbstractReferenceMeasure) -> BoolWhether enumerating this reference's support over 0:max_val truncates it.
true for the mathematically unbounded references (PoissonReference, GeometricReference): there the finite enumeration is a numerical device, and the fitted model is only an approximation to the documented unbounded family insofar as negligible conditional mass sits at the bound — which count_mple measures and reports (see boundary_mass on CountERGMResult).
false for the genuinely bounded references (BinomialReference, DiscUnifReference, DiscUnif2Reference), whose support is part of the model.
Example
using ERGMCount
is_truncating(PoissonReference()) # true
is_truncating(GeometricReference()) # true
is_truncating(BinomialReference(5)) # false
is_truncating(DiscUnif2Reference(-2, 2)) # falseERGMCount.BOUNDARY_MASS_TOL — Constant
BOUNDARY_MASS_TOLTolerance for the truncation boundary-mass diagnostic. If a fitted model puts more than this share of any dyad's conditional mass on the top support value, count_mple warns that the truncation is materially changing the model rather than merely bounding the arithmetic.
Example
using NetworkCore, ERGMCount
BOUNDARY_MASS_TOL # 0.0001
net = network(4; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 2)
add_edge!(net, 3, 4); set_edge_attribute!(net, :weight, 3, 4, 1)
fit = fit_ergm_count(net, [SumTerm()])
fit.boundary_mass <= BOUNDARY_MASS_TOL # true — the default support is chosen soModel Types
CountERGMModel
ERGMCount.CountERGMModel — Type
CountERGMModel(terms, net::Network, reference=PoissonReference())Specification of an ERGM for a count-valued network: the terms (a Tuple or Vector of count terms, stored as a Tuple so change statistics fold statically), the observed network (its :weight edge attribute holds the counts, on every edge) and the reference measure h(y).
CountERGMModel{T,D,TT,R} is parameterised on the network's vertex type T and directedness D (mirroring ERGM.ERGMModel{T,D}), the term tuple type TT and the reference type R; is_directed(model) reads D. There is no directed field.
The constructor refuses, with an ArgumentError saying why: a term that is only defined on a directed network (CountMutualTerm, CyclicalTiesTerm, NodeOSumTerm, NodeISumTerm; see ERGM.requires_directed) when net is undirected, since its statistic is identically zero there and the coefficient would not be identified; a two-mode (bipartite) network, whose impossible within-mode dyads would otherwise be counted as observed zeros; a network with edges but no :weight attribute (it would fit as a 0/1 network — see the weight= keyword of fit_ergm_count) or with an edge that carries none while others do (a bare edge is a data gap, not a count of 1); a non-integer weight; a negative count under any reference but DiscUnif2Reference(a < 0, b); and, on a network with a negative count, TransitiveWeightsTerm, CyclicalWeightsTerm or CountMutualTerm(:geometric) ("may not be used with networks with negative dyad weights", as in ergm).
Example
using NetworkCore, ERGMCount
net = network(4; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 1, 1), (2, 3, 2), (3, 4, 1), (4, 1, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
model = CountERGMModel([SumTerm(), CountMutualTerm()], net, PoissonReference())
model.terms # (SumTerm(), CountMutualTerm())
is_directed(model) # true
has_dyad_dependent(model) # true — CountMutualTerm reads the reciprocal dyadCountERGMResult
ERGMCount.CountERGMResult — Type
CountERGMResultResults from fitting a count ERGM by maximum pseudo-likelihood (fit_ergm_count / count_mple).
loglik is the maximized pseudo-log-likelihood over the (possibly truncated) dyad support; vcov is the inverse negative Hessian of the pseudo-log-likelihood at the optimum (or the parametric-bootstrap covariance, see se_type).
Support and truncation
Each dyad's conditional is enumerated over 0:max_val. For the unbounded references (Poisson, geometric) that enumeration truncates the model, so the estimand is the documented unbounded family only if negligible mass sits at the bound. The fields below record what was done, so the approximation is inspectable rather than implicit:
truncated— whether the reference is unbounded and was therefore truncated (seeis_truncating).falsefor genuinely bounded references, whose support is part of the model.max_val— the top of the enumerated support actually used.support_control— howmax_valwas chosen::bounded(the reference's own support),:fixed(the caller'smax_val),:converged(the default error-controlled doubling stopped because the last doubling moved every estimate by at mostsupport_tolstandard errors and left at mostsupport_tolexpected dyads past the previous bound and no dyad put more thanBOUNDARY_MASS_TOLof its conditional mass on the new top value),:unconverged(the doubling hit its cap while the estimates were still moving — the fit is reported but warned about),:boundary_mode(the doubling settled, but the joint distribution has a mode on the bound — see "Joint support" below) or:improper(the doubling settled, but the fitted coefficients make the unbounded model not normalisable — seeimproperbelow).support_tol,support_delta,omitted_tail— the tolerance and the two achieved bounds:support_deltais the largest |Δθ|/SE the last doubling produced,omitted_tailthe expected number of dyads the previous bound omitted. Both are0.0for a bounded reference (nothing was truncated) andNaNfor a caller-fixedmax_val(no doubling was run).support_stable—falsewhen the doubling hitmax_doublingswith the estimates still moving (support_control == :unconverged), the joint distribution has a mode on the bound (:boundary_mode) or the fitted model is not normalisable (:improper).boundary_mass— the largest conditional probability any dyad places on the top support value, at the fitted coefficients. A value materially above zero means the bound is shaping the fit;count_mplewarns pastBOUNDARY_MASS_TOL. Always0.0whentruncated == false.
Boundary statistics
A statistic that sits at its smallest (largest) attainable value on every dyad's conditional support has no finite pseudo-likelihood maximizer. As in R ergm, its coefficient is fixed at -Inf (+Inf) with standard error 0 and p-value 0, the other coefficients are estimated on the restricted supports (the exact limit), and count_mple warns. dof/aic/bic count only the finite coefficients.
Convergence, separation and conditioning
converged is the shared Newton kernel's verdict on the final fit; iterations is how many Newton iterations that fit ran and gradient_norm the norm of the pseudo-score at the reported estimates (0 at an exact maximum). An unconverged fit is warned about, listed in approximations, printed by show, and never is_exact.
separated is true when the pseudo-likelihood has no finite maximum along a combination of the statistics that a single boundary statistic does not explain — separation, R's "The MPLE does not exist!" (e.g. sum + nonzero on a network whose every count is 0 or 1: sum − nonzero is at its minimum on every dyad, so θsum → −∞, θnonzero → +∞ with a flat objective). It is decided exactly from the data by the shared verdict (NetworkCore.clogit_separation), not from where Newton stopped; separated_terms names the coefficients that carry the direction. Newton stops somewhere on that asymptote with arbitrarily large coefficients and astronomical standard errors; the fit is returned with converged = false, warned about, listed in approximations, never is_exact, and its z values, p-values and confidence intervals are NaN (the ecosystem's separation policy).
hessian_cond is the 2-norm condition number of the negative pseudo-Hessian at the reported estimates over the free coefficients (1.0 when none is free, Inf when it is singular). Above ERGMCount._HESSIAN_COND_TOL (1e8) the Hessian is numerically singular — two statistics are (nearly) collinear on this network, e.g. greaterthan.2 and atleast.3 on integer counts, or sum and nonzero on a 0/1 network — and the standard errors along the flat direction are meaningless (NaN when it is exactly singular); count_mple warns, naming the statistics that load on it, and show/approximations say so.
Standard errors
se_type records how std_errors/vcov were actually obtained — :hessian (the inverse negative pseudo-Hessian, anticonservative under dyadic dependence), :bootstrap (the parametric bootstrap of count_mple(model; se=:bootstrap); boot_replicates then holds the n_boot × p refits, excluded ones as NaN rows) or :mcmc (an MCMLE fit: inverse Fisher information estimated from the final sample plus the Monte-Carlo error of the estimate). It is what NetworkCore.se_method(fit) reports. z_values/p_values are the vectors coeftable(fit) and show(fit) print. inference_withheld is true for an MPLE fit (method=:mple) of a dyad-dependent model with the default se: its naive pseudo-Hessian standard errors under-cover, so z_values/p_values are NaN and confint refuses (see count_mple, "Inference under dyadic dependence").
Estimator
method is :mple (maximum pseudo-likelihood, count_mple) or :mcmle (Monte-Carlo maximum likelihood, count_mcmle — the estimator of R's ergm.count). For an MCMLE fit loglik is the log-likelihood itself, estimated by path sampling, and mcmc holds the Monte-Carlo record: convergence (an ERGM.MCMLEConvergence), mc_std_errors, the final samples of the statistics, n_samples, burnin, interval (the adapted one), loglik_mc_se, the start (MPLE) coefficients, the stopping rule, its p-value and its settings (termination, termination_p, conv_precision, conv_confidence). The verdict is termination_p: on a converged fit it is the test that passed, on the sample the last step was taken from; on an unconverged one it is the :confidence test re-run on a fresh sample at the returned coefficients (under :hotelling, the last iteration's test). samples, convergence's t-ratios, Hotelling p-value and effective sizes, and the standard errors all describe a sample drawn at the returned coefficients: one further draw at θ̂ after convergence, or the driver's fresh draw at the last iterate when it did not converge. They are diagnostics, not the stopping rule; show, approximations and the warning quote only the rule (and the t-ratio only under :hotelling). mcmc is nothing for an MPLE fit.
Joint support
boundary_mode is true when the joint distribution on the enumerated support has a mode on the truncation bound that carries its weight: started with every dyad at max_val, iterated conditional modes leave at least one dyad there, and the joint log-weight log h(y) + θ'g(y) of the configuration they stop at exceeds the observed network's (a coordinate-wise mode on the bound that weighs less than the data — the all-top network of a proper geometric-reference model with strong reciprocity — does not count). The support check above looks at the dyad conditionals at the observed network only; a model can pass it while its joint distribution is not normalisable on the unbounded support (a positive mutual.product or squared-strength coefficient under a Poisson reference), or has its mass far beyond the bound. Such a fit has support_control = :boundary_mode (support_stable = false) on the adaptive path, is warned about and listed in approximations, and simulate_count_ergm, gof and se=:bootstrap refuse it. The probe runs on 0:(2^max_doublings · max_val), the bound at which the adaptive sampler would give up, not on the fitted bound.
improper is true when the fitted coefficients make the model not normalisable whatever the data: under a Poisson or geometric reference, a statistic that grows faster than the reference decays — mutual.product, the squared-strength terms nodeOSum/nodeISum/nodeSum, sum(pow=p) with p > 1, or CMP beyond the reference's own log y! — has a positive leading coefficient along some configuration of the counts (one dyad, a reciprocated pair, a star, every dyad), so the weights h(y)·exp(θ'g(y)) grow without bound along it. This is decided analytically from the terms and θ (see count_mple, "Improper models"); such a fit has support_control = :improper (support_stable = false) on the adaptive path, is warned about, printed with a WARNING: line and listed in approximations, and simulate_count_ergm, gof, se=:bootstrap and count_mcmle refuse it unless a max_val is given (the truncated family, chosen in writing).
Example
using NetworkCore, ERGMCount
net = network(4; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 1, 1), (2, 3, 2), (3, 4, 1), (4, 1, 2))
add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
fit = fit_ergm_count(net, [SumTerm(), NonzeroTerm()])
fit.support_control # :converged — the default doubling stopped
fit.truncated # true — Poisson is unbounded
coef(fit) # 2-vector
coeftable(fit) # the table `show(fit)` printsReference Measure Functions
These functions operate on reference measures for computing log-probabilities and sampling.
log_reference
ERGMCount.log_reference — Function
log_reference(ref::AbstractReferenceMeasure, y::Int) -> Float64Log of the dyadwise reference measure h(y) evaluated at count y. Every concrete reference measure (PoissonReference, GeometricReference, BinomialReference, DiscUnifReference, DiscUnif2Reference) implements a method; values outside a bounded support return -Inf.
Example
using ERGMCount
log_reference(PoissonReference(2.0), 3) ≈ 3 * log(2.0) - log(6) # true
log_reference(GeometricReference(), 7) # 0.0
log_reference(BinomialReference(4), 5) # -Inf — outside 0:4sample_reference
ERGMCount.sample_reference — Function
sample_reference(ref::AbstractReferenceMeasure;
rng::Random.AbstractRNG=Random.default_rng()) -> IntDraw a single random count from the baseline distribution associated with the reference measure ref (e.g. Poisson(lambda) for PoissonReference). All randomness flows through the rng keyword, so the same rng state yields identical draws.
Example
using ERGMCount, Random
y = sample_reference(BinomialReference(10); rng=Xoshiro(1))
0 <= y <= 10 # true
sample_reference(PoissonReference(2.0); rng=Xoshiro(3)) ==
sample_reference(PoissonReference(2.0); rng=Xoshiro(3)) # true