API reference

Orbits and bins

SamplingPerceivedNetworks.vertexorbit — Function
    vertexorbit(graph::T, vertex, dₘₐₓ; index = true) where T <: MetaGraph

Generate the social orbit of a perceiver on an undirected, unweighted network (a MetaGraph whose vertices have a :name property). The orbit contains everyone within dₘₐₓ steps of the perceiver, who is removed from the returned graph. Edges carry the properties :d (distance) and :real (whether the tie exists in graph).

If index is true, vertex is the vertex index; otherwise it is the node name, which requires set_indexing_prop!(graph, :name). name is the property that holds node names.

source
SamplingPerceivedNetworks.vertexorbit_d — Function
    vertexorbit_d(rad, d) where T <: MetaGraph

Restrict a social orbit to the ties that first appear at distance d, removing those at all other distances. rad is the output of vertexorbit.

source
SamplingPerceivedNetworks.samplingbins — Function
    samplingbins(orbit, dₘₐₓ)

Group every candidate pair in orbit (the output of vertexorbit) into sampling bins, keyed by (distance, is_real). Each bin is a vector of name pairs, and the bins are the sets from which samplebins draws.

source
    samplingbins(orbit, dₘₐₓ, consents)

As samplingbins(orbit, dₘₐₓ), omitting pairs in which either node has not consented to photos (consent code below 2).

Arguments ≡≡≡≡≡≡≡≡≡≡≡

  • orbit: the output of vertexorbit
  • dₘₐₓ: the maximum distance the orbit was built with
  • consents: a map from each node name to its consent code
source

Sampling

SamplingPerceivedNetworks.samplebins — Function
    samplebins(
        [rng],
        bins;
        desired = deployed_design.desired, dvals = deployed_design.dvals,
        moreinfo = false, carryover = true, outer = nothing
    )

Sample from bins to generate the CSS list for one perceiver, as a vector of pairs. With moreinfo = true, also return the degree bin and the reality of each pair. dvals must be in increasing order.

If rng is given, every draw uses it. samplenetwork passes each perceiver's own seeded generator.

When a bin, given as (degree, reality), is smaller than the desired number, other bins are oversampled so that the total desired number (or the maximum possible number) is reached for that survey.

With carryover = true (the default), shortfalls are carried forward. A real bin that cannot supply the desired number is topped up from the real bin at the next degree. A real shortfall remaining after the last degree is made up from the counterfactual bins.

With outer = (r, f), an outer bin of all remaining eligible pairs (a member beyond dₘₐₓ, or unreachable) supplies r real and f counterfactual pairs. It is the last bin in the carry-over order. bins must then contain the keys (0, true) and (0, false), which samplenetwork builds; its degree label is 0.

Arguments ≡≡≡≡≡≡≡≡≡≡≡

  • [rng] : random number generator, e.g., MersenneTwister(2)
  • bins: full sampling bins from which to sample
  • desired: tuple of (# real, # counterfactual) for each degree bin in dvals
  • dvals: degree bins, in increasing order; each is an integer or a range of integers (combining degrees into one bin). Must be the same length as desired
  • moreinfo: if true, also return the degree bin and the reality of each pair
  • carryover: if false, a bin smaller than desired is not made up from other bins, so the list is shorter; this is the procedure as described in Feltham et al. (2025)
  • outer: nothing (the default, as deployed) or (# real, # counterfactual) for the outer bin
source
SamplingPerceivedNetworks.samplenetwork — Function
    samplenetwork(
        [rng],
        graph;
        desired = ((5, 5), (5, 5), (5, 5), (5, 5)),
        dvals = (1, 2, 3, 4),
        moreinfo = false,
        shuffle = true,
        carryover = true,
        outer = nothing
    )

Generate, for each person in an unweighted, undirected sociocentric network, a list of relationships to show them, using the social orbit procedure. For each degree bin in dvals, sample real and counterfactual pairs in the numbers given by desired.

dvals contains integers or integer ranges (a range combines several degrees into one bin). desired has one tuple (# real, # counterfactual) for each element of dvals, in the same order.

By default a bin smaller than desired is made up from other bins (see samplebins), so lists keep their full length where possible. With carryover = false each bin supplies at most its own desired number, as in the procedure described in Feltham et al. (2025), and a short bin gives a shorter list.

With outer = (r, f), an extra outer bin holds every remaining pair (a member farther than the last degree bin, or unreachable) and supplies r real and f counterfactual pairs, so that no eligible pair has inclusion probability zero. It is the last bin in the carry-over order, and its degree label is 0. The default, nothing, is the deployed design.

This is the stratified stage only. samplevillage adds the fill to the target length and the lists for isolates, as deployed.

Optionally specify a random number generator (rng).

source
    samplenetwork(
        [rng],
        graph,
        consents;
        desired = ((5, 5), (5, 5), (5, 5), (5, 5)),
        dvals = (1, 2, 3, 4),
        moreinfo = false,
        shuffle = true,
        carryover = true,
        outer = nothing
    )

Generate, for each person in an unweighted, undirected sociocentric network, a list of relationships to show them, using the social orbit procedure. For each degree bin in dvals, sample real and counterfactual pairs in the numbers given by desired.

dvals contains integers or integer ranges (a range combines several degrees into one bin). desired has one tuple (# real, # counterfactual) for each element of dvals, in the same order.

By default a bin smaller than desired is made up from other bins (see samplebins), so lists keep their full length where possible. With carryover = false each bin supplies at most its own desired number, as in the procedure described in Feltham et al. (2025), and a short bin gives a shorter list. outer adds an outer bin of all remaining pairs (see above).

Optionally specify a random number generator (rng).

Consent codes in consents (a Dict from node name to code): 0 = none, 1 = survey only, 2 = survey and photo, 3 = photo only. Only perceivers with code 1 or 2 receive a list (others are absent from the result); a pair is included only if both nodes have code ≥ 2, so a perceiver may get a short or empty list. Every node must have an entry (ArgumentError otherwise).

source
SamplingPerceivedNetworks.samplevillage — Function
    samplevillage(
        [rng],
        graph[, consents];
        isolates = String[],
        desired = deployed_design.desired,
        dvals = deployed_design.dvals,
        outer = nothing,
        carryover = true,
        randomfill = true,
        excludeperceiver = false,
        moreinfo = false,
        shuffle = true
    )

Generate the CSS lists for one village with the procedure deployed in the Honduras CSS (the HonCog.jl server code), in one call:

  1. the stratified stage, samplenetwork (orbit bins, gap carry-over, consent filter, shuffle), with the same arguments;
  2. fill to the target length (with randomfill = true): a list shorter than the target (countdesired(desired), 40 for deployed_design, plus the outer-bin quota if any) gets ceil(gap/2) real and floor(gap/2) counterfactual pairs, drawn uniformly without replacement from the whole village: every real tie, or every non-adjacent pair, among the nodes of graph with consent code ≥ 2, minus the pairs already on the list. Each pool supplies at most what it has. The fill pairs are shuffled and appended after the stratified pairs (so they are shown last);
  3. isolates: each name in isolates with consent code > 1 (2 or 3; any name if consents is not given) gets ceil(target/2) real and floor(target/2) counterfactual pairs drawn uniformly from the same village pools, with no exclusions. In HonCog an isolate is a respondent who named no one (a row with a missing alter), so they are not in graph and not in the pools. If an isolate is in graph, the new list replaces their stratified list.

Build graph from the edgelist alone, as HonCog did, so that people without ties enter only through isolates; the fill pools are the pairs among the vertices of graph. With moreinfo = true, fill and isolate pairs have the degree label -1 ("fill" in psn_edgelists). The stratified stage uses one seed per perceiver drawn from rng; the fill and isolate draws then continue on rng, visiting the lists in Dict order and then the isolates in the given order. (HonCog drew them from the global generator, so the field draws cannot be regenerated from the village seed.)

Deployed behavior reproduced, and the options that change it:

  • excludeperceiver = false (default): the fill pool may contain pairs that involve the perceiver, as in HonCog of 2022-10-25 (commit 6213868). The delivered Honduras data contain such pairs, consistent with this version. HonCog's last commit (2022-12-12, ecbab7f) tried to remove them but passes its arguments in the wrong order and throws a MethodError whenever a list is short, so it cannot have produced lists. excludeperceiver = true gives the intended rule.
  • consent: perceivers need code 1 or 2 (as in samplenetwork), isolates code > 1, so an isolate with code 3 (photo only) gets a list.
  • isolates' lists have no perceiver exclusion and no distance structure.

inclusionprobs(graph[, consents]; randomfill = true, isolates, ...) returns the exact inclusion probabilities of this procedure.

source
SamplingPerceivedNetworks.deployed_design — Constant
    deployed_design

Preset for the desired and dvals keywords (splat it in, e.g., samplenetwork(graph; deployed_design...)): the design fielded in the Honduras CSS. Four separate degree bins, 5 real and 5 counterfactual in each. This is the default of samplenetwork, samplebins and inclusionprobs.

source
SamplingPerceivedNetworks.merged_design — Constant
    merged_design

Preset for the desired and dvals keywords: an alternative that combines degrees 1 and 2 into one bin with 10 + 10 (and 5 + 5 at degrees 3 and 4). It was never deployed.

source
SamplingPerceivedNetworks.inclusionprobs — Function
    inclusionprobs(graph, v[, consents]; desired, dvals, carryover, outer,
                   randomfill = false, excludeperceiver = false, isolates)
    inclusionprobs(graph[, consents]; desired, dvals, carryover, outer,
                   randomfill = false, excludeperceiver = false, isolates)

Exact first-order inclusion probabilities of the lists drawn by samplenetwork (the default) or, with randomfill = true, by samplevillage, computed from the graph without any random sampling. Pass the same keywords as to the sampler.

The first form is for the perceiver at vertex v. The second stacks every person who would receive a list (with consents: code 1 or 2, plus the isolates that samplevillage serves) and adds a perceiver column. Both return a DataFrame with one row for every pair that could be shown, with columns from and to (each pair sorted alphanumerically), bin (the stratum: the degree bin, e.g., "1:2", "outer", or "none" for a pair that enters only through the fill or an isolate's list), real (whether the pair is a real tie) and pi (the probability that the pair is on the perceiver's list). Pairs that are not listed have probability zero. The weight for estimation is 1 / pi.

Stratified stage. Within a cell (bin × reality) the draw is a simple random sample without replacement, so pi₁ = n / N: N is the size of the cell and n the number drawn after the gap carry-over (see samplebins; carryover = false turns it off). n depends only on the cell sizes, so it is fixed given the graph and consents. The outer bin (outer = (r, f)) is one more cell.

Fill (randomfill = true). The stratified list has the fixed length L = Σ n, so the gap g = target - L and its split (g_r, g_f) = (ceil(g/2), floor(g/2)) are fixed too. Let P_r be the village pool of real pairs (consent-eligible ties among the nodes of graph; without the perceiver's own pairs if excludeperceiver). Every real pair drawn in the stratified stage is in P_r, and the number drawn is Σ n_real, so the pool left for the fill always has size M_r = |P_r| - Σ n_real, whichever pairs were drawn. The fill takes m_r = min(g_r, M_r) of them uniformly, so a pair not already on the list is drawn with probability m_r / M_r, and

pi = pi₁ + (1 - pi₁) m_r / M_r,

with pi₁ = 0 for a pair in no stratum; likewise for counterfactual pairs. This is exact. Isolates (isolates): an isolate's list is ceil(target/2) real and floor(target/2) counterfactual pairs drawn uniformly from the whole pools P_r and P_f (no exclusions), so pi = min(⌈target/2⌉, |P_r|) / |P_r| for real pairs, and likewise for counterfactual pairs; it replaces any other list the person has.

pi is the probability that a pair is on the list, not that it was answered: respondents who do not recognize someone in a pair are not asked about it, and this is not modeled. consents follows samplenetwork: a pair is eligible only if both nodes have code ≥ 2.

source

Utilities

SamplingPerceivedNetworks.psn_edgelists — Function
    psn_edgelists(vertlists; df_out = true)

Flatten the output of samplenetwork or samplevillage (a dictionary from perceiver name to that perceiver's list) into one edgelist with a row per (perceiver, pair). Columns: perceiver, from, to; if the lists were generated with moreinfo = true, also bin (the degree bin, e.g., "1:2" or "3"; "outer" for the outer bin; "fill" for a pair drawn village-wide by the fill or for an isolate) and real (whether the pair is a real tie). Each pair is sorted alphanumerically. Return a DataFrame, or a Matrix if df_out is false.

source
SamplingPerceivedNetworks.edgelist — Function
    edgelist(graph; df_out = true)

Extract the sociocentric edgelist of graph (a MetaGraph with :name vertex properties) as node names. Return a DataFrame with columns from and to, each row sorted alphanumerically; if df_out is false, return the raw Matrix of names in the graph's edge order (rows are not sorted).

source
SamplingPerceivedNetworks.countdesired — Function
    countdesired(desired)

Total number of relationships in a desired specification, i.e., the sum of all (# real, # counterfactual) entries: the target list length per perceiver.

source
SamplingPerceivedNetworks.tupleize — Function
    tupleize(alters1, alters2; sort = false)

Create a vector of tuples from the columns of an edgelist. If sort is true, each tuple is ordered alphanumerically (for symmetric ties); leave it false if the ties are asymmetric.

source
SamplingPerceivedNetworks.sort_edgelist! — Function
    sort_edgelist!(df, c1, c2)

Within each row of the DataFrame df, order the values in columns c1 and c2 alphanumerically (so that an undirected tie always reads the same way).

source