-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpercentiles.pro
46 lines (41 loc) · 1.04 KB
/
percentiles.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;+
; NAME:
; PERCENTILES
;
; PURPOSE:
; Determines what range of a distribution lies within a percentile range.
;
; CATEGORY:
; Math
;
; CALLING SEQUENCE:
; Result = PERCENTILES(Values)
;
; INPUTS:
; Values: Array containing the distribution.
;
; KEYWORD PARAMETERS:
; CONFLIMIT: The fraction of the distribution encompassed. Default: 0.68
;
; OUTPUTS:
; A 2-element vector of values that encompass a fraction CONFLIMIT
; of the distribution. For example, if CONFLIMIT=0.68 then Result gives
; the 16th and 85th percentiles.
;
; EXAMPLE:
; IDL> a = 0.01*FINDGEN(101)
; IDL> PRINT, PERCENTILES(a, CONFLIMIT=0.8)
; 0.1000000 0.900000
;
; MODIFICATION HISTORY:
; Written by: Jeremy Bailin
; 12 June 2008 Public release in JBIU
;-
function percentiles, values, conflimit=conflimit
n = n_elements(values)
if n_elements(conflimit) eq 0 then conflimit=0.68
lowindex = long(((1.0-conflimit)/2)*n)
highindex = n-lowindex-1
sortvalues = values[sort(values)]
return, [sortvalues[lowindex],sortvalues[highindex]]
end