Design-based survey estimation with weights as the interface.
designweights is a Python library for estimating finite-population
parameters from survey data. It is built for survey methodologists at
national statistical offices and research organizations, and for anyone
who needs design-based inference that they can read, check, and trust.
The design thesis is in the name. An estimator is a function of the data and a weight vector. Everything that accounts for the sampling design, for nonresponse, or for known population totals does its work by transforming the weights. Variance estimation is the same estimator applied to replicate weights. One idea, carried all the way through.
Status: version 0. The library is pre-alpha. The API below is a seed for review, not a stable surface. Follow the roadmap to see what lands next.
import designweights as dw
# Estimates are plain functions of data and weights.
total = dw.total(y, weights=w)
mean = dw.mean(y, weights=w)
rate = dw.ratio(y, x, weights=w)Install from source while the library is pre-release:
pip install git+https://github.com/hananather/designweights- Plain data between layers. Functions take and return NumPy arrays and small frozen dataclasses. No framework, no global state, no hidden caches. Every intermediate quantity can be inspected.
- Weights are the interface. Design, nonresponse, follow-up, and calibration adjustments transform weights. Estimators never change.
- Formulas are readable against the literature. Each function computes one estimator and its docstring states the formula and the reference.
- Randomness is named. Every draw comes from a named stream, so any replication reruns alone and parallel equals serial.
- Exactness is tested, not asserted. Closed forms against brute-force enumeration, replicate variances against analytic ones, unbiasedness in Monte Carlo.
The near-term arc, in order: a Sample object carrying design information,
a Weights object carrying replicate weights through a weighting pipeline,
statistic-agnostic replication variance, calibration, and model-assisted
estimation that composes with scikit-learn learners. Later: conformal
prediction for finite-population inference. The full picture is in the
roadmap.
The documentation lives at hananather.github.io/designweights.
Contributions are welcome, and the bar is quality over volume. Read CONTRIBUTING.md for the development setup, the testing rules, and how pull requests are reviewed.
BSD 3-Clause, the license family of NumPy, pandas, and scikit-learn.