Estimation API Reference

This page documents the functions for fitting, simulating, and assessing count ERGMs.

Model Fitting

fitergmcount

ERGMCount.fit_ergm_count — Function
fit_ergm_count(net::Network, terms; reference=PoissonReference(), kwargs...)

Fit an ERGM for count-valued networks, choosing the estimator as R's ergm.count does (method=:auto, the default):

  • a dyad-independent formula — made only of SumTerm, NonzeroTerm, GreaterthannTerm, CountAtleastnTerm, AtmostTerm, SmallerthanTerm, EqualToTerm, InIntervalTerm, CMPTerm — is fit by the count MPLE (count_mple): each dyad's conditional distribution over the count support P(y_ij = y | rest) ∝ h(y)·exp(θ'Δg(y)), with the reference measure h in it, is a likelihood contribution, and here the pseudo-likelihood is the likelihood, so this is the exact MLE;
  • a dyad-dependent formula is fit by Monte-Carlo maximum likelihood (count_mcmle), the estimator R reports. method=:mple asks for the count MPLE explicitly (fast, but an approximation whose naive inference is withheld; see count_mple).

R's ergm requires reference= for a valued model; here it defaults to PoissonReference() (R's reference=~Poisson).

terms may be a Vector, a Tuple or a single term. ergm_count is the R-faithful alias (matching the ergm.count package). Passing the arguments the other way round (fit_ergm_count(terms, net)) is an ArgumentError naming the right order.

Arguments

  • net: one-mode Network whose counts are the :weight edge attribute (integers, on every edge: a network with edges and no :weight at all is refused — see weight= — and so is one where only some edges carry one, naming the first bare edge; a bare edge is a data gap, not a count of 1). A network with masked (unobserved) dyads is refused — see NetworkCore.require_observed; there is no missing= keyword, because the count MPLE would enumerate every unobserved dyad as an observed row. A two-mode (bipartite) network is refused too: its within-mode dyads would be counted as observed zeros.
  • terms: count ERGM terms
  • reference: Reference measure (default: Poisson)
  • weight::Symbol=:weight: the edge attribute holding the counts — R's response="w" is weight=:w. Any name but :weight fits a copy of the network with that attribute copied to :weight (so fit.model.network is the copy; the caller's network is untouched).
  • method: :auto (default: :mple for a dyad-independent formula, :mcmle otherwise, through ERGM.resolve_method), :mple (count_mple) or :mcmle (Monte-Carlo maximum likelihood, count_mcmle — ergm.count's estimator; its keywords n_samples, burnin, interval, termination, effective_size, bridge_rungs, ... are forwarded). Anything else is an ArgumentError, and so is a keyword the chosen estimator does not take (e.g. se=:bootstrap on a dyad-dependent formula, which :auto sends to the MCMLE: the error says to pass method=:mple).
  • max_val::Int: fixes the truncation of an unbounded support. By default the support is chosen adaptively (doubling from twice the largest observed count until the estimates stop moving; see count_mple); ignored by the bounded references.
  • support_tol, max_doublings, maxiter, tol, se, n_boot, boot_burnin, boot_interval, rng: forwarded to count_mple. se=:bootstrap replaces the inverse-pseudo-Hessian covariance with a parametric bootstrap (same API as ERGM.mple); the point estimates are unchanged. With the default se=nothing a dyad-dependent MPLE fit (method=:mple) reports no z, p or interval (see count_mple, "Inference under dyadic dependence").

Returns

  • CountERGMResult: fitted model, answering the full StatsAPI surface (coef, stderror, vcov, confint, loglikelihood, nobs, dof, aic, bic, coeftable)

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()]; reference=PoissonReference())
fit.method                      # :mple — dyad-independent, so the MPLE is the MLE
fit.converged                   # true
coeftable(fit)                  # sum / nonzero estimates with z and p
fit_ergm_count(net, SumTerm())  # a single term works too
# A dyad-dependent formula: the count MPLE on request (the default would be
# the MCMLE)
dep = fit_ergm_count(net, [SumTerm(), CountMutualTerm()]; method=:mple)
dep.inference_withheld          # true
source

ergm_count

ERGMCount.ergm_count — Function
ergm_count(net::Network, terms; kwargs...)

R-faithful alias for fit_ergm_count (the same function), matching the R ergm.count package name.

Example

using ERGMCount
ergm_count === fit_ergm_count   # true
source

count_mple

ERGMCount.count_mple — Function
count_mple(model::CountERGMModel; max_val=nothing, support_tol=1e-3,
           max_doublings=8, se=nothing, n_boot=100, boot_burnin=nothing,
           boot_interval=nothing, rng=Random.default_rng(),
           maxiter=100, tol=1e-8, warn=true, drop=true) -> CountERGMResult

Maximum pseudo-likelihood estimation for count ERGMs. For each dyad the full conditional over the count support is enumerated, so the score is Σ_dyads [Δg(y_obs) − E_θ(Δg)] and the Hessian is −Σ_dyads Var_θ(Δg). Dyads with identical conditionals are compressed into one row (every dyad, for a dyad-independent model). The pseudo-log-likelihood is maximized with the shared NetworkCore.newton_fit Newton–Raphson-with-step-halving optimizer, by continuation in the support: the first fit is on 0:max(10, 2·max count) and every wider support is warm-started from the fit below it (a cold start on a wide support overshoots).

Support

The support enumerated for each dyad is the reference's own for a bounded reference (BinomialReference, DiscUnifReference, DiscUnif2Reference). For an unbounded one (PoissonReference, GeometricReference) it is 0:max_val, a truncation of the model, chosen so that the truncation is an error-controlled numerical device rather than a silent change of model:

  • max_val=nothing (default): start at twice the largest observed count (at least 10), refit at twice that bound, and stop when the doubling moved every estimate by at most support_tol standard errors (on the absolute scale where a standard error is NaN or 0) and the wider fit leaves at most support_tol expected dyads past the previous bound and no dyad puts more than BOUNDARY_MASS_TOL of its conditional mass on the new top value; the fit at the larger bound is reported (support_control = :converged, support_stable = true, with the achieved support_delta/omitted_tail). If the estimates are still moving after max_doublings (default 8) doublings the fit is reported with support_control = :unconverged, support_stable = false and a warning naming the achieved δ and bound: that is the signature of a model that is not normalisable on the unbounded support (e.g. a positive sum coefficient under a geometric reference). The doubling also stops, with the same :unconverged verdict but support_delta = omitted_tail = NaN, at the first bound on which Newton did not converge or the pseudo-Hessian is numerically singular (a collinear or separated design): there are no settled estimates to compare, so the support is not error-controlled and the convergence/conditioning warning speaks alone — the "not normalisable" reading applies only to a converged fit that keeps moving.
  • max_val=k: fix the bound (support_control = :fixed, support_delta = NaN); the boundary-mass diagnostic still reports whether it bites.
  • A bounded reference never loops: support_control = :bounded, support_delta = 0.0.

Boundary statistics

A statistic at its extreme attainable value on every dyad's conditional support has no finite MPLE; its coefficient is fixed at ∓Inf with a warning, as R ergm does (see CountERGMResult). se=:bootstrap is refused for such a fit (there is no finite model to simulate from).

Improper models

The support check is on the dyad conditionals at the observed network. 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 makes every conditional a proper Poisson law and the joint improper (Krivitsky 2012, sec. 3) — or has its mass far beyond the bound. Two checks look for that, after every fit under a Poisson or geometric reference:

  • An analytic rule. Under a Poisson reference log h(y) ≈ −y log y per dyad, under the geometric one 0. A statistic that grows faster than linearly in the counts — mutual.product, nodeOSum/nodeISum/nodeSum, sum(pow=p) with p > 1, and CMP (which beats the Poisson reference beyond a coefficient of 1, the geometric one beyond 0) — makes the weights grow without bound along some configuration of the counts when its leading coefficient is positive. The rule evaluates the leading order of log h(y) + θ'g(y) with one dyad, a reciprocated pair, a star and every dyad set to a count Y → ∞, so a positive coefficient on one super-linear term can be offset by a larger negative one on another (a positive nodeOSum under a larger negative nodeSum). A positive leading coefficient is a proof that the model is improper whatever the data; the fit is reported with fit.improper = true (support_control = :improper, support_stable = false on the adaptive path), warned about, and refused by se=:bootstrap, simulate_count_ergm, gof and count_mcmle. A term whose growth the rule does not know (a user-defined count term) makes it silent.
  • A probe. Started with every dyad at the bound where the adaptive sampler would give up, 2^max_doublings × max_val (the fitted bound itself when the caller fixed max_val), conditional modes are iterated; if dyads stay at the bound the fit is reported with fit.boundary_mode = true (and support_control = :boundary_mode, support_stable = false on the adaptive path), warned about, and refused the same way. It covers dyad-dependent models whose growth is linear (a positive transitiveweights sum under a geometric reference) or that the rule cannot read.

On a caller-fixed max_val both are recorded but nothing is refused: that is the truncated family, chosen in writing (simulate_count_ergm(fit; max_val=k) likewise).

This is not ergm.count's estimator

R's ergm.count fits by Monte-Carlo maximum likelihood; statnet has no valued MPLE. For a dyad-independent model the count MPLE is the exact MLE. For a dyad-dependent one it is a different, less efficient estimator: on ergm.count's zach example (sum + nonzero + transitiveweights) it is (0.797, −4.924, 0.385) against the MLE (0.597, −4.779, 0.562) — 1.7 and 1.8 standard errors apart on two coefficients. count_mcmle (method=:mcmle) is the estimator R reports.

Standard errors

  • se=:hessian — the inverse negative pseudo-Hessian. For a dyad-independent model (e.g. SumTerm alone) the pseudo-likelihood is the likelihood and they are correct. For a model with dyad-dependent terms (CountMutualTerm, TransitiveWeightsTerm, the node-strength terms, ...) the pseudo-likelihood multiplies dyad conditionals as if independent, so they are naive: too small (see below).
  • se=:bootstrap — parametric bootstrap: Gibbs-simulate n_boot count networks from the fitted model at θ̂ (as simulate_count_ergm does), refit the count MPLE on each, and report the empirical covariance of the refits. The point estimate is unchanged; only the covariance is replaced. Same option, keywords and semantics as ERGM.mple's, on the ONE shared NetworkCore.bootstrap_cov loop. A replicate on which the count MPLE does not exist (a boundary statistic) or does not converge is excluded from the covariance and counted in a warning; fit.boot_replicates keeps every refit (excluded ones as NaN rows). The simulating chain widens an error-controlled support on demand; with a caller-fixed max_val it stays on 0:max_val, and the bootstrap is refused if the chain puts more than BOUNDARY_MASS_TOL of a conditional on that bound.
  • se=nothing (default) — :hessian, with the inference of a dyad-dependent model withheld:

Inference under dyadic dependence

The naive pseudo-Hessian standard errors of a dyad-dependent count model are not calibrated: simulated at the MLE of the zach model above, 95 % Wald intervals built from them covered the truth 0.91, 0.98 and 0.70 of the time (300 networks; the mean standard error of transitiveweights is 0.058, half the estimator's sampling standard deviation of 0.121), against 0.96, 0.97 and 0.97 for the parametric bootstrap (100 of those networks, n_boot=60). So, by default, a dyad-dependent MPLE fit reports its point estimates and naive standard errors but no inference built on them: z_values and p_values are NaN (the coefficient table shows NaN, with a note saying why), confint refuses with an ArgumentError, fit.inference_withheld is true and approximations(fit) records it. For calibrated inference use method=:mcmle or se=:bootstrap. Passing se=:hessian explicitly is the written opt-in to the naive Wald table, printed with its caveat. Dyad-independent models are unaffected.

Convergence, separation and conditioning

The fit is warned about, and fit.converged == false recorded, when the Newton iteration exhausts maxiter or cannot move (fit.iterations, fit.gradient_norm); approximations(fit) then lists it and is_exact(fit) is false.

Separation. A design on which the pseudo-likelihood has no finite maximum along a combination of the statistics — separation, which the one-column boundary test cannot see (e.g. sum + nonzero when every count is 0 or 1, or sum + atleast(2) when every count is 0 or 2) — is decided exactly from the data: the count pseudo-likelihood is a conditional logit over each dyad class's support, and the ecosystem's shared verdict (NetworkCore.clogit_separation, the linear programme of R's mple.existence) runs on the design actually fitted, after the boundary columns are fixed. Such a fit is returned with converged = false, separated = true and the separating terms in fit.separated_terms; it is warned about (naming them, with R's "The MPLE does not exist!"), its z values, p-values and confidence intervals are NaN, it is listed in approximations, never is_exact, se=:bootstrap is refused, and the bootstrap excludes such replicates.

Conditioning. fit.hessian_cond is the condition number of the negative pseudo-Hessian at the estimates. Above ERGMCount._HESSIAN_COND_TOL (1e8) — two statistics collinear or nearly so on this network, such as greaterthan(2) and atleast(3) on integer counts, or sum and nonzero on a 0/1 network — the fit warns, naming the statistics that load on the flat direction (fit.collinear), and show/approximations carry the caveat; the standard errors along that direction are meaningless (NaN when it is exactly singular).

Keyword Arguments

  • max_val::Union{Int,Nothing}=nothing, support_tol::Float64=1e-3, max_doublings::Int=8: above
  • se=nothing: :hessian or :bootstrap (validated by the shared NetworkCore.check_se); nothing is :hessian with the inference of a dyad-dependent model withheld
  • n_boot::Int=100: number of bootstrap replicates (se=:bootstrap only)
  • boot_burnin, boot_interval: Gibbs controls (in sweeps) for the bootstrap simulations; nothing resolves through the dyad-scaled rule shared with ERGM.jl (ERGM.Extension.mcmc_defaults, converted from toggles to sweeps)
  • rng::AbstractRNG=Random.default_rng(): source of the bootstrap randomness — a fixed rng reproduces the standard errors exactly
  • maxiter::Int=100, tol::Float64=1e-8: Newton controls
  • warn::Bool=true: false silences the fit diagnostics (boundary statistic, truncation, non-convergence, undefined standard errors) — they are all still recorded on the result. As in ERGM.mple, the parametric bootstrap refits run with warn=false and report their exclusions once, in aggregate.
  • drop::Bool=true: R's control.ergm(drop=). false refuses a model with a statistic at the boundary of its attainable range (an ArgumentError naming it) instead of fixing its coefficient at ∓Inf

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(), NonzeroTerm()], net, PoissonReference())
fit = ERGMCount.count_mple(model)                 # adaptive support
fit.support_control                               # :converged
fixed = ERGMCount.count_mple(model; max_val=40)   # caller-fixed support
fixed.support_control                             # :fixed
source

count_mcmle

ERGMCount.count_mcmle — Function
count_mcmle(model::CountERGMModel; n_samples=1024, burnin=nothing,
            interval=nothing, effective_size=:auto, maxiter=60,
            termination=:confidence, conv_precision=0.1, conv_confidence=0.99,
            conv_threshold=0.1, hotelling_alpha=0.05, gamma0=0.1,
            max_step_norm=5.0, max_n_samples=nothing,
            bridge_rungs=16, bridge_samples=nothing,
            max_val=nothing, max_doublings=8, support_tol=1e-3, init=nothing,
            rng=Random.default_rng(), warn=true, drop=true) -> CountERGMResult

Monte-Carlo maximum likelihood for a count ERGM — the estimator R's ergm.count uses (statnet has no valued MPLE). fit_ergm_count(net, terms; method=:mcmle) calls it.

The iteration is ERGM.jl's (ERGM.Extension.mcmle_solve, the one ERGM.mcmle runs); this function supplies the sampler. Starting from the count MPLE (count_mple), each iteration draws n_samples networks from the model at the current coefficients with the exact Gibbs sampler of simulate_count_ergm (after burnin sweeps; the chain continues across iterations) and takes the Hummel-stepped Monte-Carlo Newton step toward the observed statistics, θ ← θ + γ·Σ̂⁻¹(g(y_obs) − ḡ). The stopping rule, tested at full step length, is termination:

  • :confidence (default) — R ergm 4's equivalence test: with confidence conv_confidence the estimating equations at the updated coefficients lie inside the tolerance region x'(conv_precision·Σ̂)⁻¹x ≤ 1 (ERGM.Extension.confidence_test); when it fails near the solution the next sample is larger, up to max_n_samples (default 16·n_samples), as R boosts its sample;
  • :hotelling — every statistic's t-ratio |g_obs − ḡ|/sd below conv_threshold and a Hotelling T² test at hotelling_alpha (ERGM.mcmc_convergence).

Sampling is ESS-adaptive (ERGM.Extension.ess_sample, R's MCMC.effectiveSize): the interval between retained draws starts at interval sweeps (default: the dyad-scaled rule) and doubles until the effective sample size of the n_samples draws reaches effective_size (default :auto = n_samples ÷ 2; a number sets it, nothing keeps the interval fixed). On ergm.count's zach example a sweep-per-draw chain has an effective size of about 180 in 1024; the adapted interval is 4–8 sweeps.

The standard errors are the inverse Fisher information plus the Monte-Carlo error of the estimate (ERGM.Extension.mcmle_covariance, as ERGM.mcmle reports them), computed — with fit.mcmc.convergence's t-ratios and Hotelling p-value — from a sample drawn at the returned coefficients. On a converged fit that is one further sample drawn after the rule passed: the sample the last step was taken from can sit a standard error away when the rule passes after one or two steps from the MPLE, and the Fisher information there is not the one at the estimate. On a fit that did not converge it is the fresh sample the iteration draws at its last iterate. The stopping verdict, fit.mcmc.termination_p, is the rule's own test (on a converged fit, the one that passed, on the pre-step sample); the warning, show and approximations quote only that rule and the step length γ — plus the largest t-ratio under termination=:hotelling, whose rule it is. At the defaults the seed-to-seed spread of the estimates and their Monte-Carlo error (about 4 % of a standard error on zach) are those of ergm.count.

loglikelihood(fit) is the log-likelihood itself, by path sampling: the dyad-independent part of the fitted model (the dyad-dependent coefficients set to zero) has an exact likelihood, and log Z is integrated from there to θ̂ over bridge_rungs Simpson segments with bridge_samples draws per grid point (default max(64, n_samples ÷ 4); fit.mcmc.loglik_mc_se is its Monte-Carlo standard error). It includes the reference measure, so it is comparable with the (pseudo-)log-likelihood of an MPLE fit of a dyad-independent model on the same network; R's logLik is the same number minus the log-likelihood at θ = 0. bridge_rungs=0 skips it (NaN).

A dyad-independent model needs no Monte Carlo: its MPLE is the exact MLE and is returned as is (fit.mcmc === nothing).

Support

An unbounded reference is sampled on an adaptive support: the chain widens 0:max_val whenever a dyad's conditional puts more than 1e-10 of its mass on the top value, starting from the MPLE's error-controlled bound, and an ArgumentError is thrown if it reaches 2^max_doublings times that bound — the signature of a model that is not normalisable. max_val=k fixes the truncated family on 0:k instead; a chain that puts more than BOUNDARY_MASS_TOL of a conditional on k is refused.

Refusals

ArgumentError when the MPLE start is separated or did not converge, or when its joint-support probe found a mode on the truncation bound (fit.boundary_mode); and when se= is passed (an MPLE option — MCMLE standard errors are always Fisher information plus Monte-Carlo error).

Boundary statistics

A statistic at the boundary of its attainable range on every dyad's conditional support (the MPLE fixes its coefficient at ∓Inf) is dropped as R does under its default control.ergm(drop=TRUE): the coefficient is fixed at ∓Inf (standard error 0, p-value 0) with R's warning, and the others are the MLE with the statistic held at its observed bound — the sampler gives every value that would move it zero weight. The log-likelihood is then not estimated (NaN). drop=false refuses such a model with an ArgumentError instead (R's drop=FALSE keeps the term; that is not implemented); a model with every statistic at its bound is refused (nothing to estimate).

Example

using NetworkCore, ERGMCount, Random
net = network(6; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 1, 2), (2, 3, 2), (3, 2, 1), (3, 4, 1), (4, 5, 2),
                  (5, 4, 1), (1, 5, 2), (5, 6, 1), (6, 2, 1), (6, 5, 2))
    add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
fit = fit_ergm_count(net, [SumTerm(), CountMutualTerm()]; method=:mcmle,
                     n_samples=400, bridge_samples=100, rng=Xoshiro(1))
fit.method                       # :mcmle
fit.mcmc.convergence.iterations  # MCMLE iterations run
coeftable(fit)                   # z and p from Fisher + Monte-Carlo standard errors
source

StatsAPI surface

Every fit answers the ecosystem's StatsAPI surface (coef, stderror, vcov, confint, loglikelihood, nobs, dof, aic, bic, coeftable, coefnames); the methods below carry ERGMCount-specific semantics.

StatsAPI.aic — Method
aic(result::CountERGMResult) -> Float64

-2·loglikelihood + 2·dof — a pseudo-likelihood AIC (a method of StatsAPI.aic): loglikelihood(result) is the maximized pseudo-log-likelihood over the enumerated count support, not a likelihood, so this number is comparable only across models fit on the same network with the same reference and support (max_val), and it carries the pseudo-likelihood's bias for dyad-dependent models. dof counts the finite coefficients (one fixed at ∓Inf by a boundary statistic is not a parameter).

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()])
aic(fit) ≈ -2 * loglikelihood(fit) + 2 * dof(fit)   # true
source
StatsAPI.bic — Method
bic(result::CountERGMResult) -> Float64

-2·loglikelihood + dof·log(nobs) with nobs the number of dyads — a pseudo-likelihood BIC (a method of StatsAPI.bic), with exactly the caveats of aic: comparable only across models fit on the same network, reference and support.

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()])
bic(fit) ≈ -2 * loglikelihood(fit) + dof(fit) * log(nobs(fit))   # true
nobs(fit)                                                        # 12 directed dyads
source
StatsAPI.confint — Method
confint(result::CountERGMResult; level=0.95) -> Matrix{Float64}

Normal-theory (Wald) confidence limits θ̂ ± z_{(1+level)/2} · se, one row per coefficient with the lower limit in column 1 and the upper in column 2 (a method of StatsAPI.confint). The standard errors are the ones the fit reports — se_method(result) says whether they are inverse-pseudo-Hessian, parametric-bootstrap or (MCMLE) Fisher-information based. For an MPLE fit (method=:mple) of a dyad-dependent model with the default se, whose naive pseudo-likelihood standard errors under-cover, confint refuses with an ArgumentError (see count_mple, "Inference under dyadic dependence"); with an explicit se=:hessian the naive intervals are returned. A coefficient fixed at ∓Inf has both limits at that value.

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()])
ci = confint(fit)                          # 2×2
all(ci[:, 1] .< coef(fit) .< ci[:, 2])     # true
confint(fit; level=0.9)                    # narrower
source
StatsAPI.coeftable — Method
coeftable(result::CountERGMResult) -> NetworkCore.CoefficientTable

The R-style coefficient table (Estimate, Std.Error, z value, Pr(>|z|)) as an inspectable NetworkCore.CoefficientTable — exactly the table show(result) prints, built from the same vectors (a method of StatsAPI.coeftable). Rows are labelled with name(term, net), the shared two-argument statistic name, and can be read by index or by name.

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()])
tbl = coeftable(fit)
tbl["sum"].estimate == coef(fit)[1]      # true
tbl[2].p_value == fit.p_values[2]        # true
source
StatsAPI.coefnames — Method
coefnames(result::CountERGMResult) -> Vector{String}

The coefficient labels, in coef(result) order — R's names(coef(fit)) for the same ergm.count formula ("sum", "nonzero", "transitiveweights.min.max.min", …), and the row labels of coeftable(result) (a method of StatsAPI.coefnames). A fresh vector on every call, so changing it cannot change the fit.

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()])
coefnames(fit)                              # ["sum", "nonzero"]
coefnames(fit) == coeftable(fit).names      # true
source

Model classification

ERGM.has_dyad_dependent — Method
has_dyad_dependent(model::CountERGMModel) -> Bool

Whether any term of the count model is dyad-dependent (see ERGM.is_dyad_dependent) — a method of the ONE ERGM.has_dyad_dependent predicate. This decides whether the dyadwise pseudo-likelihood is the likelihood (dyad-independent: the count MPLE is the exact MLE) or an approximation; show, is_exact and approximations all read this one answer.

Example

using NetworkCore, ERGMCount
net = network(3; directed=true)
add_edge!(net, 1, 2); set_edge_attribute!(net, :weight, 1, 2, 2)
has_dyad_dependent(CountERGMModel([SumTerm(), NonzeroTerm()], net))   # false
has_dyad_dependent(CountERGMModel([SumTerm(), NodeOSumTerm()], net))  # true
source
NetworkCore.is_exact — Method
is_exact(result::CountERGMResult) -> Bool

true only when all of these hold:

  1. every term is dyad-independent (see ERGM.is_dyad_dependent), so the dyad conditionals that the pseudo-likelihood multiplies are the model's own conditionals and their product is the likelihood;
  2. the fit was not truncated — for an unbounded reference (Poisson, geometric) the estimator enumerates 0:max_val, which is the likelihood of a different, truncated family (the error-controlled default keeps the difference below support_tol standard errors, but it is not zero);
  3. the Newton iteration converged (result.converged); and
  4. every coefficient is finite — a coefficient fixed at ±Inf by a boundary statistic is a limit, not a maximizer.

A SumTerm model under a bounded reference is therefore exact; the same term under a Poisson reference is not, and neither is any model containing a strength, mutual or triadic term, an unconverged fit, or a fit with a boundary statistic.

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, 3, 4); set_edge_attribute!(net, :weight, 3, 4, 1)
is_exact(fit_ergm_count(net, [SumTerm()]; reference=BinomialReference(3)))  # true
is_exact(fit_ergm_count(net, [SumTerm()]; reference=PoissonReference()))    # false
source
NetworkCore.se_method — Method
se_method(result::CountERGMResult) -> Symbol

What the reported standard errors ACTUALLY are: :hessian (the inverse negative pseudo-Hessian), :bootstrap (the parametric bootstrap of count_mple(model; se=:bootstrap)) or :fisher (an MCMLE fit: the inverse Fisher information of the final sample plus the Monte-Carlo error). Read straight off the fit, so it can never claim an estimator that was not used.

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, 3, 4); set_edge_attribute!(net, :weight, 3, 4, 1)
se_method(fit_ergm_count(net, [SumTerm()]))   # :hessian
source

Simulation

simulatecountergm

ERGMCount.simulate_count_ergm — Function
simulate_count_ergm(result::CountERGMResult; n_sim=1, burnin=nothing,
                    interval=nothing, max_val=nothing, max_doublings=8,
                    rng=Random.default_rng()) -> Vector{Network}
simulate_count_ergm(net, terms, coefficients; reference=PoissonReference(),
                    n_sim=1, burnin=nothing, interval=nothing, max_val=nothing,
                    max_doublings=8, rng=Random.default_rng()) -> Vector{Network}

Simulate networks from a count ERGM by Gibbs sampling: each sweep resamples every dyad from its full conditional P(y_ij = y | rest) ∝ h(y)·exp(θ'Δg(y)) (an inverse-CDF draw from the enumerated support), using each term's change statistic, so structural terms (mutuality, transitivity, node strength) influence the draws. The first form simulates from a fitted model at its coefficients and support; the second from an explicit specification (net provides the size, directedness and starting state; terms may be a Vector, a Tuple or a single term).

burnin and interval are counted in sweeps; nothing resolves through the dyad-scaled rule shared with ERGM.jl (20 sweeps of burn-in, then cld(max(100, n_dyads ÷ 10), n_dyads) sweeps between retained draws).

Support of an unbounded reference

A bounded reference is sampled on its own support. For PoissonReference and GeometricReference the enumerated support 0:max_val is a device, and the sampler never lets it shape the draws silently:

  • max_val=nothing (default): the support is adaptive. It starts at max(10, 2·largest seed count) (a fit's own max_val in the first form) and is doubled whenever a dyad's conditional puts more than 1e-10 of its mass on the top value, before that dyad is drawn. If it reaches 2^max_doublings times the start, the call throws an ArgumentError: a chain that keeps climbing is the signature of a model that is not normalisable at these coefficients — which every dyad conditional being proper does not rule out (a positive mutual.product or squared-strength coefficient under a Poisson reference).
  • max_val=k: the family truncated at 0:k, deliberately. If any conditional of the retained sweeps puts more than BOUNDARY_MASS_TOL on k, the draws are returned with a warning giving the share that landed on the bound. (gof and the parametric bootstrap refuse such a chain.)
  • From a fit: a fit whose max_val the caller fixed simulates that truncated family; an error-controlled fit is simulated adaptively; a fit whose joint-support probe found a mode on the bound (fit.boundary_mode) is refused unless max_val=k is passed.

A network with masked (unobserved) dyads is refused (NetworkCore.require_observed): the sampler would otherwise start from, and condition on, face values of dyads that were never observed. A two-mode (bipartite) network is refused (the sweep would resample its impossible within-mode dyads), and so is a specification with a coefficient at ∓Inf (a boundary statistic). Under DiscUnif2Reference(a < 0, b) the draws can be negative: an edge is stored for every non-zero count, with the (possibly negative) value under :weight.

All random draws flow through rng; the same rng state yields identical output. This sampler is a Gibbs sweep, not a Metropolis toggle chain, so it deliberately does not use ERGM.mh_toggle!.

Example

using NetworkCore, ERGMCount, Random
seed = network(6; directed=true)
sims = simulate_count_ergm(seed, [SumTerm(), CountMutualTerm()], [log(0.8), 0.5];
                           reference=PoissonReference(), n_sim=3, max_val=10,
                           rng=Xoshiro(1))
length(sims)                        # 3
using ERGM: compute
compute(SumTerm(), sims[1]) > 0     # true
source

Goodness of Fit

gof

Goodness-of-fit assessment is provided as a method of the shared NetworkCore.gof generic, so the same gof(result) call works across the model packages of the ecosystem.

NetworkCore.gof — Method
gof(result::CountERGMResult; n_sim=100, burnin=nothing, interval=nothing,
    max_val=nothing, rng=Random.default_rng()) -> GOFResult

Goodness-of-fit assessment of a fitted count ERGM: networks are simulated from the fitted model with simulate_count_ergm and compared with the observed network on

  • the model statistics (one level per term), and
  • the distribution of dyad count values (number of dyads with value 0, 1, 2, ... — every value the observed or a simulated network takes, negative ones included under DiscUnif2Reference(a < 0, b)).

This is a method of the shared NetworkCore.gof generic; it returns the shared NetworkCore.GOFResult (observed value, simulation envelope, and two-sided Monte-Carlo p-value per level). The simulation inherits simulate_count_ergm's refusals (masked dyads, non-finite coefficients, a model whose chain does not settle on a finite support) and adds one: a caller-fixed max_val on which the chain puts more than BOUNDARY_MASS_TOL of a conditional is an ArgumentError, not a warning — the p-values would describe the bound. For an MCMLE fit the model statistics are matched in expectation by construction; the count-value panel is the informative one.

Keyword Arguments

  • n_sim::Int=100: Number of simulated networks
  • burnin, interval, max_val, rng: passed to simulate_count_ergm

Example

using NetworkCore, ERGMCount, Random
net = network(5; directed=true)
for (i, j, w) in ((1, 2, 3), (2, 1, 1), (2, 3, 2), (3, 4, 1), (4, 1, 2), (5, 1, 1))
    add_edge!(net, i, j); set_edge_attribute!(net, :weight, i, j, w)
end
fit = fit_ergm_count(net, [SumTerm(), NonzeroTerm()])
g = gof(fit; n_sim=20, rng=Xoshiro(3))
g.statistics[1].labels             # ["sum", "nonzero"]
source

Renamed and removed names

Names that existed during development but were never released. They are not kept as deprecated aliases; calling one is an UndefVarError (a removed keyword is an ArgumentError naming the estimator that takes it).

Development nameUse instead
fit_count_ergm(net, terms; ...)fit_ergm_count(net, terms; ...) or its R-named alias ergm_count
method=:mple as the implicit default for every formulamethod=:auto (the default) follows R: the MPLE for a dyad-independent formula, the MCMLE otherwise; pass method=:mple for the count MPLE of a dyad-dependent one