Skip to contents

Reconstructs the second-order design quantities for PPS stages. For without-replacement (WOR) stages, this produces the joint inclusion probabilities \(\pi_{kl}\). For with-replacement (WR) and PMR stages, this produces the joint expected hits \(E(n_k \cdot n_l)\).

Usage

joint_expectation(
  x,
  frame = NULL,
  ...,
  stages = NULL,
  period = NULL,
  subround = NULL,
  nsim = 10000L,
  seed = 1L
)

Arguments

x

A tbl_sample object produced by execute().

frame

The frame originally passed to execute(). A data frame is the one shared frame. An ordered list of data frames is the stage registers, one per executed stage, in the order they were supplied to execute(). Either way each frame must contain the columns its stage sampled on (strata variables, cluster variables, measure of size). When NULL (the default), the computation uses the frame digest recorded on the sample instead.

The frame is checked against the digest recorded at execution. Other columns, another row order or other column types are accepted when every pool keeps the size and selection chances the sample was drawn with. Rows added or removed, a changed design value or a missing design column are refused with samplyr_error_joint_frame_mismatch, and so is any difference at all for a stage whose method depends on row order (systematic, pps_systematic, pps_systematic_mr, pps_chromy, registered methods), whose matrix is that of the order. Under frame_digest = "none" there is nothing to compare against, and a warning says so.

...

These dots are for future extensions and must be empty. stages and the arguments after it must be named exactly: the singular stage is reported rather than prefix-matched.

stages

An integer vector of stage numbers to compute, or NULL (default) to compute all PPS stages. Non-PPS stages produce NULL entries in the returned list.

period, subround

Two occasions of a scheduled master, which selects activation mode: the result describes how those two occasions of the rotation overlap rather than how the master was selected. They are read as pairs, as in execute(), and must name exactly two occasions, such as period = c(2, 3) on a schedule without subrounds, or period = c(1, 2), subround = c(2, 1) for month 2 of quarter 1 and month 1 of quarter 2. Give the same occasion twice for the joint expectation within one occasion. NULL (default) keeps the stage behavior. Mutually exclusive with stages, frame, nsim and seed, none of which activation mode uses.

nsim

Positive integer number of simulations used for Chromy's pairwise expected hits (default 10000), also forwarded to registered WR joint_fns that explicitly declare an nsim formal. Among the built-in methods only pps_chromy simulates, and the analytic ones, pps_systematic_mr included, ignore it. Raising it narrows the simulation error, at a cost linear in nsim.

seed

Single integer seeding the simulated methods (default 1), which analytic methods ignore. The session's random stream is restored afterwards, so the result is an exact function of the sample, nsim and seed, and calling this never moves a later execute(). At the default nsim a pps_chromy matrix carries simulation error of a few percent, so two seeds give slightly different answers, neither more correct than the other.

Value

With period, a tibble with one row per block of the frozen assignment, described in the "Activation mode" section. Otherwise a named list of length equal to the number of executed stages. Each element is either:

  • For PPS WOR stages: a square matrix of joint inclusion probabilities \(\pi_{kl}\), usable with survey::ppsmat().

  • For PPS WR/PMR stages (pps_multinomial, pps_chromy, pps_systematic_mr): a square matrix of joint expected hits \(E(n_k \cdot n_l)\).

  • NULL for non-PPS stages (SRS, systematic) or stages not requested via the stages argument.

Rows and columns are the stage's sampled units in the order they first appear in the rows as_svydesign() exports. These are the sample's rows, followed by a zero row for each selected primary unit whose later stages selected nothing. For a sample with one row per stage-1 unit, the stage-1 matrix therefore follows the exported rows, which is how survey::ppsmat() reads it. At a WR stage, repeated hits of the same population unit appear once, so dimensions match the number of distinct sampled units (or clusters). At a later stage below a WR parent, each parent draw occurrence defines a separate conditional block, so the same child population identity can appear in more than one block.

Each matrix is dense and covers every sampled unit of the stage, across pools as well as within them, so m sampled units take \(8 m^2\) bytes: about 80 MB at 3,200 units, 0.8 GB at 10,000 and 12.8 GB at 40,000. For a large stage, request only the stages needed with stages.

Details

Without frame, the computation uses the frame digest recorded at execution, so a sample that traveled without its (possibly confidential) frame still yields joint expectations at the method's stated quality. This needs each pool's exact chances, which the digest always holds for cluster stages and constant-chance element stages, but for element stages with varying chances only under execute(frame_digest = "full"). A summarized digest refuses rather than approximates, so pass the frame instead. An exact record of approximate targets does not make their probabilities exact. A supplied frame must keep the pools the sample was drawn from, as frame describes, and its units must be uniquely identifiable within each stratum/cluster group by their column values.

A sample drawn from separately supplied stage registers needs either its intact digest or all of those registers, in the order they were supplied. One frame is refused with samplyr_error_frame_count, because a lower-stage register holds no rows for the population an upper stage selected from.

Each PPS stage's full-population first-order quantities are rebuilt from its method and measure of size, with per-stratum targets (n_h) replayed from the allocation execute() used (proportional, Neyman, optimal, etc.), so they match those at sampling time. The matching sondage joint function then gives the submatrix of sampled units.

For stratified or conditional (within-cluster) stages, joint quantities are computed independently within each group, and cross-group entries are products of the marginal chances. The rows are then put in the order the units first appear in the sample, so the units of one group need not be contiguous. Below a WR parent, pair the matrix with stage-specific identities in this order, not blindly with every sample row when descendants duplicate a selected unit.

With certainty selections (\(\pi_i = 1\)) in a WOR design, the joint probabilities of the non-certainty units are computed from the reduced \(\pi\) vector, and the full matrix is reassembled with \(\pi_{ij} = 1\) for certainty pairs and \(\pi_{ij} = \pi_j\) for certainty x non-certainty pairs. A certainty rule at a WR or PMR stage takes each certainty unit once, so its hit count is 1 whatever the draw: \(E(n_i n_j) = 1\) for two certainty units, the diagonal included, and \(E(n_i n_j) = E(n_j)\) when only \(i\) is one. The other units are drawn with the remaining hits over their own sizes.

A second phase drawn within each final-stage pool of phase 1, by equal probabilities, is exported by as_svydesign() as phase 1's design with a smaller final take. Its matrices are that design's: each stage above the last is phase 1's, computed from phase 1's digest or from frame, which is then phase 1's frame, in the order of the rows it exports, and stages numbers the stages of that design. The last stage draws by equal probabilities and has no matrix.

Exact vs. approximate computation

The accuracy of the returned matrix depends on the sampling method, as the two tables below show. variance_estimation covers how a matrix enters a variance estimate.

WOR methods (\(\pi_{kl}\))

Every matrix here comes from sondage::joint_inclusion_prob().

MethodQuality
pps_cpsExact, Aires' formula
pps_sampfordExact, Sampford design
pps_systematicExact, circular-interval overlap
pps_poissonExact, independent draws
pps_brewerApproximate\(^*\), high-entropy
pps_spsApproximate, high-entropy
pps_paretoApproximate, high-entropy
cubeApproximate when unconstrained
lpm2Unavailable, spatial spreading not represented
scpsUnavailable, spatial spreading not represented
registeredFrom the method's joint_fn

Poisson draws are independent, so \(\pi_{kl} = \pi_k \pi_l\). Unconstrained cube uses the high-entropy approximation too.

Systematic PPS commonly has zero pair probabilities. Its exact matrix describes the design, but a zero pair probability rules out a design-unbiased variance estimator, and near-zero pairs make it unstable.

\(^*\) Exact recursive formulas for Brewer's joint inclusion probabilities (Brewer 2002, ch. 9) are \(O(N^3)\), impractical beyond a few hundred units, whereas the high-entropy approximation is \(O(N^2)\). It assumes the design is close to the maximum-entropy design with the same marginal \(\pi_i\) (Hajek 1964; Brewer and Donadio 2003), which strong ordering, balancing or extreme probabilities can break, so validate variance and interval coverage for the intended design and population. SPS and Pareto also enter it with approximate first-order targets.

Bounded cube, LPM2, and SCPS designs are refused, because count constraints and spatial spreading alter pairwise selection beyond the approximation. variance_estimation gives their replicate variance.

A method registered with sondage::register_method() has the joint probabilities its joint_fn returns, and their accuracy is that of the function. A method registered without joint_fn is refused, and so is a registered method drawn with spread.

A stage that draws a certainty plan's zones treats each zone as a draw of its own, so PSUs of different zones have the product of their chances. It needs frame, since the digest does not record the zone mates of a selected PSU. A plan drawing one PSU per zone is refused (samplyr_error_joint_method_unsupported). Two PSUs of one zone are never drawn together, so no unbiased variance estimator can use its matrix.

WR/PMR methods (\(E(n_k \cdot n_l)\))

The matrices come from sondage::joint_expected_hits().

MethodQuality
pps_multinomialExact, analytic
pps_systematic_mrExact, analytic, zero pairs possible
pps_chromyApproximate, Monte Carlo, 10,000 draws
registeredFrom the method's joint_fn

For pps_multinomial, \(E(n_k \cdot n_l) = n(n-1) p_k p_l + n p_k \mathbf{1}_{k=l}\). The sequential dependence of pps_chromy admits no closed form for \(E(n_k \cdot n_l)\), so sondage estimates it by Monte Carlo simulation under nsim and seed.

pps_systematic_mr uses one random start, so its matrix follows from the overlap of the units' intervals on the cumulated sizes, in the order of the pool. Two units whose intervals are never covered by one random start have \(E(n_k \cdot n_l) = 0\). Such a pair is never in one sample, so the matrix of the sampled units does not show the zero. It still rules out a design-unbiased variance estimator from one sample, which is why the export treats the stage as drawn with replacement (variance_estimation).

Activation mode

A scheduled master assigned every unit to a panel at its draw and froze the block-by-panel quotas, so how two occasions of the rotation overlap is already determined. joint_expectation(master, period = , subround = ) reads it from the record for two occasions, t first and u second, with neither the frame nor a simulation.

Conditional on the frozen quotas, the panels inside a block of m assignment units are an arrangement of that block's labels. Writing \(a_t\) and \(a_u\) for the units the panels active at each occasion take from the block, and \(a_{tu}\) for those active at both:

$$P(i \in W_t) = a_t / m$$ $$P(i \in W_t, i \in W_u) = a_{tu} / m$$ $$P(i \in W_t, j \in W_u) = \frac{a_t a_u - a_{tu}}{m (m - 1)}$$

for units \(i \neq j\) of one block, and the product of the marginals for units of different blocks, whose arrangements are drawn independently. The within-occasion case is the third expression at t == u.

The result has one row per block and stays small at any sample size, yet every entry of the full matrix is recoverable from it, since within a block the joints take only two values. The conditional covariance kernel is block-diagonal, not the joint-probability matrix: across blocks the joint is \(p_i p_j\), generally not zero, while the covariance is zero.

pool, stratum, class and block identify the block, and period_t, subround_t, period_u and subround_u the two occasions, in the order given. units is \(m\). take_t and take_u are \(a_t\) and \(a_u\), and shared is \(a_{tu}\). prob_t and prob_u are the marginals. joint_same and joint_distinct are the two joint expectations, the conditional counterparts of what Tillé (2020, sec. 8.2.2) calls the longitudinal and the joint longitudinal inclusion probabilities. has_pair is FALSE for a block of one unit, where no distinct pair exists and joint_distinct is NA rather than zero.

Quotas are frequently unequal, because a pool that is not a multiple of the block size gives one block an extra unit, so they are read from the record rather than derived from the panel count. A certainty block is permanent and takes every unit at every occasion, which makes joint_distinct exactly one.

These are joint expectations of the activation indicators, conditional on the phase-1 units and the frozen quotas, not the unconditional joint inclusion probabilities of the two-phase design, which also carry the master's own pairwise term. How the two combine for a variance of change is not settled here. as_svydesign() exports an occasion for ordinary totals.

Activation mode takes a master, not a materialized occasion, so neither of the two occasions needs to have been materialized.

References

High-entropy approximation: Hájek, J. (1964). Asymptotic theory of rejective sampling with varying probabilities from a finite population. Annals of Mathematical Statistics, 35(4), 1491-1523.

Brewer, K.R.W. and Donadio, M.E. (2003). The high entropy variance of the Horvitz-Thompson estimator. Survey Methodology, 29(2), 189-196.

Exact conditional Poisson (CPS) joint probabilities: Aires, N. (1999). Algorithms to find exact inclusion probabilities for conditional Poisson sampling and Pareto \(\pi\)ps sampling designs. Methodology and Computing in Applied Probability, 1(4), 457-469. doi:10.1023/A:1010091628740

Exact Brewer joint probabilities: Brewer, K.R.W. (2002). Combined Survey Sampling Inference: Weighing Basu's Elephants. Arnold, ch. 9.

Occasions of a repeated survey: Tillé, Y. (2020). Sampling and Estimation from Finite Populations. Wiley, sec. 8.2.

The variance estimator these underlie: Berger, Y.G. (2004). A simple variance estimator for unequal probability sampling without replacement. Journal of Applied Statistics, 31(3), 305-315.

See also

as_svydesign() for the default export using Brewer's approximation, survey::ppsmat() for wrapping joint matrices

Other diagnostics: compare_designs(), design_effect, frame_summary(), summary.tbl_sample(), varcomp.tbl_sample()

Examples

# A single-stage stratified Sampford sample, whose joint matrix is exact
sample <- sampling_design() |>
  stratify_by(region) |>
  draw(n = 5, method = "pps_sampford", mos = households) |>
  execute(bfa_eas, seed = 2025)

jip <- joint_expectation(sample, bfa_eas)

# survey reads the matrix by row, one row per sampled unit, and YG selects
# the Sen-Yates-Grundy form for fixed-size sampling without replacement
svy <- as_svydesign(sample, pps = survey::ppsmat(jip[[1]]), variance = "YG")
survey::svytotal(~population, svy)
#>               total     SE
#> population 20854071 297150

# A CPS sample, also with an exact joint matrix, drawn from one register
# per stage passes the registers as a list
regions <- dplyr::distinct(bfa_eas, region, .keep_all = TRUE)
registers <- sampling_design() |>
  add_stage() |>
    cluster_by(region) |>
    draw(n = 3, method = "pps_cps", mos = households) |>
  add_stage() |>
    draw(n = 12) |>
  execute(regions, bfa_eas, seed = 2025)

jip_registers <- joint_expectation(registers, list(regions, bfa_eas))
# Activation mode: how far two occasions of a rotation overlap. Four
# panels rotate two at a time, so each is live for two consecutive occasions.
rotation <- data.frame(
  panel = rep(1:4, times = 4),
  period = rep(1:4, each = 4),
  active = c(
    TRUE, TRUE, FALSE, FALSE,
    FALSE, TRUE, TRUE, FALSE,
    FALSE, FALSE, TRUE, TRUE,
    TRUE, FALSE, FALSE, TRUE
  )
)

master <- sampling_design() |>
  draw(n = 40) |>
  execute(bfa_eas, seed = 2025, panels = rotation)

# Occasions 1 and 2 share one panel of the two each activates.
joint_expectation(master, period = c(1, 2))
#> # A tibble: 10 × 18
#>     pool stratum class  activation block period_t subround_t period_u subround_u
#>    <int> <chr>   <chr>  <chr>      <int>    <int>      <int>    <int>      <int>
#>  1     1 NA      rotat… rotating       1        1          1        2          1
#>  2     1 NA      rotat… rotating       2        1          1        2          1
#>  3     1 NA      rotat… rotating       3        1          1        2          1
#>  4     1 NA      rotat… rotating       4        1          1        2          1
#>  5     1 NA      rotat… rotating       5        1          1        2          1
#>  6     1 NA      rotat… rotating       6        1          1        2          1
#>  7     1 NA      rotat… rotating       7        1          1        2          1
#>  8     1 NA      rotat… rotating       8        1          1        2          1
#>  9     1 NA      rotat… rotating       9        1          1        2          1
#> 10     1 NA      rotat… rotating      10        1          1        2          1
#> # ℹ 9 more variables: units <int>, take_t <int>, take_u <int>, shared <int>,
#> #   prob_t <dbl>, prob_u <dbl>, joint_same <dbl>, joint_distinct <dbl>,
#> #   has_pair <lgl>

# The same occasion twice gives the joint expectation within one occasion.
joint_expectation(master, period = c(2, 2))
#> # A tibble: 10 × 18
#>     pool stratum class  activation block period_t subround_t period_u subround_u
#>    <int> <chr>   <chr>  <chr>      <int>    <int>      <int>    <int>      <int>
#>  1     1 NA      rotat… rotating       1        2          1        2          1
#>  2     1 NA      rotat… rotating       2        2          1        2          1
#>  3     1 NA      rotat… rotating       3        2          1        2          1
#>  4     1 NA      rotat… rotating       4        2          1        2          1
#>  5     1 NA      rotat… rotating       5        2          1        2          1
#>  6     1 NA      rotat… rotating       6        2          1        2          1
#>  7     1 NA      rotat… rotating       7        2          1        2          1
#>  8     1 NA      rotat… rotating       8        2          1        2          1
#>  9     1 NA      rotat… rotating       9        2          1        2          1
#> 10     1 NA      rotat… rotating      10        2          1        2          1
#> # ℹ 9 more variables: units <int>, take_t <int>, take_u <int>, shared <int>,
#> #   prob_t <dbl>, prob_u <dbl>, joint_same <dbl>, joint_distinct <dbl>,
#> #   has_pair <lgl>