Types
TERGM.TERGM — Module
TERGM.jl - Temporal Exponential Random Graph ModelsSeparable Temporal ERGMs (STERGM) for networks observed at discrete time points (Krivitsky & Handcock 2014), following R tergm:
- the transition Y{t-1} → Yt factors into a formation model on the formation network Y⁺ = Y{t-1} ∪ Yt and a dissolution model on the dissolution network Y⁻ = Y{t-1} ∩ Yt;
- formation statistics are evaluated on Y⁺ (free dyads: the non-edges of Y{t-1}), dissolution statistics on Y⁻ (free dyads: the edges of Y{t-1});
- estimation is by CMPLE — conditional maximum pseudo-likelihood over the free dyads of the auxiliary networks, pooled across transitions (it equals the CMLE exactly for dyad-independent terms and is an approximation otherwise;
method = :cmple) — or by CMLE, the Monte-Carlo conditional maximum likelihood on the same constrained sample spaces (method = :cmle). The defaultmethod = :autois R tergm's choice: the CMLE for a dyad-dependent formula, the (exact) CMPLE for a dyad-independent one; - simulation draws Y⁺ and Y⁻ with Metropolis samplers constrained to the free dyads and combines them into Y_t.
The dissolution model is parameterized in terms of persistence (tergm's Persist()): positive coefficients mean ties are more likely to persist. The fitted coefficients are persistence_coef; tergm's Diss() parameterisation is their negation.
TERGM.STERGM — Type
STERGMA separable temporal ERGM formula: formation terms and dissolution (persistence) terms. Terms may be standard ERGM.jl terms (evaluated on the auxiliary networks) or TemporalTerms (also conditioned on Y{t-1}). Each side is any collection of terms `fitergmwould accept — aVector{<:AbstractERGMTerm}, apush!-builtVector{Any}, a bare term, a vector nesting vectors of terms — normalised by ERGM.jl's term-list collector, so a non-term element is refused with its position and type (andEdgesinstead ofEdges()gets the "did you mean" hint). Both sides must be non-empty (ArgumentErrornaming the side otherwise); the fields areformationanddissolution. Terms are validated against the panels when the formula is bound to data by [STERGMModel`](@ref).
Example
using TERGM, ERGM
f = STERGM([Edges(), Delrecip()], [Edges(), Mutual()])
f.formation # AbstractERGMTerm[Edges(), Delrecip()]
length(f.dissolution) # 2
f # STERGM(formation: edges + delrecip; persistence: edges + mutual)
terms = []; push!(terms, Edges()); push!(terms, Mutual())
STERGM(terms, Edges()).formation == f.dissolution # true: Vector{Any} and a bare term are fine
try; STERGM(AbstractERGMTerm[], [Edges()]); catch e; e isa ArgumentError; end # trueTERGM.STERGMModel — Type
STERGMModel{T,D}A STERGM formula bound to an observed network panel — a vector of Network{T,D} (vertex type T, directedness D, both taken from the panels, so is_directed(model) == D is a type-level fact and the networks field is a concretely typed vector).
Construction (STERGMModel(formula, networks)) requires at least two panels that share size, directedness and vertex type; refuses a two-mode (bipartite) panel and a panel containing a self-loop (the one-mode CMPLE, the free-dyad lists and the sampler range over the off-diagonal one-mode dyads only, exactly as ERGM.jl refuses the same networks); refuses any panel with masked (missing) dyads — CMPLE would enumerate them at face value; refuses the memory terms EdgeStability/PersistentEdge/NewEdge in either formula (constant on the free dyads of a separable model) and ERGM.jl's Offset terms (not implemented here: the coefficient would be estimated, not held fixed); and validates both formulas against every panel with ERGM.jl's own formula validation (ERGM.Extension.validate_formula): a declared vertex attribute must exist and be set on every vertex, Mutual/Delrecip are refused on undirected panels, Kstar/GWDegree/Degree on directed ones (use OStar/IStar, GWODegree/GWIDegree, ODegree/IDegree), and an EdgeCov matrix must be n×n. The ArgumentError names the side (formation/dissolution), the panel, the term and the fix.
Both formulas are then expanded exactly as an ERGMModel expands its terms (ERGM.jl's materialize): a multi-level NodeFactor(:grp) becomes one nodefactor.grp.<level> statistic per non-base level, a multi-cell NodeMix(:grp) one mix.grp.<l1>.<l2> per selected cell, and Degree(0:2)/IDegree/ODegree one degree<d> per degree — one coefficient per statistic, labelled as R tergm labels them. The stored formula holds the expanded, single-statistic terms (model.formula.formation is what formation_coef is indexed by). Levels, cells and degrees are resolved from the first panel, as R tergm resolves them from the union of the panels: a level absent from a later panel has an all-zero column on that transition, and a later panel carrying a level the first one lacks is refused, naming the panel and the value. The attribute values themselves are read per transition from the panel the transition starts at, so a time-varying attribute is honoured.
show prints one line — panels, size, directedness, free dyads and the two formulas' coefficient labels — never the panels themselves.
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)
model = STERGMModel(STERGM([Edges()], [Edges()]), [t0, t1])
is_directed(model) # true
typeof(model) # STERGMModel{Int64, true}
model # STERGMModel{Int64,true}: 2 panels of 5 vertices (directed), 20 free dyads; formation: edges; persistence: edges
bip = [network(6; bipartite=3), network(6; bipartite=3)]
try; STERGMModel(STERGM([Edges()], [Edges()]), bip); catch e; e isa ArgumentError; end # trueTERGM.STERGMResult — Type
STERGMResult{T,D}Fitted STERGM. The dissolution model is fit in tergm's persistence (Persist()) parameterisation: persistence_coef are persistence log-odds (positive = ties last longer; tergm's Diss() coefficients are their negation).
Fields beyond the coefficients and standard errors:
method—:cmpleor:cmle.loglik_formation,loglik_dissolution— the maximized conditional pseudo-log-likelihoods (:cmple), or the path-sampled conditional log-likelihoods (:cmle;NaNwhenbridge_rungs = 0).vcov— the joint covariance of the stacked (formation, then persistence) coefficients: block-diagonal by separability forse_type == :hessianand:fisher, the empirical covariance of the refits for the two bootstraps.se_type— how the standard errors were obtained::hessian(inverse observed pseudo-likelihood information),:bootstrap(parametric bootstrap),:block_bootstrap(per-transition block bootstrap) or:fisher(a CMLE fit: inverse Fisher information from the MCMC sample plus the Monte-Carlo component).boot_replicates— then_boot × prefitted coefficients of a bootstrap (rows with a non-finite refit are kept asNaNand excluded from the covariance; empty otherwise).n_kept— the number of free dyads the finite coefficients were estimated on: every free dyad of every transition, or, after a statistic at the boundary of its attainable range fixed a coefficient at±Inf(R ergm'sdrop), the dyads the dropped statistics do not touch. It is the BIC sample size, as R'slogLiknobsattribute is (nobs(r)itself stays every free dyad).converged—falsewhen Newton exhaustedmaxiter, the pseudo-likelihood has no finite maximum (perfect separation: the coefficients are then the last iterate, not an estimate), or the CMLE's MCMC convergence tests did not pass; all are warned about at fit time and listed byapproximations(r).inference_withheld—truefor a CMPLE fit (defaultse) of a dyad-dependent formula: the naive pseudo-likelihood standard errors are reported, but no z value, p-value or confidence interval is built on them (seecmple).mcmc—nothingfor a CMPLE fit; for a CMLE fit a NamedTuple(formation, persistence)of per-side reports (iterations,step_length,termination,termination_p,t_ratios,hotelling_p,n_eff,n_samples,mcmc_se,exact—truefor a dyad-independent side, which is fit exactly without MCMC).
Accessors: formation_coef, formation_se, persistence_coef, persistence_se, plus the full StatsAPI surface on the stacked (formation, then persistence) coefficients: coef, stderror, vcov, confint, loglikelihood, aic, bic, nobs, dof and coeftable (labels Form(1)~… / Persist(1)~…, as summary(tergm) prints them).
Example
using TERGM, ERGM
t0 = network(5; directed=true)
for (i, j) in [(1, 2), (2, 1), (3, 4), (4, 5)]; add_edge!(t0, i, j); end
t1 = network(5; directed=true)
for (i, j) in [(1, 2), (3, 4), (2, 3), (5, 1)]; add_edge!(t1, i, j); end
fit = stergm([t0, t1], [Edges()], [Edges()]) # a STERGMResult{Int64, true}
fit.method, fit.se_type, fit.converged # (:cmple, :hessian, true)
fit.n_kept == nobs(fit) == 20 # true: 16 formation + 4 dissolution rows
size(fit.boot_replicates) # (0, 2): no bootstrap was run
fit.inference_withheld # false: an edges-only CMPLE is exact
approximations(fit) # String[]TERGM.TemporalTerm — Type
TemporalTerm <: AbstractERGMTermBase type for statistics of a network transition: they depend on the current network and the previous one.