Terms

ERGMEgo.EgoTerm — Type
EgoTerm <: AbstractERGMTerm

The abstract type of every ego statistic — the terms::Vector{<:EgoTerm} of fit_ergm_ego and the type a custom ego term subtypes (exported as ERGM.jl exports AbstractERGMTerm). A subtype provides

  • name(t)::String — its label (a method of the shared NetworkCore.name);
  • ERGMEgo.ego_contribution(t, e::EgoNetwork)::Float64 — the per-ego contribution, whose design-weighted mean is compute(t, ed) (the shared NetworkCore.compute; the generic method over EgoTerm does the weighting);
  • and, to be fittable, ERGMEgo.ergm_term(t) — the ERGM.jl term whose sufficient statistic m · compute(t, ed) estimates (a public hook, like ego_contribution). Without it the term is descriptive only (compute works) and fit_ergm_ego refuses it with an ArgumentError. The built-in fittable terms are EgoEdges, EgoNodeMatch, EgoNodeFactor, EgoNodeCov, EgoAbsDiff, EgoDegree, EgoTriangle, EgoGWDegree, EgoGWESP, EgoESP, EgoMM and EgoConcurrent; ergm.ego's other terms have no ego counterpart yet.

Example

using ERGMEgo
struct EgoIsolate <: EgoTerm end                     # proportion of egos with no alters
ERGMEgo.name(::EgoIsolate) = "isolates"
ERGMEgo.ego_contribution(::EgoIsolate, e::EgoNetwork) = Float64(n_alters(e) == 0)
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2))
e2 = EgoNetwork(2, Int[], Matrix{Bool}(undef, 0, 0))
compute(EgoIsolate(), EgoData([e1, e2]))             # 0.5
EgoIsolate() isa EgoTerm                             # true
source
ERGMEgo.EgoEdges — Type
EgoEdges <: EgoTerm

Per-capita edge statistic: the design-weighted mean of degree/2 over egos. Scaled by the pseudo-population size this estimates the edges sufficient statistic. Every model passed to fit_ergm_ego must include it (as every ergm.ego model includes edges).

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11, 12], zeros(Bool, 3, 3))
e2 = EgoNetwork(2, [10], zeros(Bool, 1, 1))
ed = EgoData([e1, e2])
compute(EgoEdges(), ed)              # 1.0 — mean degree 2, halved
ego_target_stats([EgoEdges()], ed, 100)   # [100.0] — the edges target for 100 vertices
source
ERGMEgo.EgoNodeMatch — Type
EgoNodeMatch(attr) <: EgoTerm

Per-capita homophily statistic: the design-weighted mean of half the number of alters whose attr matches the ego's. Estimates the nodematch(attr) sufficient statistic.

Every ego must carry attr in ego_attrs and in alter_attrs: an ego that lacks it is an ArgumentError naming the attribute, the ego and which side (ego or alters) is missing it, raised by compute/fit_ergm_ego before any MCMC runs. (The pre-0.2 code scored such an ego as 0 — a silent zero-fill that biased the target toward "no homophily".) A carried attribute whose value is missing — for the ego, or for some of its alters (an unknown alter attribute in a real survey; as_egodata passes such a column through) — is likewise an ArgumentError naming the attribute, the ego and how many alters lack a value, instead of a TypeError from the matching loop.

Example

using ERGMEgo
e = EgoNetwork(1, [10, 11, 12], zeros(Bool, 3, 3);
               ego_attrs=Dict{Symbol,Any}(:group => "A"),
               alter_attrs=Dict{Symbol,Vector}(:group => ["A", "B", "A"]))
compute(EgoNodeMatch(:group), EgoData([e]))   # 1.0 — two matching alters / 2
try compute(EgoNodeMatch(:nope), EgoData([e])) catch e; e isa ArgumentError end   # true — ArgumentError naming :nope and ego 1
source
ERGMEgo.EgoNodeFactor — Type
EgoNodeFactor(attr; levels=nothing, base=1) <: EgoTerm
EgoNodeFactor(attr; level=x) <: EgoTerm

Per-capita main effect of a categorical attribute (ergm.ego's nodefactor(attr)): for a level x, the design-weighted mean of (1[ego is x]·degree + #alters that are x) / 2 — each tie of the population has two endpoints and is reported by both of them, hence the halving. Scaled to a network of m vertices it estimates the number of times a vertex of level x is an endpoint of a tie, ERGM.jl's NodeFactor(attr; level=x) (R's label nodefactor.<attr>.<x>).

The levels follow ergm.ego: the sorted distinct values of the egos, with the first dropped as the reference category (base=1, R's default levels = -1). base gives the indices into the sorted levels to drop (base=0 keeps every level, R's levels = TRUE); levels names the included values explicitly. A multi-level term expands into one statistic per included level when the model is fitted (and in ego_target_stats), so coef(fit) has one row per level; compute of the unexpanded term is the sum over its levels, as for ERGM.jl's NodeFactor. level=x builds a single-level term directly.

Every ego must carry attr for itself and for its alters (an ArgumentError names the ego otherwise; ergm.ego's fallback for data without alter attributes, which counts the ego's endpoint only, is not ported).

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2);
                ego_attrs=Dict{Symbol,Any}(:sex => "F"),
                alter_attrs=Dict{Symbol,Vector}(:sex => ["F", "M"]))
e2 = EgoNetwork(2, [12], zeros(Bool, 1, 1);
                ego_attrs=Dict{Symbol,Any}(:sex => "M"),
                alter_attrs=Dict{Symbol,Vector}(:sex => ["M"]))
ed = EgoData([e1, e2])
compute(EgoNodeFactor(:sex; level="M"), ed)    # 0.75 — ((0 + 1) + (1 + 1))/2 per ego, averaged
ego_target_stats([EgoNodeFactor(:sex)], ed, 10)                   # [7.5] — level "M" only: "F" is the reference
ego_target_stats([EgoNodeFactor(:sex; base=0)], ed, 10)            # [7.5, 7.5]
source
ERGMEgo.EgoNodeCov — Type
EgoNodeCov(attr) <: EgoTerm

Per-capita main effect of a numeric attribute (ergm.ego's nodecov(attr)): the design-weighted mean of (x_ego·degree + Σ x_alter)/2 (each tie reported by both endpoints, hence the halving). Scaled to a network of m vertices it estimates the sum of the attribute over the endpoints of every tie, ERGM.jl's NodeCov(attr) (R's label nodecov.<attr>). Every ego must carry a real-valued attr for itself and its alters.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2);
                ego_attrs=Dict{Symbol,Any}(:age => 20),
                alter_attrs=Dict{Symbol,Vector}(:age => [30, 40]))
e2 = EgoNetwork(2, Int[], zeros(Bool, 0, 0);
                ego_attrs=Dict{Symbol,Any}(:age => 50),
                alter_attrs=Dict{Symbol,Vector}(:age => Int[]))
compute(EgoNodeCov(:age), EgoData([e1, e2]))   # 27.5 — (20·2 + 30 + 40)/2 = 55 and 0, averaged
name(EgoNodeCov(:age))                         # "nodecov.age"
source
ERGMEgo.EgoAbsDiff — Type
EgoAbsDiff(attr; pow=1) <: EgoTerm

Per-capita absolute difference of a numeric attribute across ties (ergm.ego's absdiff(attr, pow)): the design-weighted mean of Σ_alters |x_ego − x_alter|^pow / 2. Scaled to a network of m vertices it estimates Σ_ties |xᵢ − xⱼ|^pow, ERGM.jl's AbsDiff(attr; pow) (R's labels absdiff.<attr>, and absdiff<pow>.<attr> for pow ≠ 1). Every ego must carry a real-valued attr for itself and its alters.

Example

using ERGMEgo
e = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2);
               ego_attrs=Dict{Symbol,Any}(:grade => 9),
               alter_attrs=Dict{Symbol,Vector}(:grade => [9, 12]))
compute(EgoAbsDiff(:grade), EgoData([e]))            # 1.5 — (0 + 3)/2
compute(EgoAbsDiff(:grade; pow=2), EgoData([e]))     # 4.5 — (0 + 9)/2
name(EgoAbsDiff(:grade; pow=2))                      # "absdiff2.grade"
source
ERGMEgo.EgoDegree — Type
EgoDegree(d::Integer) <: EgoTerm

Per-capita degree count: the design-weighted proportion of egos with degree exactly d (d ≥ 0). Estimates ergm.ego's degree(d) — the number of vertices of degree d — i.e. ERGM.jl's Degree(d) (R's label degree<d>). R's degree(1:3) is EgoDegree.(1:3) (one term per degree). The by= and homophily= forms of R's term are not ported.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2))
e2 = EgoNetwork(2, [10], zeros(Bool, 1, 1))
e3 = EgoNetwork(3, [11, 12], zeros(Bool, 2, 2))
ed = EgoData([e1, e2, e3])
compute(EgoDegree(2), ed)           # 0.6667 — two of three egos have degree 2
compute(EgoDegree(0), ed)           # 0.0
name.(EgoDegree.(1:2))              # ["degree1", "degree2"] — R's degree(1:2)
source
ERGMEgo.EgoTriangle — Type
EgoTriangle <: EgoTerm

Per-capita triangle statistic: the design-weighted mean of (alter–alter ties)/3 (each population triangle appears in the local view of each of its three vertices). Estimates the triangle sufficient statistic. Data whose alter–alter ties were not collected (ed.design[:alter_ties_observed] == false) is refused with an ArgumentError.

In a fit whose pseudo-population size differs from the population size, a triangle term changes the network-size offset as in ergm.ego: the offset statistic is edges − transitiveties/3 instead of edges (see fit_ergm_ego).

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11, 12], Bool[0 1 1; 1 0 0; 1 0 0])   # two alter–alter ties
e2 = EgoNetwork(2, [10, 11], Bool[0 1; 1 0])                  # one
e3 = EgoNetwork(3, [12], zeros(Bool, 1, 1))                   # none
ed = EgoData([e1, e2, e3])
compute(EgoTriangle(), ed)          # 0.3333 — (2 + 1 + 0)/3 alter ties per ego, over 3
source
ERGMEgo.EgoGWDegree — Type
EgoGWDegree(decay::Real=0.5) <: EgoTerm

Per-capita geometrically weighted degree: the design-weighted mean of e^α(1 − (1 − e^{−α})^degree) with α = decay. Estimates the gwdegree(decay, fixed=TRUE) sufficient statistic, i.e. ERGM.jl's GWDegree(decay) (labelled gwdeg.fixed.<decay>, R's name). decay must be non-negative (ArgumentError otherwise); at decay = 0 every ego with at least one alter contributes exactly 1, so the statistic is the proportion of non-isolate egos.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], Bool[0 0; 0 0])
e2 = EgoNetwork(2, Int[], Matrix{Bool}(undef, 0, 0))
ed = EgoData([e1, e2])
compute(EgoGWDegree(0.0), ed)      # 0.5 — one of two egos has alters
EgoGWDegree(1).decay               # 1.0 — any Real is accepted
source
ERGMEgo.EgoGWESP — Type
EgoGWESP(decay::Real=0.5) <: EgoTerm

Per-capita geometrically weighted edgewise shared partners (ergm.ego's gwesp(decay, fixed=TRUE)). Seen from an ego, the shared partners of its tie to alter a are the ego's other alters tied to a — a's degree s among the alter–alter ties — so the per-ego value is Σ_alters w(s)/2 with w(s) = e^α(1 − (1 − e^{−α})^s), α = decay (each tie is seen from both of its ends, hence the half). Scaled by the pseudo-population size it estimates ERGM.jl's GWESP(decay), labelled gwesp.fixed.<decay> (R's name). At decay = 0 it is the number of ties with at least one shared partner (ergm.ego's help-page model uses gwesp(0, fixed=TRUE)). decay must be non-negative.

It reads the alter–alter ties, so data whose alter ties were not collected is refused, as for EgoTriangle; and, like EgoTriangle, it is a triadic statistic: in a fit whose pseudo-population size differs from the population size the network-size offset is edges − transitiveties/3, as in ergm.ego.

The decay is fixed: EgoGWESP(decay; fixed=false) (ergm.ego's curved gwesp(decay, fixed=FALSE)) is refused with an ArgumentError.

There is no shared-partner cutoff. ergm.ego's gwesp takes cutoff (default 30) and leaves out of its statistic every tie with more than cutoff shared partners: on a census of the complete graph on 33 vertices (31 shared partners per tie) ergm.ego returns 0 where ergm's own gwesp(0.5, fixed=TRUE) returns 870.52. EgoGWESP weights every tie by its full count, as ergm's gwesp and ERGM.jl's GWESP (the statistic it estimates) do, so it differs from ergm.ego only on data in which an ego and one of its alters share more than 30 alters.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11, 12], Bool[0 1 1; 1 0 0; 1 0 0])   # alter 10 shares 11 and 12
e2 = EgoNetwork(2, [10, 11], Bool[0 1; 1 0])
ed = EgoData([e1, e2])
compute(EgoGWESP(0.0), ed)          # 1.25 — (3/2 + 2/2)/2: every tie has a shared partner
name(EgoGWESP(0.5))                 # "gwesp.fixed.0.5"
source
ERGMEgo.EgoESP — Type
EgoESP(k::Integer) <: EgoTerm

Per-capita edgewise shared partners (ergm.ego's esp(k)): the design-weighted mean of half the number of the ego's alters that have exactly k shared partners with the ego — an alter's shared partners with the ego are the ego's other alters tied to it, so its count is its degree among the alter–alter ties. Scaled by the pseudo-population size it estimates ERGM.jl's ESP(k), the number of ties with exactly k shared partners (R's label esp<k>). R's esp(0:3) is EgoESP.(0:3) (one term per count); k must be non-negative.

It reads the alter–alter ties, so data whose alter ties were not collected is refused, as for EgoTriangle; and it is a triadic statistic: in a fit whose pseudo-population size differs from the population size the network-size offset is edges − transitiveties/3, as in ergm.ego. EgoGWESP(α) is Σₖ eᵅ(1 − (1 − e⁻ᵅ)ᵏ)·EgoESP(k).

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11, 12], Bool[0 1 1; 1 0 0; 1 0 0])   # alter 10 shares 11 and 12
e2 = EgoNetwork(2, [10, 11], Bool[0 1; 1 0])
ed = EgoData([e1, e2])
compute(EgoESP(1), ed)              # 1.0 — (2/2 + 2/2)/2: alters 11, 12 of ego 1; both of ego 2
compute(EgoESP(2), ed)              # 0.25 — alter 10 of ego 1, halved, averaged
name.(EgoESP.(0:1))                 # ["esp0", "esp1"] — R's esp(0:1)
source
ERGMEgo.EgoMM — Type
EgoMM(attr) <: EgoTerm
EgoMM(attr, l1, l2) <: EgoTerm

Per-capita mixing-matrix cells of a categorical attribute (ergm.ego's mm(attr), the default form mm(~attr, levels2 = -1)): for the cell of levels (l1, l2), the design-weighted mean of half the number of the ego's alters such that the ego and the alter carry l1 and l2, in either order. Scaled by the pseudo-population size it estimates the number of ties between a vertex of level l1 and one of level l2, ERGM.jl's NodeMix(attr, l1, l2); R's label is mm[<attr>=<l1>,<attr>=<l2>].

EgoMM(attr) is a specification that expands into one statistic per cell when the model is fitted (and in ego_target_stats), as ergm.ego does: the levels are the sorted values found at either end of a reported ego–alter tie (an alter's level counts even when no ego carries it; an ego with no alters adds none), the cells are the unordered pairs l1 ≤ l2 in R's order — (u₁,u₁), (u₁,u₂), (u₂,u₂), (u₁,u₃), … — and the first cell is dropped as the reference (R's levels2 = -1). compute of the unexpanded term is the sum of its cells. EgoMM(attr, l1, l2) builds one cell directly.

Not implemented, and refused: R's two-attribute form mm(A ~ B) (written EgoMM(:A, :B)), its margins mm(A ~ .), and the levels=/levels2= selections. Every ego must carry attr for itself and its alters. ergm.ego 1.1.4's mm stops with an error on a weighted design; EgoMM weights its per-ego values as every other term does.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2); ego_attrs=Dict{Symbol,Any}(:g => "A"),
                alter_attrs=Dict{Symbol,Vector}(:g => ["A", "B"]))
e2 = EgoNetwork(2, [12], zeros(Bool, 1, 1); ego_attrs=Dict{Symbol,Any}(:g => "B"),
                alter_attrs=Dict{Symbol,Vector}(:g => ["B"]))
ed = EgoData([e1, e2])
compute(EgoMM(:g, "A", "B"), ed)          # 0.25 — ego 1's one A–B alter, halved, averaged
ego_target_stats([EgoMM(:g)], ed, 10)     # [2.5, 2.5] — cells A–B and B–B; A–A is the reference
name(EgoMM(:g, "A", "B"))                 # "mm[g=A,g=B]"
source
ERGMEgo.EgoConcurrent — Type
EgoConcurrent() <: EgoTerm

Per-capita concurrency (ergm.ego's concurrent): the design-weighted proportion of egos with two or more alters. Scaled by the pseudo-population size it estimates ERGM.jl's Concurrent(), the number of vertices of degree two or more (R's label concurrent). Like EgoDegree it is a property of the ego, not of a tie, so it is not halved. R's by= form (concurrency by an attribute) is not implemented and is refused.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2))
e2 = EgoNetwork(2, [10], zeros(Bool, 1, 1))
e3 = EgoNetwork(3, [11, 12, 13], zeros(Bool, 3, 3))
compute(EgoConcurrent(), EgoData([e1, e2, e3]))   # 0.6667 — two of three egos have ≥ 2 alters
name(EgoConcurrent())                              # "concurrent"
source
NetworkCore.compute — Method
compute(term::EgoTerm, ed::EgoData) -> Float64

The design-weighted mean per-ego contribution of the term (a per-capita statistic; multiply by a network size to get a target sufficient statistic — see ego_target_stats). A method of the shared NetworkCore.compute statistic protocol (ERGMEgo.compute === NetworkCore.compute).

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11, 12], zeros(Bool, 3, 3))
e2 = EgoNetwork(2, [10], zeros(Bool, 1, 1))
ed = ego_design(EgoData([e1, e2]); weights=[1.0, 3.0])
compute(EgoEdges(), ed)             # 0.75 — weighted mean degree (3 + 3·1)/4 = 1.5, halved
compute(EgoEdges(), EgoData([e1, e2]))   # 1.0 under unit weights
source
NetworkCore.name — Method
name(term::EgoTerm) -> String

The label of an ego term: ergm.ego's label for the statistic it estimates, which is R ergm's label of the same term — edges, nodematch.<attr>, nodefactor.<attr>.<level>, nodecov.<attr>, absdiff.<attr>, degree<d>, triangle, gwdeg.fixed.<decay>, gwesp.fixed.<decay>, esp<k>, mm[<attr>=<l1>,<attr>=<l2>], concurrent — and so the label of its row in coeftable(fit) and of its coefficient in coefnames(fit), so a coefficient is found by its R name (coeftable(fit)["edges"]). For a fittable term it is name(ERGMEgo.ergm_term(term)), except EgoMM, whose ERGM.jl counterpart NodeMix carries R's nodemix label. A method of the shared NetworkCore.name generic (ERGMEgo.name === NetworkCore.name).

Example

using ERGMEgo
name(EgoEdges()), name(EgoNodeMatch(:Grade)), name(EgoGWDegree(0.5))
# ("edges", "nodematch.Grade", "gwdeg.fixed.0.5") — ergm.ego's labels
name(EgoDegree(0)), name(EgoGWESP(0.0))   # ("degree0", "gwesp.fixed.0")
source
ERGMEgo.ego_mixing_matrix — Function
ego_mixing_matrix(ed::EgoData, attr::Symbol) -> (levels, matrix)

Design-weighted ego–alter mixing counts for a categorical attribute: matrix[a, b] is the weighted number of ego–alter pairs with ego level levels[a] and alter level levels[b]. Every ego must carry attr on both the ego and its alters; one that does not is an ArgumentError naming the attribute and the ego (it used to be skipped silently, so the matrix quietly described a subset of the sample), and so is a missing value on either side (the same rule as EgoNodeMatch).

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11], zeros(Bool, 2, 2); ego_attrs=Dict{Symbol,Any}(:g => "A"),
                alter_attrs=Dict{Symbol,Vector}(:g => ["A", "B"]))
e2 = EgoNetwork(2, [12], zeros(Bool, 1, 1); ego_attrs=Dict{Symbol,Any}(:g => "B"),
                alter_attrs=Dict{Symbol,Vector}(:g => ["B"]))
mm = ego_mixing_matrix(EgoData([e1, e2]), :g)
mm.levels            # ["A", "B"]
mm.matrix            # [1.0 1.0; 0.0 1.0]
source
ERGMEgo.ego_target_stats — Function
ego_target_stats(terms, ed::EgoData, m::Int) -> Vector{Float64}

Target sufficient statistics for a network of size m: m times the design-weighted per-capita ego statistics — what ergm.ego passes to ergm as target.stats (R's summary(egor ~ …, scaleto = m)). A multi-level EgoNodeFactor gives one target per included level. Under a census (every vertex an ego, unit weights, m = nv) they reduce exactly to the network's own statistics.

Example

using ERGMEgo, NetworkCore, Random
net = load_dataset(:faux_mesa_high)
ed = simulate_ego_sample(net, 205; ego_attrs=[:Grade, :Sex], rng=Xoshiro(1))   # a census
ego_target_stats([EgoEdges(), EgoNodeMatch(:Grade)], ed, 205)   # [203.0, 163.0] — the network's own
ego_target_stats([EgoNodeFactor(:Sex), EgoAbsDiff(:Grade), EgoDegree(0)], ed, 205)   # [171.0, 79.0, 57.0] — R's nodefactor.Sex.M, absdiff.Grade, degree0
ego_target_stats([EgoEdges()], ed, 1000)                         # [990.24] — scaled to 1000 vertices
source

Making a custom term fittable

A custom EgoTerm extends two public (not exported) hooks. ERGMEgo.ego_contribution gives one ego's contribution to the per-capita statistic. ERGMEgo.ergm_term maps the ego term to the ERGM.jl term whose sufficient statistic it estimates; the built-in fittable terms are its methods, and a custom term becomes fittable by adding one.

ERGMEgo.ego_contribution — Function
ERGMEgo.ego_contribution(term::EgoTerm, e::EgoNetwork) -> Float64

The contribution of one ego's local network e to the per-capita statistic of term: compute(term, ed) is its design-weighted mean over the egos of ed. Every built-in EgoTerm is a method of it (EgoEdges contributes degree/2, EgoTriangle the ties among the alters over 3), and a custom ego term adds one. A public (not exported) name: the hook a custom term extends, with ERGMEgo.ergm_term to make it fittable.

Example

using ERGMEgo
e1 = EgoNetwork(1, [10, 11, 12], zeros(Bool, 3, 3))
ERGMEgo.ego_contribution(EgoEdges(), e1)        # 1.5 — degree 3, halved
struct EgoIsolated <: EgoTerm end
ERGMEgo.name(::EgoIsolated) = "isolated"
ERGMEgo.ego_contribution(::EgoIsolated, e::EgoNetwork) = Float64(n_alters(e) == 0)
ERGMEgo.ego_contribution(EgoIsolated(), e1)     # 0.0
Base.ispublic(ERGMEgo, :ego_contribution)       # true
source
ERGMEgo.ergm_term — Function
ERGMEgo.ergm_term(term::EgoTerm) -> AbstractERGMTerm

The ERGM.jl term whose sufficient statistic m · compute(term, ed) estimates — the hook that makes an ego term fittable by fit_ergm_ego: EgoEdges → Edges(), EgoNodeMatch(a) → NodeMatch(a), EgoNodeFactor(a; level=l) → NodeFactor(a; level=l), EgoNodeCov(a) → NodeCov(a), EgoAbsDiff(a; pow) → AbsDiff(a; pow), EgoDegree(d) → Degree(d), EgoTriangle → Triangle(), EgoGWDegree(α) → GWDegree(α), EgoGWESP(α) → GWESP(α), EgoESP(k) → ESP(k), EgoMM(a, l1, l2) → NodeMix(a, l1, l2), EgoConcurrent() → Concurrent(). A term without a method (a custom EgoTerm that has not added one, or the goodness-of-fit statistics) is descriptive only, and fit_ergm_ego refuses it with an ArgumentError naming the term. A public (not exported) name, as ERGMEgo.ego_contribution is: add a method to it (with the matching ego_contribution) to fit a custom term, provided the per-ego contribution really is an unbiased per-capita estimate of the ERGM term's statistic.

Example

using ERGMEgo, ERGM
ERGMEgo.ergm_term(EgoEdges())                       # Edges()
name(ERGMEgo.ergm_term(EgoGWDegree(0.5)))           # "gwdeg.fixed.0.5" — R's label
name(ERGMEgo.ergm_term(EgoNodeFactor(:Sex; level="M")))   # "nodefactor.Sex.M"
struct EgoTwoStar <: EgoTerm end                     # per-capita 2-stars: C(degree, 2) — each 2-star has ONE centre, no divisor
ERGMEgo.name(::EgoTwoStar) = "kstar2"                # R's label for kstar(2)
ERGMEgo.ego_contribution(::EgoTwoStar, e::EgoNetwork) = Float64(binomial(ego_degree(e), 2))
ERGMEgo.ergm_term(::EgoTwoStar) = Kstar(2)          # now fittable
Base.ispublic(ERGMEgo, :ergm_term)                  # true
source