bethel
Python port of the CRAN R package bethel: sample size and allocation according to Bethel's procedure (1989) for multivariate stratified surveys.
Minimizes survey costs under coefficient-of-variation (CV) constraints on several target estimates.
Links
| Resource | URL |
|---|---|
| PyPI | https://pypi.org/project/bethel/ |
| GitHub | https://github.com/micheledemeo/bethel |
| R package (CRAN) | https://cran.r-project.org/package=bethel |
| Tutorial notebook | notebooks/bethel.ipynb |
Install
pip install bethel
From source:
git clone https://github.com/micheledemeo/bethel.git
cd bethel
pip install -e .
Examples
The worked example from the CRAN R package help page (?bth) is in
notebooks/bethel.ipynb: dataset pop, variables
income, books, sportDays, same parameters and expected results as R.
pip install -e ".[notebook]"
jupyter notebook notebooks/bethel.ipynb
Minimal usage:
from bethel import bth, load_pop, prepare_strata, prepare_targets
pop = load_pop()
var_cols = ["income", "books", "sportDays"]
strata = prepare_strata(pop, "strata", var_cols, cost=1, min_sample=3, min_rate=0.04)
targets = prepare_targets(pop, var_cols, cv=0.05)
bth(strata, targets)
API
| Function | Role |
|---|---|
bth(strata, targets, eps=1e-10) |
Core Bethel allocation (same role as R bth) |
prepare_strata(...) |
Build strata from a unit-level population |
prepare_targets(...) |
Build targets (CV + totals) |
load_pop() |
Example population (1000 rows) |
Input strata
| Column | Content |
|---|---|
strata |
Stratum label |
var_* |
Estimated variances of the target variables |
population_size |
Population size N |
cost |
Unit cost per interview |
min_sample |
Absolute minimum sample size |
min_rate |
Minimum sampling rate |
Input targets
| Column | Content |
|---|---|
cv |
Target coefficient of variation |
total |
Estimated population total |
One row in targets is required for each variance column in strata.
Output
bethel_sample— continuous Bethel solution (ceiling)adjusted_sample— after minimum constraints and cap atN
Citation
If you use this software, please cite the method and the package:
@article{bethel1989,
author = {Bethel, James W.},
title = {Sample Allocation in Multivariate Surveys},
journal = {Survey Methodology},
volume = {15},
pages = {47--57},
year = {1989}
}
@software{bethel_py,
author = {De Meo, Michele},
title = {bethel: Bethel's algorithm for multivariate stratified surveys (Python)},
year = {2026},
url = {https://pypi.org/project/bethel/},
note = {Python port of the CRAN R package bethel}
}
References
- Bethel, J.W. (1989). Sample Allocation in Multivariate Surveys. Survey Methodology, 15, 47–57.
- Chromy, J.B. (1987). Design Optimization With Multiple Objectives. ASA Survey Research Methods, 194–199.
Author
Michele De Meo <micheledemeo@gmail.com>
Author of the original R package on CRAN.
License
GPL (≥ 2), same as the R package.
R-to-Python migration with a little help from LLMs. Bethel's algorithm (1989) is all his; the Python port had some AI assistance.
Metadata
Release files for bethel 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bethel-0.2.1.tar.gz | 17.2 kB | Without provenance | Details for bethel-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bethel-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for bethel-0.2.1-py3-none-any.whl |
Total release size: 31.7 kB
Release files / bethel-0.2.1.tar.gz
| Download URL | bethel-0.2.1.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2bd81fbdc940ed47bfff666966b0f422177c2bee7a38378bfdaee0442f3bef6
|
|
BLAKE2b-256 checksum How to use checksums |
317680306a71bd076a799d827d5eec906f4cf7144ccb2713ec96b3f493adc0fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / bethel-0.2.1-py3-none-any.whl
| Download URL | bethel-0.2.1-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a0fea9c0d47a403c52301af17a8e69fed20c7affebd7c202a21051ef2fc058f
|
|
BLAKE2b-256 checksum How to use checksums |
721624c202f1b1c90a7a5a1f4a77cb17c52dd63eb1957b1a997fcd716769a31a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for bethel 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.