Terms

Every term implements the ecosystem's statistic protocol — compute(term, rnet) and name(term) are the one NetworkCore.compute/NetworkCore.name generic each (reached through ERGM.jl and exported by ERGMRank, so using ERGMRank suffices) — plus the rank-specific swap_change. RankNonconformity offers :all and :localAND only; ergm.rank's local1/local2/geometric/thresholds variants are refused with an ArgumentError that says they are not implemented (see the terms guide).

ERGMRank.RankDeference — Type
RankDeference <: AbstractERGMTerm

Deference (aversion), rank.deference in ergm.rank: the number of ordered triples (ego i, deferred-to l, other j) such that l ranks j over i while i ranks l over j. A negative coefficient is aversion to deference. Implements compute and swap_change.

Example

using ERGMRank
m = [0 3 2 1;
     3 0 1 2;
     1 3 0 2;
     2 1 3 0]
rnet = as_rank_network(m)
compute(RankDeference(), rnet)         # 6.0 (R ergm.rank: summary(nw ~ rank.deference))
name(RankDeference())                  # "rank.deference"
swap_change(RankDeference(), rnet, 1, 2, 3)   # Δ if ego 1 swaps its ranks of 2 and 3
source
ERGMRank.RankNonconformity — Type
RankNonconformity(variant=:all) <: AbstractERGMTerm

Nonconformity, rank.nonconformity in ergm.rank.

  • :all — global nonconformity: over unordered actor pairs {i, j} and ordered alter pairs (k, l), count comparisons on which i and j disagree ((y_ik > y_il) ≠ (y_jk > y_jl)).
  • :localAND — local nonconformity (Krivitsky & Butts): ego i disagrees with an actor l that i ranks over both j and k, counting cases where l ranks j over k while i ranks k at least as high as j.
Not implemented: ergm.rank's other `rank.nonconformity` variants

ergm.rank's rank.nonconformity(to = "local1"), "local2", "geometric" and "thresholds" have no counterpart here. Only :all and :localAND exist; any other variant is refused at construction with ArgumentError: RankNonconformity: variant must be :all or :localAND (got :local1); ergm.rank's local1/local2/geometric/thresholds variants are not implemented in ERGMRank.jl.

Example

using ERGMRank
m = [0 3 2 1;
     3 0 1 2;
     1 3 0 2;
     2 1 3 0]
rnet = as_rank_network(m)
compute(RankNonconformity(), rnet)             # 10.0 (R: rank.nonconformity("all"))
compute(RankNonconformity(:localAND), rnet)    # 4.0  (R: rank.nonconformity("localAND"))
name(RankNonconformity(:localAND))             # "rank.nonconformity.localAND"
try
    RankNonconformity(:local1)
catch err
    err isa ArgumentError                      # true: not implemented
end
source
ERGMRank.RankNodeICov — Type
RankNodeICov(x) <: AbstractERGMTerm

Attractiveness/popularity covariate, rank.nodeicov in ergm.rank: for each ego and each ordered alter pair (j, k) with j ranked over k, add x[j] − x[k]. A positive coefficient means high-covariate actors tend to be ranked higher. A covariate whose length is not the number of actors is refused by compute and swap_change (an ArgumentError quoting both).

Fields

  • x::Vector{Float64}: Actor-level covariate
  • label::String: Name for output (default "x")

Example

using ERGMRank
m = [0 3 2 1;
     3 0 1 2;
     1 3 0 2;
     2 1 3 0]
rnet = as_rank_network(m)
compute(RankNodeICov([10, 20, 30, 40]), rnet)        # -40.0 (R: rank.nodeicov)
name(RankNodeICov([10, 20, 30, 40]; label="age"))   # "rank.nodeicov.age"
source
ERGMRank.RankInconsistency — Type
RankInconsistency(ref; weights=nothing, wtname=nothing, wtcenter=false) <: AbstractERGMTerm

(Weighted) inconsistency, rank.inconsistency(x, attrname, weights, wtname, wtcenter) in ergm.rank: the number of ego–alter pair comparisons on which the network disagrees with a reference ranking ((y_ij > y_ik) ≠ (ref_ij > ref_ik)), each comparison optionally weighted. Useful for drift from a prior wave or an exogenous ordering. Fitting RankInconsistency(rnet) to rnet itself puts the statistic at the boundary of its attainable range (zero inconsistency), where no finite estimate exists — see fit_ergm_rank.

Arguments

  • ref: the reference ranking — a rank matrix (same convention as the network's) or a RankNetwork.
  • weights: nothing (every comparison counts 1), an n × n × n array whose [i, j, k] element weighs ego i's comparison of alters j and k, or a function (i, j, k) -> weight (evaluated on every triple of distinct actors). The statistic is then Σ_{i} Σ_{j ≠ k} weights[i, j, k] · 1[(y_ij > y_ik) ≠ (ref_ij > ref_ik)] over ordered alter pairs, exactly as in ergm.rank.
  • wtcenter: if true the weights are centred at their mean before use — as in R, the mean of the function's values over the triples of distinct actors, or of every entry of an array that is not NaN/missing (so pass NaN in the i == j, i == k, j == k cells of an array to keep them out of the mean, as R's NA). NaN/missing weights count as 0.
  • wtname: a label for the weights; the term is then named rank.inconsistency:<wtname> (with a trailing c when centred), following R's inconsistency.rank:<wtname>c.

Fields

  • ref::Matrix{Int}: reference rank matrix
  • weights::Union{Nothing, Array{Float64,3}}: the weights actually used (centred, invalid cells zero), or nothing
  • label::String: the term's name

Example

using ERGMRank
m = [0 3 2 1;
     3 0 1 2;
     1 3 0 2;
     2 1 3 0]
rnet = as_rank_network(m)
compute(RankInconsistency(rnet), rnet)          # 0.0: no disagreement with itself
other = copy(rnet); swap_ranks!(other, 1, 2, 3)
compute(RankInconsistency(rnet), other)         # 2.0: ego 1's (2,3) comparison, both orders
name(RankInconsistency(rank_matrix(rnet)))      # "rank.inconsistency"
w = RankInconsistency(rnet; weights=(i, j, k) -> i, wtname="ego")
compute(w, other) == 2.0                        # true: both comparisons weigh 1 (ego 1)
name(w)                                         # "rank.inconsistency:ego"
source
ERGMRank.RankEdgeCov — Type
RankEdgeCov(cov) <: AbstractERGMTerm

Dyadic covariate, rank.edgecov in ergm.rank: for each ego and ordered alter pair (j, k) with j ranked over k, add cov[i, j] − cov[i, k]. With cov[i, j] = x[j] it is exactly RankNodeICov(x). A covariate matrix that is not n × n is refused by compute and swap_change.

Fields

  • cov::Matrix{Float64}: Dyadic covariate matrix
  • label::String: Name for output

Example

using ERGMRank
m = [0 3 2 1;
     3 0 1 2;
     1 3 0 2;
     2 1 3 0]
rnet = as_rank_network(m)
x = [10.0, 20.0, 30.0, 40.0]
cov = repeat(x', 4, 1)                                  # cov[i, j] = x[j]
compute(RankEdgeCov(cov), rnet) == compute(RankNodeICov(x), rnet)   # true: -40.0
name(RankEdgeCov(cov; label="distance"))                # "rank.edgecov.distance"
source

Swap change statistics

ERGMRank.swap_change — Function
swap_change(term, rnet::RankNetwork, ego, j, k) -> Float64

The change in the statistic of term when ego swaps the ranks it assigns alters j and k — compute(term, y_swapped) − compute(term, y) — the AlterSwap analogue of ERGM.change_stat. (The methods are derived independently from the term definitions as a swap move, which has no counterpart in R ergm.rank's single-cell change functions.) It is evaluated from the comparisons the swap actually touches (the alter pairs of ego's row that involve j or k): O(n) for RankDeference, RankNodeICov, RankInconsistency and RankEdgeCov, O(n²) for both RankNonconformity variants — never by recomputing either full statistic — and allocates nothing. rnet is left unchanged.

Every rank term implements this method alongside compute; the sampler's _swap_delta!, the swap-MPLE design and gof all run on it. A term that implements only compute would make the sampler fall back to nothing: there is no brute-force default, because a per-step O(n⁴) recomputation is exactly what this method exists to prevent (the test suite keeps that brute force as its oracle, ERGMRank._swap_delta_bruteforce).

ego, j and k must be distinct actors in 1:n with ego ∉ {j, k} (an ArgumentError otherwise); a covariate of the wrong size is refused as compute refuses it.

Example

using ERGMRank
m = [0 3 2 1;
     3 0 1 2;
     1 3 0 2;
     2 1 3 0]
rnet = as_rank_network(m)
term = RankDeference()
Δ = swap_change(term, rnet, 1, 2, 3)      # ego 1 swaps its ranks of 2 and 3
swapped = copy(rnet); swap_ranks!(swapped, 1, 2, 3)
Δ == compute(term, swapped) - compute(term, rnet)    # true
source