Estimation and Simulation

fit_ergm_multi is the ecosystem's harmonised fit_<model> name and ergm_multi the R ergm.multi name; they are one const function.

ERGMMulti.fit_ergm_multi — Function
fit_ergm_multi

The harmonised fit_<model> name of the multilayer ERGM fitter — a const alias of ergm_multi (fit_ergm_multi === ergm_multi), which is the R ergm.multi name. Both are exported; use whichever reads better.

Example

using ERGMMulti
fit_ergm_multi === ergm_multi   # true
source
ERGMMulti.ergm_multi — Function
ergm_multi(m::MultilayerNetwork, terms; offsets=Dict{Int,Float64}(),
           method=:auto, maxiter=100, tol=1e-8, se=nothing, n_boot=100,
           boot_burnin=nothing, boot_interval=nothing,
           rng=Random.default_rng(), threaded=true,
           n_samples=1024, burnin=nothing, interval=nothing,
           mcmle_maxiter=60, termination=:confidence, conv_precision=0.1,
           conv_confidence=0.99, max_n_samples=nothing, bridge_rungs=16,
           bridge_samples=nothing, init=nothing, drop=true) -> MultiERGMResult
ergm_multi(model::MultiERGMModel; kwargs...) -> MultiERGMResult
fit_ergm_multi(...)                            # the same function

Fit a multilayer ERGM — by default (method=:auto) as R's ergm.multi does: by maximum pseudo-likelihood when every term is dyad-independent (where it is the exact MLE) and by Monte-Carlo maximum likelihood otherwise (see "Estimators" below) — over the within-layer dyads (the dyad universe of ergm.multi's block-diagonal construction): each dyad's conditional edge probability is logistic in θ'Δg, with Δg the add-direction change statistics of the layer-aware terms. ergm_multi is the R (ergm.multi) name and fit_ergm_multi the ecosystem's harmonised fit_<model> name; they are one const function (fit_ergm_multi === ergm_multi).

The terms are validated against the data when the MultiERGMModel is built: an out-of-range layer index, a within-layer term whose attribute the layer lacks, an undirected-only term on a directed layer (or the reverse), and a masked (missing) dyad in any layer all throw an ArgumentError before any fitting. An unconverged Newton iteration is loud: a warning is emitted, fit.converged is false, show prints the caveat and approximations(fit) records it. A statistic at the boundary of its attainable range (no co-occurring tie under InterlayerDependence, no mutual dyad under LayerMutual, no triangle under LayerTriangle — even when no single tie could close one —, a perfectly separated NodeMatch, ...) has no finite estimate: as R ergm's default drop=TRUE, its coefficient is fixed at ∓Inf with standard error 0 (R's warning is printed), the other coefficients are estimated with it held there (the MPLE on the dyads it does not touch; the MCMLE with the sampler never moving it off its observed bound), is_exact(fit) is false, and show/approximations say so. ergm.multi 0.3.0 does not apply the drop to layer terms (it reports NA, or a finite value where its estimation stopped); its offset spelling, offset(L(~term, ~A)) with offset.coef = -Inf, fits the same model as the drop here. drop=false (R's control.ergm(drop=FALSE)) refuses such a statistic with an ArgumentError before any fit. A statistic with no identifiable coefficient — its change statistics are all 0 on the dyads fitted, or a linear combination of the others' — is reported as NaN (R's NA) with a warning, and the others are fitted without it. Separation by a combination of statistics (no single column at its boundary, yet the ties are perfectly predicted — R's "The MPLE does not exist!") is detected by NetworkCore's separation verdict on the design actually fitted, with or without offsets: a warning names the separating terms, and the fit is returned with converged == false, separated == true, the terms in fit.separated_terms, and NaN z values, p-values and confidence intervals; show/approximations carry the verdict and se=:bootstrap is refused. (A method=:mcmle fit refuses a separated MPLE start.)

offsets maps term indices to fixed coefficients (per-layer offsets, e.g. Dict(1 => -log(n)) for a size adjustment); the remaining coefficients are estimated with the offset contribution absorbed into the linear predictor.

Estimators

method=:auto (the default) follows R: :mple when no term is dyad-dependent and :mcmle otherwise (ERGM.resolve_method, the rule of every ERGM-family fitter).

method=:mple maximizes the product of the (layer, i, j) conditionals. For a dyad-independent formula that product is the likelihood and the fit is the exact MLE. For a dyad-dependent formula it is not what R reports, and must be asked for explicitly.

method=:mcmle is R's estimator. Starting from the MPLE, each iteration draws n_samples multilayer networks at the current coefficients with the sampler of simulate_multi_ergm (one retained state every interval proposals after burnin; the chain continues across iterations, offsets included) and takes the Monte-Carlo Newton step θ ← θ + γ·Σ̂⁻¹(g(y_obs) − ḡ) on the free coefficients, with Hummel's step length γ. The iteration is ERGM.jl's own (ERGM.Extension.mcmle_solve, the loop ERGM.mcmle runs), so the stopping rule is R ergm 4's: at γ = 1, with confidence conv_confidence (0.99), the estimating equations at the updated coefficients must lie within the tolerance region set by conv_precision (0.1); when the test fails near the solution the sample is boosted, up to max_n_samples (default 16·n_samples). termination=:hotelling selects the older t-ratio (conv_threshold) and Hotelling T² (hotelling_alpha) rule at a fixed sample size. The reported coefficients are the update from the sample that passed; the standard errors are that sample's inverse Fisher information plus the Monte-Carlo error (ERGM.Extension.mcmle_covariance, as ERGM.mcmle), with full z, p and confint. loglikelihood(fit) is the log-likelihood itself, by path sampling from the dyad-independent part of the model (whose normalizer is exact) over bridge_rungs Simpson segments of bridge_samples draws (default n_samples; bridge_rungs=0 skips it and reports NaN); aic/bic are built on it. fit.method is :mcmle, fit.mcmc holds the record (convergence, mc_std_errors, samples, n_samples, burnin, interval, loglik_mc_se, start, termination, termination_p, conv_confidence, conv_precision, estimated, loglik_note; the samples and convergence diagnostics are those of the pre-step sample), se_method(fit) == :fisher and objective(fit) == :likelihood. The result is reproducible from rng and independent of the thread count.

method=:mcmle on a dyad-independent formula returns the exact MPLE with no Monte Carlo (fit.mcmc === nothing). A statistic at the boundary of its attainable range is fixed at ∓Inf (above): the step, the stopping rule and the covariance run over the other coefficients (fit.mcmc.estimated lists them), and if the fixed statistic is dyad-dependent the log-likelihood (and AIC, BIC) is NaN, because the path sampler's dyad-independent reference model cannot hold it at its bound (show/approximations say so). A dyad-independent statistic with no identifiable coefficient is held at 0 and reported NaN; a dyad-dependent one needs init=. The MCMLE is refused with an ArgumentError when the MPLE start is separated or did not converge (unless init= is given), and when statistics would be fixed at both -Inf and +Inf (the sampler cannot hold both).

Each estimator takes its own keywords: se, n_boot, boot_burnin, boot_interval and threaded are the MPLE's; n_samples, burnin, interval, mcmle_maxiter, termination, conv_precision, conv_confidence, conv_threshold, hotelling_alpha, max_n_samples, bridge_rungs, bridge_samples and init the MCMLE's; maxiter, tol, rng and drop both. A keyword the chosen estimator does not take is an ArgumentError that names the estimator that does — for example se=:bootstrap on a dyad-dependent formula, which method=:auto sends to the MCMLE: pass method=:mple explicitly.

Standard errors of the MPLE

  • default (se=nothing) — the inverse negative pseudo-Hessian. With only dyad-independent terms the pseudo-likelihood is the likelihood, these standard errors are correct and the full Wald table is reported. With any dyad-dependent term (LayerMutual, LayerTriangle, InterlayerDependence, MultiplexMutual, a WithinLayer of a dyad-dependent term, ...) the pseudo-likelihood multiplies the (layer, i, j) conditionals as if independent and the naive standard errors under-cover (95% Wald intervals covered 0.76–0.94 in simulation), so the fit reports the estimates and the naive standard errors but withholds the inference built on them: z and p are NaN, show says why, confint throws an ArgumentError, approximations(fit) records it (fit.inference_withheld == true). This is ERGM.jl's mple default; the MCMLE (the method=:auto default for such a formula) or se=:bootstrap give calibrated inference.
  • se=:hessian — the same standard errors, with the naive Wald table (z, p, confint) reported: the written opt-in to what R prints for an MPLE fit. show keeps the anticonservatism warning.
  • se=:bootstrap — parametric bootstrap: simulate n_boot multilayer networks from the fitted model at θ̂ (offsets included) with simulate_multi_ergm, refit ergm_multi on each with the same offsets, and report the empirical covariance of the refits. The point estimates are unchanged; only the covariance is replaced. Offset rows stay NaN — a fixed coefficient carries no uncertainty. A replicate whose refit does not converge is excluded (warned once; fit.boot_replicates keeps it as a NaN row). The standard errors are conditional on a finite refit: the excluded replicates are the extreme ones, so the standard errors are biased downward (the warning, show and approximations say so). This is the same option, with the same keywords and the same semantics, as ERGM.mple's, and it runs on the ONE shared NetworkCore.bootstrap_cov loop. It is refused (ArgumentError) when a coefficient is fixed at ∓Inf by a boundary statistic (a network cannot be simulated at an infinite coefficient) and on a separated fit.

Keyword Arguments

  • offsets::Dict{Int,Float64}: fixed coefficients by term index
  • method::Symbol=:auto: :auto, :mple or :mcmle (above; anything else is an ArgumentError)
  • n_samples, burnin, interval, mcmle_maxiter, termination, conv_precision, conv_confidence, conv_threshold, hotelling_alpha, max_n_samples, bridge_rungs, bridge_samples, init: the MCMLE's controls (above); burnin/interval default to the dyad-scaled rule of every ERGM-family sampler
  • maxiter::Int=100, tol::Float64=1e-8: Newton iteration controls (of the MPLE, and of the MCMLE's MPLE start)
  • drop::Bool=true: fix a statistic at the boundary of its attainable range at ∓Inf (R ergm's default); false refuses such a model instead
  • se=nothing: nothing, :hessian or :bootstrap (above; anything else is refused by the shared NetworkCore.check_se)
  • n_boot::Int=100: number of bootstrap replicates (se=:bootstrap only)
  • boot_burnin, boot_interval: MCMC controls for the bootstrap simulations; nothing (default) resolves to the dyad-scaled rule shared with every ERGM-family sampler (ERGM.Extension.mcmc_defaults: 20 × n_dyads and max(100, n_dyads ÷ 10) over the within-layer dyads)
  • rng::AbstractRNG=Random.default_rng(): source of the bootstrap randomness — a fixed rng reproduces the standard errors exactly
  • threaded::Bool=true: run the bootstrap refits on all threads. The replicates are simulated from rng before any refit and each refit is deterministic, so the standard errors are identical whatever the thread count (pinned by a test)

Example

using ERGMMulti, ERGM, NetworkCore, Random
rng = Xoshiro(1)
m = MultilayerNetwork(12; directed=true)
add_layer!(m, :friendship); add_layer!(m, :advice)
for i in 1:12, j in 1:12
    i == j && continue
    rand(rng) < 0.2 && add_layer_edge!(m, :friendship, i, j)
    rand(rng) < 0.2 && add_layer_edge!(m, :advice, i, j)
end
terms = [LayerEdges(1), LayerEdges(2), InterlayerDependence(1, 2)]
mle = fit_ergm_multi(m, terms; n_samples=400, rng=Xoshiro(3))
mle.method, se_method(mle)       # (:mcmle, :fisher) — dyad-dependent: R's estimator
coeftable(mle).names             # ["L(friendship)~edges", "L(advice)~edges", "L(friendship&advice)~edges"]
size(confint(mle))               # (3, 2)
fit = fit_ergm_multi(m, terms; method=:mple)
fit.converged                    # true
fit.inference_withheld           # true — the MPLE of a dependent formula: no z, p or interval
boot = fit_ergm_multi(m, terms; method=:mple, se=:bootstrap, n_boot=50, rng=Xoshiro(2))
size(confint(boot))              # (3, 2) — parametric-bootstrap intervals
try
    fit_ergm_multi(m, terms; se=:bootstrap)     # :auto chose the MCMLE
catch e
    occursin("method=:mple", e.msg)             # true
end
source
ERGMMulti.simulate_multi_ergm — Function
simulate_multi_ergm(m::MultilayerNetwork, terms, θ; n_sim=1, burnin=nothing,
                    interval=nothing, rng=Random.default_rng())
    -> Vector{MultilayerNetwork}
simulate_multi_ergm(model::MultiERGMModel, θ; kwargs...)

Simulate multilayer networks from P(y) ∝ exp(θ'g(y)) with a Metropolis sampler restricted to within-layer dyads (matching the dyad universe of the block-diagonal model): propose toggling a random (layer, i, j), accept an addition with min(1, exp(θ'Δg)) and a removal with min(1, exp(−θ'Δg)). The chain is the ONE shared Metropolis kernel of the ERGM family, ERGM.mh_toggle!, with (layer, i, j) moves; the rng is drawn proposal-first, then acceptance, so seeded runs are reproducible.

The (m, terms, θ) form builds a MultiERGMModel first, so the terms are validated against the layers (an out-of-range layer, a missing attribute, an undirected-only term on a directed layer, ... throw before the chain starts). θ has one entry per statistic of the model (model.terms.names), which equals one per term unless a WithinLayer term expands (a multi-level NodeFactor, a Degree(0:2)).

burnin/interval default (nothing) to the dyad-scaled rule shared with every ERGM-family sampler (ERGM.Extension.mcmc_defaults): 20 × n_dyads and max(100, n_dyads ÷ 10) over the within-layer dyads.

A layer with a masked (missing) dyad is refused with an ArgumentError naming the layer (NetworkCore.missing_policies(simulate_multi_ergm) == (:error,)): the chain would otherwise toggle the unobserved dyad at its face value. Every coefficient must be finite: a ∓Inf (a boundary statistic's R-drop value, coef(fit) of such a fit) or NaN entry is refused with an ArgumentError naming it ("simulatemultiergm: every coefficient must be finite (got L(a&b)~edges = -Inf) …") — the chain would otherwise reject every proposal (θ'Δ is NaN) and return copies of the input. Remove the dropped term, as R's drop=TRUE does, and simulate from that model.

Example

using ERGMMulti, ERGM, Random
m = MultilayerNetwork(8; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
draws = simulate_multi_ergm(m, [LayerEdges(), InterlayerDependence(1, 2)],
                            [-1.5, 2.0]; n_sim=10, rng=Xoshiro(1))
length(draws)                         # 10
draws[1] isa MultilayerNetwork{true}  # true
source

StatsAPI surface

Every verb of the ecosystem's StatsAPI surface is implemented on MultiERGMResult: coef, coefnames, stderror, vcov, confint, loglikelihood, nobs, dof, aic, bic and coeftable (pinned by NetworkCore.check_statsapi(fit; required=(STATSAPI_VERBS..., :coefnames), strict=true) in the test suite).

StatsAPI.coef — Method
coef(r::MultiERGMResult) -> Vector{Float64}

The fitted coefficients, one per statistic of r.model.terms (labelled by r.model.terms.names). An offset term reports its fixed value; a statistic at the boundary of its attainable range reports ∓Inf (R's drop).

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
coef(fit) ≈ [log(2 / 10), log(1 / 11)]    # true — logit(density) per layer
source
StatsAPI.coefnames — Method
coefnames(r::MultiERGMResult) -> Vector{String}

The coefficient labels, in coef(r) order — ergm.multi's labels (L(a)~edges, L(a&b)~edges, L((a,b))~mutual, …), an offset row wrapped as offset(<label>), as R's names(coef(fit)) prints them. They are the row names of coeftable(r); the vector is a copy, so changing it does not change the fit. A method of StatsAPI.coefnames (StatsBase's coefnames).

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)]; offsets=Dict(2 => -2.0))
coefnames(fit)                          # ["L(a)~edges", "offset(L(b)~edges)"]
coefnames(fit) == coeftable(fit).names  # true
source
StatsAPI.stderror — Method
stderror(r::MultiERGMResult) -> Vector{Float64}

The standard errors the fit reports — inverse pseudo-Hessian or parametric bootstrap, whichever se_method(r) says; NaN for an offset term, 0.0 for a coefficient fixed at ∓Inf.

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
stderror(fit)[1] ≈ sqrt(1 / (12 * (2 / 12) * (10 / 12)))   # true — binomial information
fit_off = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)]; offsets=Dict(2 => -2.0))
isnan(stderror(fit_off)[2])                                 # true — fixed, no uncertainty
source
StatsAPI.vcov — Method
vcov(r::MultiERGMResult) -> Matrix{Float64}

The covariance matrix of the coefficients (p × p), of which stderror(r) is the square root of the diagonal; offset rows and columns are NaN.

Example

using ERGMMulti, LinearAlgebra
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
size(vcov(fit))                              # (2, 2)
sqrt.(diag(vcov(fit))) ≈ stderror(fit)       # true
vcov(fit)[1, 2] ≈ 0.0                        # true — the layers' MPLEs are independent
source
StatsAPI.confint — Method
confint(r::MultiERGMResult; 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(r): inverse pseudo-Hessian, parametric bootstrap or Fisher information plus Monte-Carlo error). For an MPLE fit (method=:mple) of a dyad-dependent model with se not given, whose naive pseudo-likelihood SEs under-cover, confint refuses with an ArgumentError (r.inference_withheld); refit with the MCMLE (the default) or se=:bootstrap for calibrated intervals, or with an explicit se=:hessian to accept the naive ones. A separated fit (r.separated) has no interval: every row is NaN. Offset rows are NaN: a fixed coefficient has no interval.

Example

using ERGMMulti, ERGM, NetworkCore, Random
rng = Xoshiro(3)
m = MultilayerNetwork(10; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
for l in 1:2, i in 1:10, j in 1:10
    i != j && rand(rng) < 0.3 && add_layer_edge!(m, l, i, j)
end
fit = ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
ci = confint(fit)                          # 2×2
all(ci[:, 1] .< coef(fit) .< ci[:, 2])     # true
source
StatsAPI.coeftable — Method
coeftable(r::MultiERGMResult) -> NetworkCore.CoefficientTable

The R-style coefficient table (Estimate, Std.Error, z value, Pr(>|z|)) as an inspectable NetworkCore.CoefficientTable — exactly the table show(r) prints, built from the same vectors (a method of StatsAPI.coeftable). Rows are labelled with the model's direction-aware statistic names (r.model.terms.names, ergm.multi's labels), offset rows labelled offset(<name>) as R labels them, with NaN standard error, z and p; the z → p map is the shared NetworkCore.z_pvalues. For an MPLE fit of a dyad-dependent formula with se not given (r.inference_withheld) every finite coefficient's z and p is NaN, and so is every z and p of a separated fit (r.separated).

Example

using ERGMMulti, ERGM, NetworkCore, Random
rng = Xoshiro(3)
m = MultilayerNetwork(10; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
for l in 1:2, i in 1:10, j in 1:10
    i != j && rand(rng) < 0.3 && add_layer_edge!(m, l, i, j)
end
fit = ergm_multi(m, [LayerEdges(1), LayerEdges(2)]; offsets=Dict(2 => -1.0))
tbl = coeftable(fit)
tbl.names                                   # ["L(a)~edges", "offset(L(b)~edges)"]
tbl["L(a)~edges"].estimate == coef(fit)[1]  # true
isnan(tbl[2].p_value)                       # true
source
StatsAPI.loglikelihood — Method
loglikelihood(r::MultiERGMResult) -> Float64

The maximized pseudo-log-likelihood over the within-layer dyads — the log-likelihood itself only when every term is dyad-independent (is_exact(r)) — for an MPLE fit; for a method=:mcmle fit, the log-likelihood at the estimates, by path sampling (r.mcmc.loglik_mc_se is its Monte-Carlo standard error).

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
ll = 2 * log(2 / 12) + 10 * log(10 / 12) + log(1 / 12) + 11 * log(11 / 12)
loglikelihood(fit) ≈ ll                      # true — two independent binomials
source
StatsAPI.nobs — Method
nobs(r::MultiERGMResult) -> Int

The number of within-layer dyads — the rows of the pseudo-likelihood: L · n · (n − 1) for directed layers, L · n · (n − 1) / 2 for undirected.

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2)
nobs(fit_ergm_multi(m, [LayerEdges()]))      # 24 — 2 layers × 12 ordered dyads
source
StatsAPI.dof — Method
dof(r::MultiERGMResult) -> Int

The number of estimated parameters: the free (non-offset) coefficients that are finite — a coefficient fixed at ∓Inf by a boundary statistic is not an estimated parameter, and neither is an offset.

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :b, 1, 3)
dof(fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)]))                          # 2
dof(fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)]; offsets=Dict(1 => -2.0)))  # 1
source
StatsAPI.aic — Method
aic(r::MultiERGMResult) -> Float64

-2 · loglikelihood(r) + 2 · dof(r) (pseudo-likelihood based whenever the model has a dyad-dependent term).

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
aic(fit) ≈ -2 * loglikelihood(fit) + 2 * dof(fit)    # true
source
StatsAPI.bic — Method
bic(r::MultiERGMResult) -> Float64

-2 · loglikelihood(r) + dof(r) · log(n), where n is the number of within-layer dyads the coefficients were estimated on (nobs(r), unless a boundary statistic was dropped — then the dyads it does not touch).

Example

using ERGMMulti
m = MultilayerNetwork(4; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
add_layer_edge!(m, :a, 1, 2); add_layer_edge!(m, :a, 2, 3); add_layer_edge!(m, :b, 1, 3)
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
bic(fit) ≈ -2 * loglikelihood(fit) + dof(fit) * log(nobs(fit))    # true
source

Every accessor reads the fit as it was actually made: an offset term's standard error is NaN, a boundary statistic's coefficient is ∓Inf with standard error 0, a statistic with no identifiable coefficient is NaN, dof counts only finite non-offset coefficients, and loglikelihood is a pseudo-log-likelihood for an MPLE fit unless is_exact(fit).

Goodness of Fit

ERGMMulti extends the ecosystem's single gof generic (defined in NetworkCore.jl) with a method for a multi-network fit.

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

Goodness-of-fit assessment for a fitted multilayer ERGM: simulate n_sim multilayer networks at the fitted (and offset) coefficients with simulate_multi_ergm and compare the observed data against the simulated distributions. The panels, in order:

  • "model statistics" — the fitted terms' statistics (one level per statistic, labelled as in coeftable(result)). For an MPLE fit of a dyad-dependent model this panel mostly measures the MPLE's bias, not misfit — read the auxiliary panels for that;
  • "layer edges" — the edge count of each layer (one level per layer);
  • "multiplexity" — the number of dyads tied in exactly k of the L layers, k = 0, …, L (ordered dyads on directed layers): the cross-layer structure no single-layer panel sees;
  • per layer <name>, the auxiliary distributions of gof.ergm, none of which the model fits by construction: "degree: <name>" on undirected layers, "idegree: <name>" and "odegree: <name>" on directed ones (the number of actors with degree 0, 1, …), and "esp: <name>" (the number of ties whose endpoints share 0, 1, … partners; outgoing two-paths i→k→j on directed layers, statnet's default OTP). Levels run up to the largest value seen in the observed or any simulated network.

burnin/interval default to the dyad-scaled rule of every ERGM-family sampler (ERGM.Extension.mcmc_defaults). Extends NetworkCore.jl's shared gof generic and returns the shared NetworkCore.GOFResult container; per-level p-values are two-sided Monte-Carlo p-values computed with the (1 + k)/(N + 1) estimator (never exactly zero). The fitted network is never masked (the estimator refused it), so the simulation needs no missing= policy. Geodesic-distance panels are not implemented.

A fit with a coefficient fixed at ∓Inf (a statistic at the boundary of its attainable range, R's drop) is simulated as fitted: the chain starts at the observed network, which is at that bound, and never moves the statistic off it. A NaN coefficient of a dyad-independent statistic is simulated at 0 (any value gives the same model); a dyad-dependent NaN, or statistics fixed at both -Inf and +Inf, are refused with an ArgumentError naming them.

Example

using ERGMMulti, ERGM, NetworkCore, Random
rng = Xoshiro(4)
m = MultilayerNetwork(10; directed=true)
add_layer!(m, :a); add_layer!(m, :b)
for l in 1:2, i in 1:10, j in 1:10
    i != j && rand(rng) < 0.3 && add_layer_edge!(m, l, i, j)
end
fit = fit_ergm_multi(m, [LayerEdges(1), LayerEdges(2)])
g = gof(fit; n_sim=20, burnin=2000, interval=50, rng=Xoshiro(5))
g isa GOFResult                            # true
[panel.name for panel in g.statistics]
# ["model statistics", "layer edges", "multiplexity", "idegree: a", "odegree: a",
#  "esp: a", "idegree: b", "odegree: b", "esp: b"]
g.statistics[2].labels                     # ["a", "b"] — one level per layer
g.statistics[3].labels                     # ["0", "1", "2"] — dyads tied in k layers
all(0 .< g.statistics[1].p_values .<= 1)   # true — (1+k)/(N+1), never 0
source

Renamed and removed names

0.2.0 is the first release. These names of the development versions were removed without a deprecation period; there is no alias for them.

RemovedUse instead
fit_multi_ergm(m, terms; ...)fit_ergm_multi(m, terms; ...) or ergm_multi(m, terms; ...)
coefficient labels L.edges.1, L.edges.all, L.mutual.1, L.triangle.1ergm.multi's labels with the layer names: L(friendship)~edges, L((friendship,advice))~edges, L(friendship)~mutual, L(friendship)~triangle
L1.<term>, L1+2.<term>, Lall.<term> (WithinLayer)L(friendship)~<term>, L((friendship,advice))~<term>
duplex.1.2 (InterlayerDependence)L(friendship&advice)~edges
duplex.mutual.1.2 (MultiplexMutual)L(friendship,advice)~mutual
<label> (offset) (offset rows of coeftable)offset(<label>)
the MPLE as the default for every formulamethod = :auto (R's rule); pass method = :mple for the MPLE of a dyad-dependent formula