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
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 do not exactly match R binsmooth
because:
- we take a different approach to estimating the tail (upper bound)
- choice of spline interpolation
This implementation uses scipy's PchipInterpolator
which implements [1],
while the default interpolator in the R implementation is [2]. The interpolator
in the R implementation can be changed to [1] by setting monoMethod="monoH.FC"
.
Accuracy is dependent on the mean of the distribution. If you do not supply a mean, then one will be estimated in an adhoc manner and the accuracy of estimates may be poor.
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-0.14.tar.gz
.
File metadata
- Download URL: binsmooth-0.14.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0583cbf5973ea677f0f67a15afff20a9ce6f6ced317a059197d8254fbc31c89b |
|
MD5 | 6dc8ec1ae06b467e8940a684c39f20b2 |
|
BLAKE2b-256 | 3823fe25cd2af8941bac41e7fe0196e5b58c619c2fe8c2626a4dc0432a6b7ec7 |
File details
Details for the file binsmooth-0.14-py2.py3-none-any.whl
.
File metadata
- Download URL: binsmooth-0.14-py2.py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31d67a97fef208ac399f0f3a7a20284133bb6454e28964c8dd3800cc0323526a |
|
MD5 | c10a5537669de98df674d20df3b9125a |
|
BLAKE2b-256 | db63b6a4e1bfa9a54bb8278128cda5bb5919e931f9883b2ab19147b4e74f136d |