binsmooth - Better Estimates from Binned Income Data.
Project description
binsmooth
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])
bs = BinSmooth()
bs.fit(bin_edges, counts)
# 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="HYMAN"
as a default, which is
scipy's PchipInterpolator
[1]. While the R implementation uses the spline
from [2], which can be mimiced 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
Built Distribution
File details
Details for the file binsmooth-2023.9.0.tar.gz
.
File metadata
- Download URL: binsmooth-2023.9.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62c720c584da4e67ef077302153be57d29e94fa851a44d2beac8f6a2e6d73f9f |
|
MD5 | 84fb2a3003ee163701017fa2099a6485 |
|
BLAKE2b-256 | 4a3870cce139e7f75ad96e714fe8d971d2e76ac39872eac415d624fbe8a446a8 |
File details
Details for the file binsmooth-2023.9.0-py3-none-any.whl
.
File metadata
- Download URL: binsmooth-2023.9.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b67f83d42460f68ab6ec98fb6a6b37717f62e8fdc6947bdfeff7d42d91b47dba |
|
MD5 | 6865cc35a4e08a418ae71f983a623658 |
|
BLAKE2b-256 | 5dcd90526fbd36f146d82cb7736d2242a198ff775b3a8b77c17e6968fafdb54e |