Skip to main content

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.

Install

From PyPI (after release):

pip install bethel

From source:

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 at N

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>

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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bethel 0.2.0
File Size Uploaded Provenance Actions
bethel-0.2.0.tar.gz 16.2 kB Without provenance Details for bethel-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bethel 0.2.0
File Interpreter ABI Platform Actions
bethel-0.2.0-py3-none-any.whl Python 3 none any Details for bethel-0.2.0-py3-none-any.whl

Total release size: 30.3 kB

Release files / bethel-0.2.0.tar.gz

Download URL bethel-0.2.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
40b6292510ae28954547292494163eb928df4d91e9020e732b98ef17b5259096
BLAKE2b-256 checksum
How to use checksums
984ede2aa71e1bd68feaf96f4584fb07a477cd6c964fa1b049d8ad2a68bc6ed5
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.0-py3-none-any.whl

Download URL bethel-0.2.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
698e1e4bf4ce42edd52005babe380d88d655b30f7cfbd82c73028a41bbe568b3
BLAKE2b-256 checksum
How to use checksums
4c510dbbdf48df59977c57542b54be11c8bb9fe8f18ff40d0399c918af5bfb68
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.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page