[Scipy-tickets] [SciPy] #74: Statistics Review: percentileofscore

SciPy scipy-tickets at scipy.net
Tue Dec 5 09:09:05 CST 2006


#74: Statistics Review: percentileofscore
-------------------------+--------------------------------------------------
 Reporter:  rkern        |        Owner:  rkern                   
     Type:  review       |       Status:  assigned                
 Priority:  normal       |    Milestone:  Statistics Review Months
Component:  scipy.stats  |      Version:  devel                   
 Severity:  normal       |   Resolution:                          
 Keywords:               |  
-------------------------+--------------------------------------------------
Comment (by dhuard):

 Here is a fix
 {{{
 def percentileofscore(data, score):
     """Percentile-position of score relative to data.

     score: Array of scores at which the percentile is computed.

     Return percentiles (0-100).

     Example
         x = linspace(-2,2,100)
         percentileofscore(randn(50),x)

     Return an error if the score is outside the range of data.
     """
     cdf = empiricalcdf(data)
     interpolator = interpolate.interp1d(sort(data), sort(cdf))
     return interpolator(score)*100.

 def empiricalcdf(data, method='Hazen'):
     """Compute the empirical cdf using one method among:
     Weibull:     i/(N+1)
     Hazen:       (i-0.5)/N
     Chegodayev:  (i-.3)/(N+.4)
     Cunnane:     (i-.4)/(N+.2)
     Gringorten:  (i-.44)/(N+.12)
     California:  (i-1)/N

     Where i goes from 1 to N.
     Return cdf computed at data.
     """

     i = argsort(argsort(data)) + 1.
     N = len(data)

     if method == 'Weibull':
         cdf = i/(N+1)
     elif method == 'Hazen':
         cdf = (i-0.5)/N
     elif method == 'California':
         cdf = (i-1)/N
     elif method == 'Chegodayev':
         cdf = (i-.3)/(N+.4)
     elif method == 'Cunnane':
         cdf = (i-.4)/(N+.2)
     elif method == 'Gringorten':
         cdf = (i-.44)/(N+.12)
     else:
         raise 'Unknown method. Choose among Weibull, Hazen, Chegodayev,
 Cunnane, Gringorten and California.'

     return cdf
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/scipy/ticket/74#comment:3>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list