Skip to main content

chromy_core/
lib.rs

1//! Chromy's method of sequential random sampling, as a library.
2//!
3//! Chromy (1979) selects units one at a time down an ordered list, each with
4//! probability proportional to its size, so that the realised hits of every
5//! unit differ from its expected hits by less than one — *probability
6//! minimum replacement*. The procedure is the backbone of many large
7//! establishment and household surveys, and of `PROC SURVEYSELECT
8//! METHOD=PPS_SEQ`; until now it lived only inside proprietary software and
9//! one Stata module. This crate is the method in the open, with the
10//! apparatus that surrounds it in practice:
11//!
12//! - [`pmr`]: the sequential selection itself, deterministic given the
13//!   uniforms, with compensated summation and an explicit account of every
14//!   floating-point adjustment it had to make;
15//! - [`serpentine`] and [`nested`]: hierarchical sorting of the frame, so
16//!   that neighbouring units are alike and the systematic character of the
17//!   selection buys variance;
18//! - [`mpps`]: a maximal size measure over several auxiliary variables, for
19//!   surveys that must serve more than one estimate;
20//! - [`expected_hits`] and [`eqcv`]: from sizes to expected hits, with
21//!   certainty units resolved by iteration, and the allocation that
22//!   equalises anticipated coefficients of variation across variables;
23//! - [`select`] / [`select_from`]: the full procedure with a random head,
24//!   as SAS runs it;
25//! - [`multiplicity_estimate`]: the estimator that matches the design, with
26//!   the successive-difference variance;
27//! - [`joint_inclusion`]: exact second-order inclusion probabilities for
28//!   the without-replacement design, by the closed forms of Chauvet and
29//!   Le Gleut's Theorem 3 and their randomized-head mixture — the
30//!   Sen–Yates–Grundy variance becomes exact, not approximated.
31//!
32//! The crate has no dependencies and takes its randomness as arguments —
33//! a slice of uniforms — so a caller in R, Python or Rust reproduces a
34//! selection exactly from its own generator and seed. The reference for
35//! every numerical choice is the implementation these functions were
36//! distilled from, tested bit for bit in `tests/golden.rs`.
37//!
38//! Chromy, J. R. (1979). Sequential sample selection methods. *Proceedings
39//! of the American Statistical Association, Survey Research Methods
40//! Section*, 401–406. Chauvet, G. and Le Gleut, R. (2021). Properties of
41//! Chromy's sampling procedure. *Survey Methodology* 47(2).
42
43mod allocate;
44mod error;
45mod estimate;
46mod joint;
47mod order;
48mod pmr;
49mod select;
50mod size;
51
52pub use allocate::{eqcv, expected_hits, EqcvAllocation, EqcvOptions};
53pub use error::Error;
54pub use estimate::{multiplicity_estimate, Estimate};
55pub use joint::joint_inclusion;
56pub use order::{nested, serpentine, Key};
57pub use pmr::{pmr, Selection};
58pub use select::{
59    eligible_positions, head_position, required_uniforms, select, select_from, Head, Selected,
60};
61pub use size::mpps;