Estimation and Simulation

fit_stergm is an exported alias for stergm. The StatsAPI verbs coef, stderror, vcov, loglikelihood, nobs, dof, aic and bic are defined on STERGMResult (stacked formation-then-persistence vector) alongside the two documented below; NetworkCore.check_statsapi(fit; strict = true) pins the full surface.

TERGM.stergm — Function
stergm(networks, formation, dissolution; method=:auto, kwargs...) -> STERGMResult
fit_stergm(networks, formation, dissolution; method=:auto, kwargs...) -> STERGMResult

Fit a STERGM to a panel of networks (fit_stergm === stergm).

method:

  • :auto (default) — resolved by ERGM.jl's rule (ERGM.resolve_method): the CMPLE when neither formula has a dyad-dependent term (there the conditional pseudo-likelihood IS the conditional likelihood, so the CMPLE is the exact CMLE and no MCMC is run), the CMLE otherwise. R's tergm() has no default estimator — it requires estimate= — so this default is TERGM.jl's choice: the conditional MLE whenever it differs from the CMPLE.
  • :cmple — conditional maximum pseudo-likelihood on the formation/dissolution networks (cmple). Exact CMLE for dyad-independent terms; an approximation for dyad-dependent terms (Mutual, GWESP, ...), for which the default fit reports estimates and naive standard errors but no z, p or interval — pass se = :bootstrap for parametric-bootstrap inference. tergm's estimate = "CMPLE".
  • :cmle — Monte-Carlo conditional maximum likelihood (cmle): tergm's estimate = "CMLE". For a dyad-independent formula it returns the CMPLE (the two coincide) without running MCMC.
  • :egmme — throws an ArgumentError (EGMME is not implemented; see TERGM.egmme).

Remaining keyword arguments are forwarded to the estimator. A keyword that estimator does not take is an ArgumentError naming the estimator that does — e.g. se = :bootstrap (a CMPLE keyword) on a dyad-dependent formula, which method = :auto fits by CMLE, asks for method = :cmple.

networks is the panel: a vector of at least two Networks observed at successive times, first. formation and dissolution are each a term or any collection of terms fit_ergm accepts (a push!-built Vector{Any}, a bare Edges(), nested vectors), normalised by STERGM. The common slips are said in words rather than as a MethodError: the panel in the wrong position (stergm(terms, terms, networks)) is ArgumentError: arguments are swapped …, a single network instead of a panel is ArgumentError: stergm needs a panel ….

Coming from R tergm: tergm(nets ~ Form(~edges + mutual) + Persist(~edges), estimate = "CMLE") (R requires estimate=) is stergm(nets, [Edges(), Mutual()], [Edges()]) — Form() is the second argument, Persist() the third; estimate = "CMPLE" is method = :cmple.

Example

using TERGM, ERGM
t0 = network(5; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(5; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
fit.converged                     # true
formation_coef(fit)[1] ≈ log(1 / 17)   # 1 of 18 prior non-ties formed
persistence_coef(fit)[1] ≈ 0.0         # 1 of 2 prior ties persisted
coef(stergm([t0, t1], Edges(), Edges())) == coef(fit)   # true: a bare term needs no brackets
try; stergm([Edges()], [Edges()], [t0, t1]); catch e; occursin("swapped", e.msg); end   # true
source
TERGM.cmple — Function
cmple(model::STERGMModel; maxiter=100, tol=1e-8, se=nothing,
      n_boot=200, burnin=nothing, rng=Random.default_rng()) -> STERGMResult

Conditional maximum pseudo-likelihood: for every transition t,

  • formation rows are the non-edges of Y{t-1}; the response is edge presence in Yt and change statistics are evaluated on the formation network Y⁺ = Y{t-1} ∪ Yt;
  • dissolution rows are the edges of Y{t-1}; the response is persistence into Yt and change statistics are evaluated on the dissolution network Y⁻ = Y{t-1} ∩ Yt.

Rows pool across transitions; the two logistic likelihoods are maximized independently (separability) by ERGM.jl's MPLE design fitter on the shared NetworkCore.newton_fit/logistic_derivatives kernel (maxiter Newton iterations, tolerance tol).

Nothing about a bad fit is silent. A fit that exhausts maxiter is returned with converged == false, a warning (cmple: the Newton iteration did not converge in maxiter=…), the caveat under show's tables and an entry in approximations(fit).

A statistic at the boundary of its attainable range — a NodeMatch no prior same-group tie of which persists, a Triangle on a triangle-free auxiliary network, … — has no finite CMPLE. As R ergm does (its default drop=TRUE), cmple warns "observed statistic(s) … are at their smallest attainable values. Their coefficients will be fixed at -Inf", returns that coefficient as -Inf (+Inf at the largest value) with standard error 0 and p-value 0, and fits the remaining coefficients on the free dyads the dropped statistic does not touch — the exact limit of the pseudo-likelihood. dof(fit) counts the finite coefficients and bic uses the dyads they were estimated on (fit.n_kept), as R's logLik does; approximations(fit) and show name the fixed coefficients. (R tergm 4.2 itself does not drop: its operator terms bypass ergm's attainable-range check, so it warns "The MPLE does not exist!" and returns a large finite value on the asymptote, e.g. −19.6 with a standard error of 1600 — the same finite coefficients to 1e-6, but an arbitrary number where TERGM.jl reports -Inf.)

Perfect separation by a combination of statistics — which the boundary test cannot see — leaves the pseudo-likelihood without a maximum. R warns "The MPLE does not exist!"; cmple decides it with the ecosystem's shared verdict (NetworkCore.logistic_separation, an exact linear programme, via ERGM.jl's design fitter), warns "cmple: the CMPLE does not exist (separation)" naming the separating terms, and returns the fit with converged == false; z values, p-values and confint are then NaN, as for every unconverged CMPLE.

Standard errors

se selects the standard errors (validated by NetworkCore.check_se):

  • :hessian — inverse observed pseudo-likelihood information. Exact for a dyad-independent formula (there the CMPLE is the CMLE). The default (se = nothing) is :hessian with the inference it supports decided by the formula — see "Inference under dyadic dependence".
  • :bootstrap — parametric bootstrap: each of n_boot replicates simulates every transition from the fitted model, conditional on the observed previous panel (simulate_stergm, burnin toggles per side), refits the CMPLE on the simulated transitions, and the standard errors are the empirical covariance of the refits (through the shared NetworkCore.bootstrap_cov; reproducible from rng, identical at any thread count). It is the same keyword, and the same procedure, as ERGM.jl's mple(se = :bootstrap) and is calibrated under dyadic dependence at any panel length (coverage 0.93–0.98 in the simulations below). The point estimates are unchanged; vcov becomes the joint bootstrap covariance and boot_replicates holds the refits. A replicate without a finite refit is excluded with one warning and recorded in approximations(fit). Refused (ArgumentError) for a fit that did not converge or carries a ±Inf coefficient — a panel cannot be simulated at it.
  • :block_bootstrap — per-transition block bootstrap (the btergm scheme): resample the time-transitions with replacement n_boot times and refit. Its resampling units are the transitions, so it under-covers on short panels and is not a remedy for anything there: it is refused below 10 transitions (ArgumentError) and warned about below 20. Refused also when the point estimate carries a ±Inf coefficient.

Inference under dyadic dependence

For a formula with a dyad-dependent term (has_dyad_dependent(model)) the naive inverse-Hessian standard errors are not calibrated in general. In simulation (30 actors, 200 panels per configuration, 1–10 transitions, 95 % Wald intervals) they covered 0.89–0.96 for Form(edges + mutual) + Persist(edges + mutual) but only 0.70–0.82 on the formation side of edges + GWESP(0.5); the parametric bootstrap covered 0.91–0.98 in both. So, as ERGM.jl's mple does, a CMPLE fit (default se) of a dyad-dependent formula reports its point estimates and naive standard errors but no inference built on them: the z and p columns are NaN (with a note saying why), confint throws an ArgumentError, fit.inference_withheld is true and approximations(fit) records it. For inference use se = :bootstrap or method = :cmle. Passing se = :hessian explicitly is the written opt-in to the naive Wald table (what R tergm's CMPLE summary prints), shown with the pseudo-likelihood caveat. Dyad-independent formulas are unaffected.

Example

using TERGM, ERGM, Random
rng = Xoshiro(1)
panels = [network(12; directed=true) for _ in 1:4]
for i in 1:12, j in 1:12
    i != j && rand(rng) < 0.2 && add_edge!(panels[1], i, j)
end
for t in 2:4, i in 1:12, j in 1:12
    i == j && continue
    keep = has_edge(panels[t-1], i, j) ? rand(rng) < 0.7 : rand(rng) < 0.1
    keep && add_edge!(panels[t], i, j)
end
model = STERGMModel(STERGM([Edges(), Mutual()], [Edges()]), panels)
fit = cmple(model)
fit.inference_withheld          # true: a dyad-dependent CMPLE, default se
boot = cmple(model; se=:bootstrap, n_boot=50, rng=Xoshiro(2))
se_method(boot)                 # :bootstrap
size(boot.boot_replicates)      # (50, 3)
coef(boot) == coef(fit)         # true: only the standard errors change
size(confint(boot))             # (3, 2)
source
TERGM.cmle — Function
cmle(model::STERGMModel; n_samples=1000, burnin=nothing, interval=nothing,
     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=16 * n_samples,
     init=nothing, bridge_rungs=16, bridge_samples=n_samples,
     newton_maxiter=100, tol=1e-8, rng=Random.default_rng(),
     verbose=false) -> STERGMResult

Conditional maximum likelihood by MCMC — R tergm's estimate = "CMLE".

By separability the conditional likelihood is a product of a formation and a persistence likelihood, each an exponential family on a constrained sample space: Y⁺t ranges over the networks containing Y{t−1} with statistics evaluated on Y⁺t, Y⁻t over the sub-networks of Y_{t−1}, and the sufficient statistic of a side is its model statistics summed over transitions. Each side is fit separately:

  • A side with no dyad-dependent term is fit exactly: its CMPLE is its CMLE, so no MCMC is run. For a dyad-independent formula cmle therefore returns the coefficients, standard errors and log-likelihood of cmple (fit.mcmc.formation.exact == true).
  • A side with a dyad-dependent term is fit by Monte-Carlo MLE, started at its CMPLE (or init). Every iteration draws n_samples pooled statistics — one Metropolis chain per transition on the free dyads of that side (the kernel of simulate_stergm, ERGM.mh_toggle! with a uniformly drawn free dyad), started at the observed auxiliary network, burnin toggles (default: ERGM.jl's dyad-scaled rule, 20 per free dyad), one draw every interval toggles (default: 2 per free dyad) — and runs ERGM.jl's MCMLE iteration (ERGM.Extension.mcmle_solve): the update θ += γ·Σ̂⁻¹(g_obs − ḡ) with Hummel's step length γ (from gamma0, at most doubling per iteration, norm-capped at max_step_norm). The stopping rule is ERGM.jl's, hence R ergm 4's: at full step length, termination = :confidence (default) declares convergence when the estimating equation at the updated coefficients lies, with confidence conv_confidence, inside the tolerance region of precision conv_precision (ERGM.Extension.confidence_test); when the test fails near the solution the next sample is enlarged as R does, up to max_n_samples. termination = :hotelling is the older rule (every t-ratio |g_obs − ḡ|/sd below conv_threshold and a Hotelling T² test non-significant at hotelling_alpha).

Standard errors are the inverse Fisher information estimated from the final MCMC sample plus the Monte-Carlo component of the estimate (ERGM.Extension.mcmle_covariance); se_method(fit) == :fisher, and fit.mcmc.<side>.mcmc_se is the Monte-Carlo standard error alone.

The log-likelihood (hence AIC/BIC) is path-sampled: Simpson's rule over bridge_rungs intervals (bridge_samples draws per rung, thinned by ERGM.jl's dyad-scaled interval unless interval is given) from a dyad-independent reference — the CMPLE of the side's dyad-independent terms — where the likelihood is exact. bridge_rungs = 0 skips it (loglikelihood, aic, bic are NaN).

init is a stacked start (formation, then persistence — coef(fit) of an earlier fit, to continue an unconverged one). newton_maxiter and tol control the CMPLE starts and the exact sides. All randomness comes from rng: one seed per chain is drawn from it up front, so a fit is reproducible and identical at any thread count.

Refusals and loud results. A dyad-dependent side whose CMPLE start does not exist (a statistic at the boundary of its attainable range — no finite MLE exists either — a separated design, or an empty side) is refused with an ArgumentError. A fit that exhausts maxiter is returned with converged == false, a warning quoting the stopping rule's verdict, the caveat in show and an entry in approximations(fit); fit.mcmc holds the per-side diagnostics (iterations, step_length, termination, termination_p, and — recomputed on the final sample — t_ratios, hotelling_p, n_eff, n_samples, mcmc_se).

Validation. With Mutual as the only dyad-dependent term the conditional likelihood factorises over pairs of actors and the exact CMLE is computable by enumeration; the test suite compares cmle with it and with tergm's CMLE on two panels (fixture cmle_stergm.toml).

Example

using TERGM, ERGM, Random
rng = Xoshiro(1)
panels = [network(12; directed=true) for _ in 1:4]
for i in 1:12, j in 1:12
    i != j && rand(rng) < 0.2 && add_edge!(panels[1], i, j)
end
for t in 2:4, i in 1:12, j in 1:12
    i == j && continue
    keep = has_edge(panels[t-1], i, j) ? rand(rng) < 0.7 : rand(rng) < 0.1
    keep && add_edge!(panels[t], i, j)
end
model = STERGMModel(STERGM([Edges(), Mutual()], [Edges()]), panels)
fit = cmle(model; n_samples=500, rng=Xoshiro(2))
fit.method, se_method(fit)            # (:cmle, :fisher)
fit.mcmc.formation.exact              # false: Mutual needs MCMC
fit.mcmc.persistence.exact            # true: edges alone is fit exactly
persistence_coef(fit) == persistence_coef(cmple(model))   # true
size(confint(fit))                    # (3, 2)

exact = cmle(STERGMModel(STERGM([Edges()], [Edges()]), panels))
coef(exact) == coef(cmple(STERGMModel(STERGM([Edges()], [Edges()]), panels)))   # true
source
TERGM.egmme — Function
TERGM.egmme(model::STERGMModel; kwargs...)

Equilibrium Generalized Method of Moments estimation is not implemented and this function is not exported — exporting it would advertise an estimator that does not exist. It is retained, and reachable as TERGM.egmme, only so that calling it raises an explanatory ArgumentError rather than an UndefVarError; stergm(...; method = :egmme) throws the same error.

Use cmple or cmle on panel data.

source
TERGM.formation_coef — Function
formation_coef(r::STERGMResult) -> Vector{Float64}

The formation model's coefficients: log-odds contributions to a prior non-tie forming, one per formation term (r.model.formula.formation).

Example

using TERGM, ERGM
t0 = network(5; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(5; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
formation_coef(fit)[1] ≈ log(1 / 17)   # 1 of 18 prior non-ties formed: logit(1/18)
approximations(fit) == String[]        # true: both sides have a finite CMPLE
source
TERGM.formation_se — Function
formation_se(r::STERGMResult) -> Vector{Float64}

Standard errors of formation_coef; se_method(r) says how they were obtained (:hessian, :bootstrap, :block_bootstrap, or :fisher for a CMLE fit).

Example

using TERGM, ERGM
t0 = network(5; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(5; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
formation_se(fit) == stderror(fit)[1:1]   # true
formation_se(fit)[1] ≈ sqrt(1 / (18 * (1/18) * (17/18)))   # true: Bernoulli information of 18 rows
source
TERGM.persistence_coef — Function
persistence_coef(r::STERGMResult) -> Vector{Float64}

The dissolution model's coefficients in tergm's persistence (Persist()) parameterisation: log-odds contributions to a prior tie persisting, one per dissolution term (r.model.formula.dissolution). Positive values mean ties last longer; tergm's Diss() coefficients are -persistence_coef(r).

Example

using TERGM, ERGM
t0 = network(5; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(5; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
persistence_coef(fit)[1] ≈ 0.0   # 1 of 2 prior ties persisted: logit(1/2)
approximations(fit) == String[]  # true: both sides have a finite CMPLE
source
TERGM.persistence_se — Function
persistence_se(r::STERGMResult) -> Vector{Float64}

Standard errors of persistence_coef; se_method(r) says how they were obtained (:hessian, :bootstrap, :block_bootstrap, or :fisher for a CMLE fit).

Example

using TERGM, ERGM
t0 = network(5; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(5; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
persistence_se(fit) == stderror(fit)[2:2]   # true
persistence_se(fit)[1] ≈ sqrt(2)             # true: 2 Bernoulli rows at p = 1/2
source
ERGM.has_dyad_dependent — Method
has_dyad_dependent(model::STERGMModel) -> Bool

Method on ERGM.jl's exported predicate: whether either formula (formation or dissolution) contains a dyad-dependent term (is_dyad_dependent; the temporal terms are dyad-independent — they condition only on the exogenous previous network).

This is THE predicate that decides whether CMPLE is an approximation: when both formulas are dyad-independent the conditional pseudo-likelihood is the conditional likelihood, so CMPLE is the exact CMLE and the inverse-Hessian standard errors are the exact ML ones. Used by show(::STERGMResult) (the prose caveat), by is_exact(::STERGMResult) (the machine-readable answer) and by the rule that withholds naive inference, so the three cannot drift apart.

Example

using TERGM, ERGM
t0 = network(5; directed=true); add_edge!(t0, 1, 2)
t1 = network(5; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
has_dyad_dependent(STERGMModel(STERGM([Edges(), Delrecip()], [Edges()]), [t0, t1]))  # false
has_dyad_dependent(STERGMModel(STERGM([Edges()], [Edges(), Mutual()]), [t0, t1]))    # true
source
StatsAPI.coeftable — Method
coeftable(r::STERGMResult) -> NetworkCore.CoefficientTable

The R-style coefficient table (Estimate, Std.Error, z value, Pr(>|z|)) of the stacked coefficients — formation first, then persistence — as an inspectable NetworkCore.CoefficientTable (a method of StatsAPI.coeftable, the ecosystem's ONE coeftable binding). Rows are labelled as summary(tergm) labels them: Form(1)~<term> and Persist(1)~<term>, with <term> ERGM.jl's direction-aware R label (gwesp.OTP.fixed.0.5 on a directed panel). The numbers are exactly the ones show(r) prints in its Formation: / Persistence: blocks — both are built from the same two tables — and a coefficient fixed at ±Inf by a boundary statistic carries p = 0, as R prints it. Rows can be read by index or by name.

Example

using TERGM, ERGM, NetworkCore
nets = [network(6; directed=true) for _ in 1:3]
for (t, (i, j)) in enumerate([(1, 2), (2, 3), (3, 4)]); add_edge!(nets[t], 1, 2); add_edge!(nets[t], i, j); end
fit = stergm(nets, [Edges()], [Edges()])
tbl = coeftable(fit)
tbl.names                                   # ["Form(1)~edges", "Persist(1)~edges"]
tbl["Persist(1)~edges"].estimate == persistence_coef(fit)[1]   # true
tbl[1].std_error == formation_se(fit)[1]    # true
source
StatsAPI.coefnames — Method
coefnames(r::STERGMResult) -> Vector{String}

The coefficient labels in coef(r) order — formation first, then persistence — as summary(tergm) and R's names(coef(fit)) give them: Form(1)~<term> and Persist(1)~<term>. Identical to coeftable(r).names (a method of StatsAPI.coefnames); a fresh vector.

Example

using TERGM, ERGM, NetworkCore
nets = [network(6; directed=true) for _ in 1:3]
for (t, (i, j)) in enumerate([(1, 2), (2, 3), (3, 4)]); add_edge!(nets[t], 1, 2); add_edge!(nets[t], i, j); end
fit = stergm(nets, [Edges()], [Edges()])
coefnames(fit)                              # ["Form(1)~edges", "Persist(1)~edges"]
coefnames(fit) == coeftable(fit).names      # true
source
StatsAPI.confint — Method
confint(r::STERGMResult; level=0.95) -> Matrix{Float64}

Normal-theory (Wald) confidence limits θ̂ ± z_{(1+level)/2} · se, one row per stacked coefficient (formation first, then persistence; the order of coef(r)), lower limit in column 1 and upper in column 2 (a method of StatsAPI.confint). The standard errors are the ones the fit reports (r.se_type says which). A CMPLE fit (default se) of a dyad-dependent formula reports no interval — confint throws an ArgumentError naming the ways to get one (se = :bootstrap, method = :cmle, or the explicit opt-in se = :hessian, whose intervals inherit the naive pseudo-likelihood standard errors; see cmple). A coefficient fixed at ±Inf has a degenerate interval [±Inf, ±Inf], as it has standard error 0. level must lie in (0, 1) (ArgumentError otherwise).

Example

using TERGM, ERGM, NetworkCore
nets = [network(6; directed=true) for _ in 1:3]
for (t, (i, j)) in enumerate([(1, 2), (2, 3), (3, 4)]); add_edge!(nets[t], 1, 2); add_edge!(nets[t], i, j); end
fit = stergm(nets, [Edges()], [Edges()])
ci = confint(fit)                          # 2×2
all(ci[:, 1] .< coef(fit) .< ci[:, 2])     # true
confint(fit; level=0.9)                    # narrower
source
NetworkCore.objective — Method
objective(r::STERGMResult) -> Symbol

:conditional_pseudolikelihood — the pooled logistic pseudo-likelihood over the free dyads of the formation (Y⁺) and dissolution (Y⁻) auxiliary networks — for a CMPLE fit and for a CMLE fit of a dyad-independent formula (where the two coincide and no MCMC is run); :mc_likelihood for a CMLE fit that maximized a Monte-Carlo approximation of the conditional likelihood.

source
NetworkCore.is_exact — Method
is_exact(r::STERGMResult) -> Bool

true iff the fit converged, every coefficient is finite, and every term in both formulas is dyad-independent: there the conditional pseudo-likelihood is the conditional likelihood, so CMPLE is the exact CMLE. Add one dyad-dependent term to either formula and CMPLE reports false — the approximation is a property of the fit, not of the method name — and so does CMLE, which then maximizes a Monte-Carlo approximation of the likelihood. A fit whose pseudo-likelihood has no finite maximum (converged == false, or a coefficient fixed at ±Inf by a boundary statistic) is not an exact estimate of anything and reports false too.

source
TERGM.simulate_stergm — Function
simulate_stergm(prev_net, formula::STERGM, θ_form, θ_diss;
                burnin=nothing, rng=Random.default_rng()) -> Network

Simulate one STERGM transition from prev_net: draw the formation network Y⁺ (Metropolis over the non-edges of prev_net, under the formation coefficients θ_form) and the dissolution network Y⁻ (over its edges, under the persistence coefficients θ_diss), then combine Y_t = (Y⁺ \ Y_{t−1}) ∪ Y⁻.

burnin is the number of Metropolis toggles per side; nothing (the default) resolves to ERGM.jl's dyad-scaled rule (ERGM.Extension.mcmc_defaults: 20 toggles per free dyad of that side). Both samplers run on the shared ERGM.mh_toggle! kernel and draw only from rng. A move toggles one dyad drawn uniformly from the free dyads of the side — the symmetric proposal on the constrained sample space, whose stationary distribution is exactly the constrained model (verified against enumeration in the test suite).

formula is validated against prev_net with ERGM.jl's formula rules (a nodal term's attribute must exist there; ArgumentError naming the side and the term otherwise) and expanded exactly as STERGMModel expands it, so a raw multi-level NodeFactor(:grp) takes one coefficient per level and a fitted model's expanded formula passes through unchanged. θ_form/θ_diss must have one entry per expanded term; the ArgumentError otherwise names the side's terms, both counts and the per-side accessors (formation_coef(fit) / persistence_coef(fit), not the stacked coef(fit)).

Example

using TERGM, ERGM, Random
prev = network(10; directed=true)
for i in 1:10, j in 1:10
    i != j && (i + j) % 3 == 0 && add_edge!(prev, i, j)
end
formula = STERGM([Edges()], [Edges()])
yt = simulate_stergm(prev, formula, [-30.0], [30.0]; rng=Xoshiro(1))
ne(yt) == ne(prev)     # true: no formation, full persistence
source
simulate_stergm(result::STERGMResult, n_steps; kwargs...) -> Vector{Network}

Simulate n_steps transitions forward from the last observed panel of a fitted STERGM, at its fitted formation and persistence coefficients (keywords as for simulate_network_sequence).

Example

using TERGM, ERGM, Random
t0 = network(6; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(6; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
future = simulate_stergm(fit, 3; rng=Xoshiro(1))
length(future)          # 4: the last observed panel plus 3 simulated ones
source
TERGM.simulate_network_sequence — Function
simulate_network_sequence(formula, init_net, n_steps, θ_form, θ_diss;
                          burnin=nothing, rng=Random.default_rng()) -> Vector{Network}

Simulate a sequence of n_steps STERGM transitions starting from init_net (the returned sequence includes the initial network as its first element and has the concrete element type of init_net). θ_diss are persistence coefficients; burnin/rng as for simulate_stergm.

Example

using TERGM, ERGM, Random
init = network(8; directed=true)
for i in 1:8, j in 1:8
    i != j && (i + j) % 4 == 0 && add_edge!(init, i, j)
end
seq = simulate_network_sequence(STERGM([Edges()], [Edges()]), init, 5,
                                [-2.0], [1.0]; rng=Xoshiro(3))
length(seq)                      # 6
eltype(seq)                      # Network{Int64, true}
source
NetworkCore.gof — Method
gof(result::STERGMResult; n_sim=50, burnin=nothing, rng=...) -> GOFResult

Transition-level goodness of fit, after gof.tergm: for each observed transition Y{t−1} → Yt, simulate n_sim STERGM transitions from the same starting panel Y_{t−1} at the fitted coefficients, and compare — pooled over transitions — what was observed to what the model reproduces.

Extends NetworkCore.jl's shared gof generic and returns the shared NetworkCore.GOFResult container with these GOFStatistic panels, in order:

  1. "tie changes" (levels formed, persisted): the pooled counts of ties that formed and ties that persisted. Not a diagnostic for a formula containing Edges() on that side — those counts are the sufficient statistics of Form~edges / Persist~edges, which the CMPLE reproduces in expectation by construction (p-values near 1 are expected); it is a sanity check of the simulator, and the one panel that speaks for an edges-free formula.
  2. "formation statistics" and "persistence statistics": every term of the formation model evaluated on the observed formation network Y⁺ = Y{t−1} ∪ Yt against its value on the simulated Y⁺, and the same for the persistence model on Y⁻ = Y{t−1} ∩ Yt (labels are the fitted coefficients'). The edges level is again reproduced by construction; the others are the model-statistic check of gof.tergm — the first place a dyad-dependent CMPLE (a Mutual, Triangle, GWESP, … whose pseudo-likelihood point estimate may be biased) shows a misfit.
  3. The degree distribution of the simulated Yt against the observed Yt, pooled over transitions — "idegree" and "odegree" (levels 0 … n−1) for a directed panel, "degree" for an undirected one: the out-of-model check, informative for every formula (tergm's default gof statistics are the degree and duration distributions).

Two-sided Monte-Carlo p-values use the (1 + k)/(N + 1) estimator (never exactly zero). One seed per (transition, simulation) is drawn from rng up front and each simulation runs on its own Xoshiro(seed) on every thread, so the result is reproducible from rng alone and thread-count independent. burnin is forwarded to simulate_stergm. gof(fit) is the one goodness-of-fit verb of the model family.

Example

using TERGM, ERGM, Random
t0 = network(6; directed=true); add_edge!(t0, 1, 2); add_edge!(t0, 3, 4)
t1 = network(6; directed=true); add_edge!(t1, 1, 2); add_edge!(t1, 2, 3)
fit = stergm([t0, t1], [Edges()], [Edges()])
g = gof(fit; n_sim=20, rng=Xoshiro(1))
[s.name for s in g.statistics]   # ["tie changes", "formation statistics", "persistence statistics", "idegree", "odegree"]
g.statistics[1].labels           # ["formed", "persisted"]
g.statistics[2].labels           # ["edges"]
source