Created
April 8, 2015 17:56
-
-
Save mprymek/09fc63173da26fba8ea0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make inverse fuction for SciPy's ECDF | |
import numpy as np | |
import statsmodels as sm | |
import scipy as sp | |
num_samples = 1000 | |
values = np.random.randn(num_samples) | |
ecdf = sm.distributions.ECDF(values) | |
ecdf_i = sp.interpolate.interp1d(ecdf.y,ecdf.x) | |
quant1 = 0.7 | |
val1 = np.percentile(values,quant1*100) | |
quant2 = ecdf(val1) | |
val2 = ecdf_i(quant2) | |
print "quantile %s ~ value %s ~ quantile %s ~ value %s\n"%(quant1,val1,quant2,val2) | |
print "quantile error: %s"%(quant2-quant1) | |
print "value error: %s"%(val1-val2) | |
### sample output: | |
# quantile 0.7 ~ value 0.507576803872 ~ quantile 0.7 ~ value 0.507447104053 | |
# | |
# quantile error: 1.11022302463e-16 | |
# value error: 0.000129699818594 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment