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 using scipy's fmin to perform automatic 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 more densely in areas where the CDF is steeper and less in flatter areas, rather than evenly spaced sampling.
Warnings
Results will be different to the original R implementation due to differences in spline implementation between R's splinefun and scipy's PchipInterpolator.
Accuracy is highly 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.
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.12.tar.gz
.
File metadata
- Download URL: binsmooth-0.12.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8116bf77cf1a1fdd1cffd1756f0340516abe46ffa128a18ad4cacfce7b1f911 |
|
MD5 | 89f6e4c562686bc78142f9f31a827655 |
|
BLAKE2b-256 | 268f460e577316dfaf9fe744c03256fe45deb0009ed2665b33325b66e70170ef |
File details
Details for the file binsmooth-0.12-py2.py3-none-any.whl
.
File metadata
- Download URL: binsmooth-0.12-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a119ab40c56510d2e9b31037def62a1cff6d81f6244ad54bcac4bc2fa3003f1d |
|
MD5 | 9062fd0cd7fadc87e7ef53cf95c6802d |
|
BLAKE2b-256 | a6341f3eaab943da59f5144841a20dae916e419aecd5fa3b95417d55e229b151 |