Result-Metadata Protocol

Every model package in this ecosystem approximates something. ERGM's MPLE maximises a pseudo-likelihood, not the likelihood; a panel TERGM's CMPLE is the exact CMLE on a dyad-independent formula and an approximation with anticonservative standard errors on a dyad-dependent one; a SAOM maximises a moment condition; a relational-event model maximises a case-control partial likelihood over a sampled risk set.

None of that should have to be read out of a show method or a warning string. The result-metadata protocol makes it programmatically inspectable: seven accessors that any fitted model may specialise, and one constructor, fit_metadata, that collects them into a ResultMetadata.

using ERGM, NetworkCore

net = load_dataset(:sampson)
fit = ergm(net, [Edges(), Mutual()]; method=:mple)

meta = fit_metadata(fit)
meta.objective      # :pseudolikelihood
meta.is_exact       # false — the formula is dyad-dependent
meta.se_method      # :hessian  (anticonservative under dependence!)
meta.missing_method # :available_case

Each accessor has a conservative default, so a package that has not declared is reported as :unspecified rather than silently assumed exact.

The Container

NetworkCore.ResultMetadata — Type
ResultMetadata

What a fitted model actually did, in a form that can be inspected and tabulated rather than read out of a warning. Built by fit_metadata from the seven accessors of the shared result-metadata protocol.

The approximations field carries any free-text caveats the package wants to attach (e.g. "support truncated at 20; boundary mass 3e-6").

Example

md = fit_metadata("a value whose type declares nothing")
md isa ResultMetadata           # true
md.objective, md.is_exact       # (:unspecified, false) — the conservative defaults
md                              # prints one line per field
source
NetworkCore.fit_metadata — Function
fit_metadata(fit) -> ResultMetadata

Collect the shared result-metadata protocol for a fitted model: what it estimates, what objective it maximised, whether that objective is exact for this model, how the standard errors were computed, how missing dyads and tied events were treated, and any further caveats.

This is what makes an approximation programmatically inspectable instead of a sentence in a show method, and it is the source the ecosystem capability matrix is generated from.

import NetworkCore: estimand, objective, is_exact, se_method, missing_method
struct CMPLEFit end                       # a package's result type
estimand(::CMPLEFit) = :stergm_formation
objective(::CMPLEFit) = :conditional_pseudolikelihood
is_exact(::CMPLEFit) = false
se_method(::CMPLEFit) = :hessian
missing_method(::CMPLEFit) = :available_case

md = fit_metadata(CMPLEFit())
md.is_exact          # false — CMPLE of a dyad-dependent formula
md.se_method         # :hessian, therefore anticonservative here
md.missing_method    # :available_case

A package opts in by adding methods for estimand, objective, is_exact, se_method, missing_method, tie_method and approximations on its result type. Anything undeclared reports :unspecified (and is_exact reports false) rather than being optimistically assumed.

source

The Accessors

NetworkCore.estimand — Function
estimand(fit) -> Symbol

The population quantity the fit targets (e.g. :ergm, :stergm_formation, :saom, :relational_event). Defaults to :unspecified.

Part of the shared result-metadata protocol; see fit_metadata.

Example

import NetworkCore: estimand
struct MyFit end
estimand(::MyFit) = :ergm
estimand(MyFit())          # :ergm
estimand("anything else")  # :unspecified — the default for an undeclared type
source
NetworkCore.objective — Function
objective(fit) -> Symbol

The objective function that was actually maximised — not the one the model is named after. Conventional values:

  • :likelihood — the exact likelihood of the model
  • :pseudolikelihood — a dyadwise (or swapwise) pseudo-likelihood
  • :conditional_pseudolikelihood — CMPLE, as in panel TERGM
  • :mc_likelihood — a Monte-Carlo approximation to the likelihood (MCMLE)
  • :moment — method of moments / Robbins-Monro (SAOM)
  • :partial_likelihood — conditional-logit / case-control partial likelihood

Defaults to :unspecified. See fit_metadata.

Example

import NetworkCore: objective
struct MPLEFit end
objective(::MPLEFit) = :pseudolikelihood
objective(MPLEFit())    # :pseudolikelihood
source
NetworkCore.is_exact — Function
is_exact(fit) -> Bool

Whether objective coincides with the exact likelihood for this particular fitted model, not in general.

This is deliberately a property of the fit rather than of the estimator: a CMPLE fit of a dyad-independent formula is the CMLE, while the same estimator on a dyad-dependent formula is an approximation with anticonservative standard errors. The distinction is precisely what a user needs and cannot see.

Defaults to false — the conservative answer for a package that has not declared. See fit_metadata.

Example

import NetworkCore: is_exact
struct MPLEFit; dyad_independent::Bool; end
is_exact(fit::MPLEFit) = fit.dyad_independent    # MPLE is the MLE only for a dyad-independent model
is_exact(MPLEFit(true)), is_exact(MPLEFit(false))    # (true, false)
source
NetworkCore.se_method — Function
se_method(fit) -> Symbol

How the reported standard errors were obtained. Conventional values:

  • :hessian — inverse negative Hessian of the objective (for a pseudo-likelihood this is generally anticonservative under dependence)
  • :fisher — Fisher information from an MC sample
  • :bootstrap — parametric or block bootstrap
  • :sandwich — Godambe / robust sandwich
  • :none — no standard errors reported

Defaults to :unspecified. See fit_metadata.

Example

import NetworkCore: se_method
struct BootFit end
se_method(::BootFit) = :bootstrap
se_method(BootFit())    # :bootstrap
source
NetworkCore.missing_method — Function
missing_method(fit) -> Symbol

How unobserved (masked) dyads were treated. Conventional values:

  • :none — the data had no masked dyads
  • :available_case — masked dyads excluded from the objective (e.g. ERGM MPLE)
  • :condition_on_face — masked dyads frozen at their stored face value, an explicitly different estimand from missing-data maximum likelihood
  • :rejected — the estimator refuses masked data

Defaults to :unspecified. See the ecosystem missing-data contract in missing.jl (supports_missing, require_observed).

Example

import NetworkCore: missing_method
struct MPLEFit end
missing_method(::MPLEFit) = :available_case    # masked dyads left out of the design
missing_method(MPLEFit())    # :available_case
source
NetworkCore.tie_method — Function
tie_method(fit) -> Symbol

How tied event times were handled, for the relational-event models. :none when ties cannot arise or none were present; :not_applicable for models without event times. Otherwise one of TIE_POLICIES — the policy the fit actually ran, which is why :error can never appear here: a fit that would have had to break a tie under ties=:error threw instead of returning.

Defaults to :not_applicable. See fit_metadata.

Example

import NetworkCore: tie_method
struct REMFit; ties::Symbol; end
tie_method(fit::REMFit) = fit.ties
tie_method(REMFit(:efron))    # :efron
tie_method("an ERGM fit")     # :not_applicable — no event clock
source
NetworkCore.approximations — Function
approximations(fit) -> Vector{String}

Free-text caveats attached to a fit — the approximations a reader would need to know about and that do not fit the fixed vocabulary of the other accessors. Defaults to empty. See fit_metadata.

Example

import NetworkCore: approximations
struct TruncFit end
approximations(::TruncFit) = ["support truncated at 20; boundary mass 3e-6"]
approximations(TruncFit())    # 1-element Vector{String}
approximations(1.0)           # String[] — the default
source

missing_method and tie_method report the policy that was actually applied, and connect this protocol to the ecosystem contracts.

The StatsAPI Surface

The metadata protocol says how a fit was obtained; the StatsAPI surface says what can be read off it. Every fitted-model type in the ecosystem answers the StatsAPI verbs wherever the quantity exists — coef, stderror, vcov, confint, loglikelihood, nobs, dof, aic, bic, coeftable and coefnames — each defined by the package on its own result type, never here. NetworkCore.jl contributes the three shared pieces: it re-exports the coeftable and coefnames generics so that every package extends the same bindings (NetworkCore.coeftable === StatsAPI.coeftable, and using NetworkCore, REM leaves the verbs defined), it provides CoefficientTable as the value coeftable(fit) returns (the same vectors the fit's show prints), and it provides check_statsapi, the one checker each package's testset runs (check_statsapi(fit; strict=true)) so that "implements the surface" is a test, not prose. See Shared Inference for the checker.