Skip to main content

binsmooth - Better Estimates from Binned Income Data.

Project description

binsmooth

PyPI version Build Status

Python implementation of "Better Estimates from Binned Income Data"

Better Estimates from Binned Income Data: Interpolated CDFs and Mean-Matching
Paul T. von Hippel, David J. Hunter, McKalie Drown
Sociological Science
Volume 4, Number 26, Pages 641-655
2017

Originally implemented in the R package binsmooth.

Usage

from binsmooth import BinSmooth

bin_edges = np.array([0, 18200, 37000, 87000, 180000])
counts = np.array([0, 7527, 13797, 75481, 50646, 803])
mean_estimate = 95000

bs = BinSmooth()
bs.fit(bin_edges, counts, m=mean_estimate)

# Print median estimate
print(bs.inv_cdf(0.5))

Installation

Install via pip

pip install binsmooth

pypi page https://pypi.org/project/binsmooth/

Improvements

Better tail estimate by bounded optimisation rather than the adhoc search method found in the R implementation.

More precise inverse CDF by dynamically sampling the CDF. This is done by sampling proportional to the steepness of the CDF i.e. sampling more in areas where the CDF is steeper.

Warnings

Results may not exactly match R binsmooth because of a different approach to estimating the tail (upper bound).

Furthermore the fit method uses spline_type="PCHIP" by default, which is scipy's PchipInterpolator [1]. While the R implementation uses the spline from [2], which can be mimicked by setting spline_type="HYMAN".

References

[1]: Fritsch, F. N. and Carlson, R. E. (1980). Monotone piecewise cubic interpolation. SIAM Journal on Numerical Analysis
[2]: Hyman, J. M. (1983). Accurate monotonicity preserving cubic interpolation. SIAM Journal on Scientific and Statistical Computing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binsmooth-2023.10.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

binsmooth-2023.10.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file binsmooth-2023.10.0.tar.gz.

File metadata

  • Download URL: binsmooth-2023.10.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for binsmooth-2023.10.0.tar.gz
Algorithm Hash digest
SHA256 87b046a90363e6e138152824216c549b2995cae76f2b8375403457846194dfa3
MD5 5d1b12846e491cebe41c801fec3cc758
BLAKE2b-256 59712374052457a5f733c74bc608775f6475ff3911e9d4051e726d0f5773c4fc

See more details on using hashes here.

File details

Details for the file binsmooth-2023.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for binsmooth-2023.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 076b6689bd477b2843e2aee13d4b48c6b30523f9f4e64b9b78a4c8c53837ed24
MD5 fc663a62d05c672c33c2a877a0fa0183
BLAKE2b-256 f8ab781072682f65083baa2f99ce8da109ba5338788a52aea7f62367b5a3fb32

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page