Measures API Reference

Graph-level indices, censuses, graph correlation, and QAP inference.

Graph-level indices

SNA.gden — Function
gden(net; diag=false, discount_bipartite=false, missing=:error) -> Float64

Graph density, the proportion of possible ties that are present: R sna::gden. An undirected tie counts once, so a loop-free undirected network has density ne(net) / (n(n−1)/2). Loops are excluded unless diag=true. Two-mode density includes all actor pairs in its denominator unless discount_bipartite=true, which restricts it to cross-mode pairs. With diag=true an undirected network has n(n+1)/2 possible dyads (NetworkCore' convention), not sna's symmetric-matrix n².

missing=:error refuses masked (unobserved) dyads. missing=:face counts each masked dyad at its stored face value: the denominator still contains every dyad. SNA.jl does not estimate a density over observed dyads only.

Graphs.density is Graphs.jl's function and keeps its own semantics on a Network (it counts loops); gden is the sna measure.

Example

using SNA
net = network(4; directed=false)
add_edges!(net, [(1, 2), (2, 3)])
gden(net)                            # 2 / 6 = 0.3333
source
SNA.grecip — Function
grecip(net; measure=:dyadic, missing=:error) -> Float64

Graph reciprocity: R sna::grecip. With M, A and N the numbers of mutual, asymmetric and null dyads:

  • :dyadic (default): the proportion of dyads that are symmetric, (M + N) / (M + A + N);
  • :dyadic_nonnull: the proportion of non-null dyads that are mutual, M / (M + A);
  • :edgewise: the proportion of ties that are reciprocated, 2M / (2M + A);
  • :edgewise_lrr: the log of edgewise reciprocity over density, log(M (M + A + N) / (M + A/2)²);
  • :correlation: the correlation between y_ij and y_ji over dyads.

An undefined ratio is NaN, as in sna. missing=:error refuses masked dyads; missing=:face classifies them from their stored face values.

Example

using SNA
net = network(3)
add_edges!(net, [(1, 2), (2, 1), (2, 3)])
grecip(net)                          # (1 + 1) / 3 = 0.6667
grecip(net; measure=:edgewise)       # 2 / 3
source
SNA.gtrans — Function
gtrans(net; measure=:weak, missing=:error) -> Float64

Graph transitivity: R sna::gtrans, over ordered triples of distinct vertices (i, j, k) (loops are ignored).

  • :weak (default): the proportion of two-paths i→j→k that are closed by i→k. On an undirected network this is 3 × triangles / connected triples, igraph's global transitivity.
  • :strong: the proportion of ordered triples for which i→k is present exactly when some two-path i→j→k is, counted per intermediary j.
  • :weakcensus / :strongcensus: the numerators of the two ratios (counts).
  • :correlation: the correlation between y_ik and the number of two-paths from i to k.

A ratio with no qualifying triples is 1.0, as in sna. sna's rank measure (for valued data) is not implemented.

missing=:error refuses masked dyads; missing=:face counts them at their stored face values in numerator and denominator.

Example

using SNA
net = network(3)
add_edges!(net, [(1, 2), (2, 3), (1, 3)])
gtrans(net)                          # 1.0: the only two-path 1→2→3 is closed
source
SNA.transitivity — Function
transitivity(net; type=:global, cmode=:total, missing=:error) -> Float64 or Vector{Float64}

Clustering coefficients, named after igraph's transitivity (sna has no local clustering coefficient).

  • type=:global (default): sna's weak transitivity, gtrans(net). On an undirected network this is igraph's global transitivity. On a directed network igraph ignores direction; sna and this function do not.
  • type=:local: a vector of local clustering coefficients. A vertex with fewer than two neighbours (loops excluded) has no coefficient and scores NaN, as in igraph.
    • Undirected networks: the Watts–Strogatz coefficient, the share of the k(k−1)/2 pairs of a vertex's k neighbours that are tied.
    • Directed networks, cmode=:total (default): Fagiolo's (2007) total-degree coefficient, [(A+Aᵀ)³]ᵢᵢ / (2[dᵢᵗᵒᵗ(dᵢᵗᵒᵗ−1) − 2dᵢ↔]), the share of all directed triangles through i that are realized. It equals the Watts–Strogatz coefficient when every tie is mutual.
    • Directed networks, cmode=:weak: the Watts–Strogatz coefficient of the weak symmetrization (an arc in either direction is a tie), which is what igraph computes on a directed graph.
  • type=:average: the mean of the local coefficients over vertices that have one (degree ≥ 2), igraph's transitivity(type="average"); NaN if no vertex has one.

missing=:error refuses masked dyads; missing=:face counts them at their stored face values.

Example

using SNA
net = network(4; directed=false)
add_edges!(net, [(1, 2), (1, 3), (2, 3), (3, 4)])
transitivity(net; type=:local)       # [1.0, 1.0, 0.3333, NaN]
transitivity(net; type=:average)     # 0.7778

References

Fagiolo, G. (2007). Clustering in complex directed networks. Physical Review E, 76, 026107.

source
SNA.mutuality — Function
mutuality(net; missing=:error) -> Int

The number of mutual (reciprocated) dyads, R sna::mutuality (a count, not a proportion).

missing=:error refuses masked dyads; missing=:face classifies them from their stored face values.

Example

using SNA
net = network(3)
add_edges!(net, [(1, 2), (2, 1), (2, 3)])
mutuality(net)                       # 1
source
SNA.hierarchy — Function
hierarchy(net; measure=:reciprocity, missing=:error) -> Float64

Graph hierarchy: R sna::hierarchy.

  • :reciprocity (default): 1 − grecip(net) (dyadic reciprocity).
  • :krackhardt: Krackhardt's hierarchy, the proportion of reachable (unordered) pairs whose reachability is one-way, i.e. 1 − the :dyadic_nonnull reciprocity of the reachability matrix.

A network with no dyads, or (for :krackhardt) no reachable pair, gives NaN, as in sna. missing=:error refuses masked dyads; missing=:face uses their stored face values.

Example

using SNA
chain = network(3)
add_edges!(chain, [(1, 2), (2, 3)])
hierarchy(chain; measure=:krackhardt)    # 1.0: every reachable pair is one-way
source
SNA.efficiency — Function
efficiency(net; missing=:error) -> Float64

Krackhardt's efficiency: R sna::efficiency.

Efficiency is computed per weak component in arc (digraph) terms, exactly as in sna: a component of size nᶜ requires nᶜ − 1 arcs for weak connection and can hold at most nᶜ(nᶜ − 1); arcs beyond the requirement are "excess", and efficiency is 1 − Σ excess / Σ maximum possible excess. An undirected edge counts as two arcs (sna treats symmetric data as a digraph), and self-loops are ignored (sna's diag=FALSE). A network whose components are all single vertices has no possible excess and gives NaN, as in sna.

missing=:error refuses masked dyads; missing=:face counts their stored face values as arcs.

Example

using SNA
path = network(3; directed=false)
add_edges!(path, [(1, 2), (2, 3)])
efficiency(path)                     # 1 − (4 − 2) / (6 − 2) = 0.5
source
SNA.connectedness — Function
connectedness(net; missing=:error) -> Float64

Krackhardt's connectedness: the proportion of (unordered) vertex pairs joined by a semipath, i.e. lying in the same weak component (R sna::connectedness). A network of one vertex has connectedness 1, as in sna.

missing=:error refuses masked dyads; missing=:face takes their stored face values as ties.

Example

using SNA
net = network(4; directed=false)
add_edges!(net, [(1, 2), (3, 4)])
connectedness(net)                   # 2 of 6 pairs = 0.3333
source
SNA.brokerage — Function
brokerage(net, cl; missing=:error) -> NamedTuple

Gould–Fernandez brokerage, R sna::brokerage. Actor j brokers the ordered pair (i, k) when i → j → k and there is no tie i → k. Given the class of every actor, cl (a vector with one entry per vertex, or the name of a vertex attribute), each brokered pair counts towards one role of j:

Rolesna labelClasses of i → j → k
coordinatorw_IA → A → A
itinerant brokerw_OA → B → A
representativeb_IOA → A → B
gatekeeperb_OIA → B → B
liaisonb_OA → B → C
totaltany

The result has sna's components, with the six roles in the order above (roles):

  • raw_nli: the n × 6 matrix of each actor's role counts;
  • exp_nli, sd_nli, z_nli: their expectation and standard deviation, and the z-scores (raw − exp) / sd, under Gould and Fernandez's null model, in which ties are independent with the observed density and the class sizes are fixed;
  • raw_gli, exp_gli, sd_gli, z_gli: the same for the network totals;
  • exp_grp, sd_grp: expectation and standard deviation per class (rows in the order of clid);
  • clid, n: the classes in order of first appearance and their sizes.

A z-score whose standard deviation is 0 is NaN or infinite, as in R. The z-scores refer to a normal approximation that is rough for small groups; a conditional uniform graph test (cug_test) gives a simulation-based alternative. On an undirected network every tie is read in both directions, as sna does. Self-loops are ignored (sna counts them in the density).

missing=:error refuses masked dyads; missing=:face uses their stored face values.

Example

using SNA
net = network(5)
add_edges!(net, [(1, 2), (2, 3), (3, 4), (4, 5)])
b = brokerage(net, [:a, :a, :b, :b, :c])
b.roles                              # ["w_I", "w_O", "b_IO", "b_OI", "b_O", "t"]
b.raw_nli[2, :]                      # actor 2 is a representative: 1 → 2 → 3
b.z_gli                              # z-scores of the network totals

References

Gould, R.V., Fernandez, R.M. (1989). Structures of mediation: a formal approach to brokerage in transaction networks. Sociological Methodology, 19, 89–126.

source

Census functions

SNA.dyad_census — Function
dyad_census(net; missing=:error) -> NamedTuple

The dyad census, R sna::dyad.census: the numbers of mutual, asymmetric and null dyads, as (mutual=…, asymmetric=…, null=…). Loops are not dyads.

missing=:error refuses masked dyads; missing=:face classifies each from its stored face value (there is no NA cell in this census).

Example

using SNA
net = network(3)
add_edges!(net, [(1, 2), (2, 1), (2, 3)])
dyad_census(net)                     # (mutual = 1, asymmetric = 1, null = 1)
source
SNA.triad_census — Function
triad_census(net; missing=:error) -> Vector{Int}

The triad census, R sna::triad.census.

Masked (unobserved) dyads are rejected by default (missing=:error); pass missing=:face to classify triads from the stored face values of their masked dyads (see NetworkCore.require_observed).

For directed networks, returns the 16-element Davis–Leinhardt census over the M-A-N (mutual/asymmetric/null) isomorphism classes, in the standard order used by R sna::triad.census:

003, 012, 102, 021D, 021U, 021C, 111D, 111U, 030T, 030C,
201, 120D, 120U, 120C, 210, 300

For undirected networks, returns the 4-element census by triad edge count (0, 1, 2, 3 edges).

Uses the edge-driven Batagelj–Mrvar (2001) algorithm: only triads containing at least one tie are enumerated (each exactly once, from its lowest-labeled connected pair), so the cost is O(Σ_(u,v)∈E (deg(u)+deg(v))) rather than O(n³); the empty-triad count is recovered by subtraction from C(n,3).

Example

using SNA
net = network(3)
add_edges!(net, [(1, 2), (2, 3), (1, 3)])
triad_census(net)[9]                 # 1: one 030T (transitive) triad
source

Graph correlation

SNA.gcor — Function
gcor(g1, g2; mode=:auto, diag=false, missing=:error) -> Float64

Graph correlation, R sna::gcor: the Pearson correlation of the two networks' tie values over the dyads they share. As in sna the diagonal is left out unless diag=true; an undirected pair counts once (mode=:graph), an ordered pair of a directed network once in each direction (mode=:digraph). mode=:auto takes undirected networks and symmetric matrices as undirected data.

The graphs are Networks or adjacency matrices. For two-mode data (two-mode networks, or p × q incidence matrices) only cross-mode pairs are compared.

missing=:error refuses masked dyads; missing=:face uses their stored face values.

Example

using SNA
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
gcor(flo, biz)                       # 0.3719, as R sna::gcor
source
SNA.gcov — Function
gcov(g1, g2; mode=:auto, diag=false, missing=:error) -> Float64

Graph covariance, R sna::gcov: the covariance of the two networks' tie values over the dyads they share, selected as in gcor.

Example

using SNA
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
gcov(flo, biz)
source

QAP Inference and Network Regression

Permutation tests and network regression following R sna::qaptest, sna::netlm, and sna::netlogit.

SNA.qaptest — Function
qaptest(f, g1, g2; n_sim=1000, threaded=true, missing=:error,
        rng=Random.default_rng()) -> QAPTestResult

Quadratic assignment procedure (QAP) test of the graph-level statistic f for the network pair (g1, g2), R sna::qaptest.

f(A1, A2) is computed on the adjacency matrices of the two networks and must return a scalar, for instance gcor. The observed value is compared with its distribution under n_sim independent uniform vertex permutations of g1 (rows and columns together) with g2 held fixed: the QAP null hypothesis of no association between the two structures, conditional on both. The p-values are the proportions of permuted values at least (pgreq) or at most (pleeq) the observed one, as in sna, so they can be exactly 0.

g1 and g2 are Networks or adjacency matrices of equal size.

Two-mode data. For two-mode networks, or p × q incidence matrices, f is called on the p × q incidence matrices (rows: mode 1, columns: mode 2), and each permutation reorders the mode-1 actors and the mode-2 actors separately. A directed two-mode network with ties from mode 2 to mode 1 is refused; pass its square sociomatrix as a raw matrix to test a statistic of the full matrix.

missing=:error refuses a network argument with masked (unobserved) dyads, because a masked dyad read at face value would enter both the statistic and the null distribution; missing=:face computes f from the stored face values. Raw matrices carry no mask.

Replicates use independently seeded random number generators drawn from rng, so results are reproducible and do not depend on the number of threads; threaded=false runs them serially. f must be thread-safe when threading is on.

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
qt = qaptest(gcor, flo, biz; n_sim=1000, rng=Xoshiro(1))
qt.testval, qt.pgreq                 # 0.3719, about 0.001
source
SNA.netlm — Function
netlm(y, xs; intercept=true, nullhyp=:qapspp, n_sim=1000, mode=:auto,
      threaded=true, missing=:error, rng=Random.default_rng()) -> NetLMResult

Linear (OLS) regression of the network y on one or more predictor networks xs, with QAP null-hypothesis testing, R sna::netlm.

The networks are vectorized over their dyads (all ordered pairs for directed data, one entry per unordered pair for undirected data; the diagonal is always excluded) and y is regressed on the predictors by OLS. Coefficient significance is assessed by comparing the observed t-statistics with a permutation null distribution.

Arguments

  • y: Dependent network (Network or adjacency matrix)
  • xs: Predictor network(s): a single network/matrix, or a vector/tuple of them, all of the same order as y
  • intercept::Bool=true: Include an intercept column
  • nullhyp::Symbol=:qapspp: Null hypothesis for the coefficient tests
    • :qap/:qapspp: Dekker's double-semi-partialing QAP (default, as in modern R sna): each predictor is residualized on the remaining predictors, the residual matrix is repeatedly row/column-permuted, and the t-statistic of the permuted residual (refit alongside the other predictors) forms the null distribution. Robust to multicollinearity among the predictors. With a single regressor this degenerates to :qapy.
    • :qapy: Classical y-permutation QAP: permute the rows/columns of y and refit
    • :qapx: Permute each predictor matrix separately and refit
    • :classical: Parametric t-tests (no permutation), for reference only: dyadic dependence typically makes them badly anti-conservative
  • n_sim::Int=1000: Number of permutation replicates (R's reps)
  • mode::Symbol=:auto: Dyad set: :digraph (every ordered pair), :graph (every unordered pair), or :auto, which takes the directedness of y when it is a network and, for raw matrices, treats the data as undirected when y and every predictor are symmetric. (sna's default is "digraph" for any matrix, which counts each pair of a symmetric matrix twice and makes the classical standard errors √2 too small.)
  • missing::Symbol=:error: Missing-dyad policy for y and the predictors (NetworkCore.require_observed). A masked (unobserved) dyad read at face value becomes a fabricated row of the design matrix, biasing both the coefficients and the QAP null, so the default :error rejects a masked network argument. :face is the explicit opt-in to regressing on the stored face values; netlm does not implement listwise deletion of unobserved dyads or any missing-data estimator (NetworkCore.supports_missing(netlm) == false)
  • rng: Random number generator

Two-mode data. For two-mode networks (or p × q incidence matrices) the observations are the cross-mode dyads only: within-mode pairs cannot carry a tie, and treating them as observed zeros would add a spurious association (and can flip the sign of a slope). Permutations reorder each mode separately. For a directed two-mode network the mode-2 → mode-1 pairs are included only when some argument has a tie there.

The two-sided permutation p-value pgreqabs is reported by show; one-sided pleeq/pgreq are also stored. As in sna, a p-value is the proportion of permuted statistics at least as extreme as the observed one (no +1 correction), so it can be exactly 0; show prints it as < 1/n_sim.

Replicates use independently seeded random number generators drawn from rng and are reproducible across thread counts; threaded=false disables threading.

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
fit = netlm(flo, biz; n_sim=500, rng=Xoshiro(1))
source
SNA.netlogit — Function
netlogit(y, xs; intercept=true, nullhyp=:qapspp, statistic=:lr, n_sim=1000,
         mode=:auto, threaded=true, missing=:error,
         rng=Random.default_rng()) -> NetLogitResult

Logistic regression of the binary network y on one or more predictor networks xs, with QAP null-hypothesis testing, R sna::netlogit.

The networks are vectorized over dyads exactly as in netlm (including its treatment of mode, two-mode data and missing dyads), and a binomial GLM with logit link is fitted by the shared Newton optimizer. The supported null hypotheses (:qap/:qapspp, Dekker double semi-partialing, the default; :qapy; :qapx; :classical) have the same meaning as in netlm. As in R sna, the semi-partialing residuals are computed by linear regression of each predictor on the others, then permuted and refitted in the logistic model.

y must be dichotomous (all dyad values 0 or 1).

The test statistic

A QAP test compares a statistic with its permutation distribution, and any statistic gives a valid test. sna uses the Wald z, coef / se. On sparse binary data that statistic often does not exist for some permutation: the permuted design is separated, the maximum-likelihood coefficient is infinite, and sna's glm returns a meaningless z near 0 for it. On Florentine marriage ~ business ties about 6 % of the permutations are separated.

  • statistic=:lr (default): the signed root likelihood-ratio statistic sign(β̂ₖ) √(D₋ₖ − D), where D is the model's deviance and D₋ₖ the deviance without coefficient k. It is finite on separated permutations too (the deviance has an infimum), so every replicate counts and none is dropped. In large samples it is close to the Wald z.
  • statistic=:wald: sna's Wald z. A separated permutation has no Wald z, so the permutation p-values of every coefficient with a separated replicate are withheld (NaN, with a warning saying how many replicates were separated) rather than computed from a fabricated z or from the surviving replicates only.

nullhyp=:classical fits only the observed design and reports sna's Wald test against a t distribution; its p-values assume independent dyads, which dyadic dependence typically violates badly, and are not a substitute for QAP inference.

If the observed design is completely or quasi-completely separated there is no finite estimate. netlogit then follows the ecosystem's separation policy (NetworkCore.logistic_separation): it warns, returns the fit with converged == false, names the separated coefficients in fit.separated, and withholds inference. The test statistics, p-values and confidence intervals are NaN, and no permutation is run. R's glm warns "fitted probabilities numerically 0 or 1 occurred" for the same design, and sna::netlogit reports its meaningless estimates and p-values.

The reported null deviance is that of the model with every probability 1/2, 2N log 2, as sna computes it (sna fits without a separate intercept); a pseudo-R² computed from it is larger than one computed from the intercept-only deviance. Missing dyads are handled exactly as in netlm: netlogit implements no missing-data estimator (NetworkCore.supports_missing(netlogit) == false).

n_sim replicates (R's reps) use independently seeded random number generators drawn from rng and are reproducible across thread counts; threaded=false disables threading.

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
fit = netlogit(flo, biz; n_sim=1000, rng=Xoshiro(1))   # DSP QAP, LR statistic
fit.pgreqabs                         # business ties: p < 0.001
source

Conditional uniform graph tests

SNA.cug_test — Function
cug_test(net, f; cmode=:size, n_sim=1000, threaded=true, missing=:error,
         rng=Random.default_rng(), kwargs...) -> CUGTestResult

Conditional uniform graph (CUG) test of the graph-level statistic f, R sna::cug.test. The observed f(net; kwargs...) is compared with its distribution over n_sim networks drawn uniformly at random from the networks that share a feature of net:

  • cmode=:size (default): the same number of vertices (every tie present independently with probability 1/2);
  • cmode=:edges: the same number of vertices and of ties;
  • cmode=:dyad_census: the same numbers of mutual, asymmetric and null dyads.

The simulated networks have the directedness of net and no self-loops. f is any function of a Network that returns a number, for instance gtrans, grecip or g -> centralization(g, degreecent); keyword arguments other than those listed are passed to it.

The result reports pgteobs and plteobs, the proportions of simulated values at least and at most the observed one (as in sna, without a +1 correction, so they can be 0). A small pgteobs says the statistic is larger than expected from the conditioning feature alone. Simulated values that are NaN count in neither tail.

Self-loops in net are ignored (sna's diag=FALSE); conditioning with loops (diag=TRUE), valued networks (ignore.eval=FALSE) and two-mode networks are not implemented and raise an ArgumentError.

Replicates use independently seeded random number generators drawn from rng, so the result is reproducible and does not depend on the number of threads; threaded=false runs them serially. f must be thread-safe when threading is on. missing=:error refuses a network with masked dyads; missing=:face uses their stored face values (f itself is called on unmasked networks).

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
# Is the marriage network more transitive than its density implies?
ct = cug_test(flo, gtrans; cmode=:edges, n_sim=500, rng=Xoshiro(1))
ct.obs_stat                          # 0.1915
ct.pgteobs                           # about 0.33: no
source
SNA.CUGTestResult — Type
CUGTestResult

Result of a cug_test, with the fields of R's cug.test object.

Fields

  • obs_stat::Float64: the observed statistic
  • rep_stat::Vector{Float64}: its values on the simulated networks
  • cmode::Symbol: what the simulated networks were conditioned on
  • directed::Bool: whether the networks are directed
  • plteobs::Float64: the proportion of simulated values <= the observed one
  • pgteobs::Float64: the proportion of simulated values >= the observed one
  • reps::Int: the number of simulated networks (n_sim)

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
ct = cug_test(flo, gtrans; cmode=:edges, n_sim=200, rng=Xoshiro(1))
ct isa CUGTestResult, ct.obs_stat, ct.pgteobs
source

Result Types

SNA.QAPTestResult — Type
QAPTestResult

Result of a qaptest permutation test, with the fields of R's qaptest object.

Fields

  • testval::Float64: Observed value of the test statistic
  • dist::Vector{Float64}: Monte Carlo null distribution (one value per replicate)
  • pgreq::Float64: Proportion of null draws >= the observed value
  • pleeq::Float64: Proportion of null draws <= the observed value
  • reps::Int: Number of replicates (n_sim)

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
qt = qaptest(gcor, flo, biz; n_sim=200, rng=Xoshiro(1))
qt isa QAPTestResult, qt.pgreq
source
SNA.NetLMResult — Type
NetLMResult

Result of a netlm network regression.

Fields

  • coefficients::Vector{Float64}: OLS coefficient estimates
  • names::Vector{String}: Coefficient names
  • tstat::Vector{Float64}: t-statistics
  • covariance::Matrix{Float64}: iid-dyad OLS covariance
  • loglik::Float64: maximized iid Gaussian log likelihood
  • pleeq::Vector{Float64}: p(stat_perm <= stat_obs) per coefficient
  • pgreq::Vector{Float64}: p(stat_perm >= stat_obs) per coefficient
  • pgreqabs::Vector{Float64}: Two-sided p(|stat_perm| >= |stat_obs|) (the p-value reported by show)
  • dist::Union{Nothing,Matrix{Float64}}: Null distribution of the test statistics (n_sim × k; nothing for nullhyp = :classical)
  • r_squared::Float64: Coefficient of determination
  • adj_r_squared::Float64: Adjusted R²
  • n::Int: Number of dyadic observations
  • df_residual::Int: Residual degrees of freedom
  • nullhyp::Symbol: Null hypothesis actually used
  • reps::Int: Number of Monte Carlo replicates (0 for :classical)
  • intercept::Bool: Whether an intercept column was included
  • directed::Bool: Whether the dyads were treated as directed

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
fit = netlm(flo, biz; n_sim=200, rng=Xoshiro(1))
fit isa NetLMResult, coef(fit)
source
SNA.NetLogitResult — Type
NetLogitResult

Result of a netlogit network logistic regression.

Fields

  • coefficients::Vector{Float64}: Logit coefficient estimates
  • names::Vector{String}: Coefficient names
  • se::Vector{Float64}: Standard errors (inverse Fisher information)
  • covariance::Matrix{Float64}: iid-dyad inverse-information covariance
  • converged::Bool: Whether the shared Newton fit converged
  • tstat::Vector{Float64}: the test statistic of each coefficient: the signed root likelihood-ratio statistic for statistic = :lr, the Wald z (coef ./ se) for statistic = :wald and nullhyp = :classical
  • pleeq::Vector{Float64}: p(stat_perm <= stat_obs) per coefficient
  • pgreq::Vector{Float64}: p(stat_perm >= stat_obs) per coefficient
  • pgreqabs::Vector{Float64}: Two-sided p(|stat_perm| >= |stat_obs|)
  • dist::Union{Nothing,Matrix{Float64}}: Null distribution of the test statistics (nothing for nullhyp = :classical)
  • deviance::Float64: Residual deviance
  • null_deviance::Float64: Deviance of the model with every probability 1/2 (2N log 2), as sna reports it; not the intercept-only deviance
  • aic::Float64, bic::Float64: Information criteria
  • n::Int: Number of dyadic observations
  • df_residual::Int: Residual degrees of freedom
  • nullhyp::Symbol: Null hypothesis actually used
  • reps::Int: Number of Monte Carlo replicates (0 for :classical)
  • intercept::Bool: Whether an intercept column was included
  • directed::Bool: Whether the dyads were treated as directed
  • statistic::Symbol: The QAP test statistic, :lr or :wald
  • separation::NetworkCore.SeparationVerdict: the separation verdict on the observed design (NetworkCore.logistic_separation)
  • separated::Vector{String}: the coefficients whose maximum-likelihood value is infinite (the separated terms); empty when the observed design has a finite maximiser. When it is not empty, converged is false and the test statistics, p-values and confidence intervals are NaN

Example

using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
fit = netlogit(flo, biz; n_sim=200, rng=Xoshiro(1))
fit isa NetLogitResult, fit.statistic
source

Result Metadata

SNA.jl implements the ecosystem's result-metadata protocol for its regression results, so what a fit did is inspectable via NetworkCore.fit_metadata(result).

NetworkCore.objective — Method
objective(::NetLMResult) -> Symbol

:least_squares — the coefficients are ordinary least squares of the vectorized dyads of y on the vectorized dyads of the predictors. Nothing about the QAP null enters the point estimates.

source
NetworkCore.objective — Method
objective(::NetLogitResult) -> Symbol

:likelihood — the coefficients maximize the binomial (logit-link) likelihood of the vectorized dyads, fitted by the shared Newton optimizer.

source
NetworkCore.is_exact — Method
is_exact(::NetLMResult) -> Bool

true: OLS solves its objective in closed form, and that objective is the exact Gaussian likelihood of the model actually fitted — a regression treating the dyads as independent observations. It is not a statement that the dyads are independent; that assumption is exactly what the QAP permutation null in NetworkCore.approximations is there to work around.

source
NetworkCore.is_exact — Method
is_exact(r::NetLogitResult) -> Bool

true when the Newton fit converged to a finite maximum: it then maximizes the exact binomial likelihood of the dyad-independent logit model that is being fitted. As with netlm, this says the objective is not approximated — not that the independence assumption holds. false for an unconverged fit and for a separated design, which has no maximum.

source
NetworkCore.se_method — Method
se_method(::NetLMResult) -> Symbol

:ols — homoskedastic iid-dyad OLS covariance. These standard errors studentize the QAP statistic; they do not account for dyadic dependence.

source
NetworkCore.se_method — Method
se_method(::NetLogitResult) -> Symbol

:fisher — the inverse Fisher information of the binomial GLM (inv(X'WX) at convergence), which treats every dyad as an independent observation and is therefore anticonservative under dyadic dependence. The reported p-values do NOT come from these standard errors (unless nullhyp = :classical): they come from the QAP permutation null.

source

Inference contracts

netlm and netlogit implement coef, coefnames, stderror, vcov, confint, loglikelihood, nobs, dof, aic, bic, and coeftable from StatsAPI. The point estimates are an ordinary OLS or logistic fit that treats the dyads as independent, and so are the covariance and confidence intervals; dyadic dependence makes them anti-conservative. Inference about the coefficients comes from the QAP permutation p-values (pgreqabs, printed by show).

  • The default null hypothesis is Dekker's double semi-partialing (:qapspp), which keeps its size when predictors are correlated; :qapy and :qapx are also available. nullhyp=:classical reports parametric tests that assume independent dyads: for reference only.
  • A p-value is the proportion of permuted statistics at least as extreme as the observed one, without a +1 correction, as in sna; it can be 0 and is printed as < 1/n_sim.
  • netlogit's QAP statistic is the signed root likelihood-ratio statistic by default. Sparse binary data often have permutations whose logistic fit is separated (an infinite coefficient); the likelihood-ratio statistic exists there, so every replicate counts. statistic=:wald uses sna's Wald z, which does not exist on a separated permutation: the permutation p-values of the coefficients such a replicate touches are then withheld (NaN, with a warning), never computed from the surviving replicates.
  • An observed design that is completely or quasi-completely separated has no finite estimate. netlogit follows the ecosystem's separation policy: it warns, returns converged == false with the separated coefficients in fit.separated, and withholds the test statistics, p-values and confidence intervals (NaN); no permutation is run. The verdict is NetworkCore.jl's logistic_separation: a linear programme over the design, with the separating direction verified in exact arithmetic.
  • Two-mode data use the cross-mode dyads only, and permutations reorder each mode separately.
  • Raw matrices with mode=:auto are undirected when the response and every predictor are symmetric (sna treats every matrix as directed).
using SNA, Random
flo = load_dataset(:florentine_marriage)
biz = load_dataset(:florentine_business)
fit = netlm(flo, biz; n_sim=200, rng=Xoshiro(2026))
coef(fit)
coefnames(fit)                       # ["(intercept)", "x1"], R's names(coef(fit))
stderror(fit)
confint(fit)
coeftable(fit)
fit.pgreqabs                         # the QAP p-values

Replicate random number generators are seeded from rng before scheduling, so threaded=false and threaded=true give the same result. A qaptest statistic must be thread-safe when threading is on.