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 <: AbstractERGMTermDeference (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 3ERGMRank.RankNonconformity — Type
RankNonconformity(variant=:all) <: AbstractERGMTermNonconformity, 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.
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
endERGMRank.RankNodeICov — Type
RankNodeICov(x) <: AbstractERGMTermAttractiveness/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 covariatelabel::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"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 aRankNetwork.weights:nothing(every comparison counts 1), ann × n × narray whose[i, j, k]element weighs egoi's comparison of altersjandk, 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: iftruethe 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 notNaN/missing(so passNaNin thei == j,i == k,j == kcells of an array to keep them out of the mean, as R'sNA).NaN/missingweights count as 0.wtname: a label for the weights; the term is then namedrank.inconsistency:<wtname>(with a trailingcwhen centred), following R'sinconsistency.rank:<wtname>c.
Fields
ref::Matrix{Int}: reference rank matrixweights::Union{Nothing, Array{Float64,3}}: the weights actually used (centred, invalid cells zero), ornothinglabel::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"ERGMRank.RankEdgeCov — Type
RankEdgeCov(cov) <: AbstractERGMTermDyadic 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 matrixlabel::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"Swap change statistics
ERGMRank.swap_change — Function
swap_change(term, rnet::RankNetwork, ego, j, k) -> Float64The 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