forked from ChrisBeaumont/beaumont-idl-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edf.pro
55 lines (49 loc) · 1.3 KB
/
edf.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
46
47
48
49
50
51
52
53
54
55
;+
; PURPOSE:
; This procedure calculates the empirical distribution function (edf)
; of a set of data, evaluated at each input data point. The edf is
; the empirical equivalent of the cumulative distribution function.
;
; CATEGORY:
; Statistics
;
; CALLING SEQUENCE:
; edf, data, x, y, [/plot, _extra = extra]
;
; INPUTS:
; data: A vector of data values
;
; KEYWORD PARAMETERS:
; PLOT: Set to plot the results.
; _extra: Any extra kewyord passed to edf is forwarded to PLOT
;
; OPTIONAL OUTPUTS:
; x: On output, the variable holds the values of data, in numerical order
; y: On output, the variable holds a vector. y[i] = Fraction(data < x)
;
; MODIFICATION HISTORY:
; June 2009: Written by Chris Beaumont
;-
pro edf, data, x, y, plot = plot, _extra = extra
compile_opt idl2
on_error, 2
;- check inputs
if n_params() lt 1 then begin
print, 'edf calling sequence'
print, 'edf, data, x, y, [/plot, plot_keywords]'
return
endif
if n_elements(data) le 1 then $
message, 'input data must have at least 2 elements'
fin = where(finite(data),sz)
if sz lt 5 then $
message, 'input data must have at least 5 finite elements'
fin = data[fin]
s = sort(fin)
x = fin[s]
y = (findgen(sz)) / sz
if keyword_set(plot) then begin
plot, x, y, xtit = 'X', ytit = 'EDF(x)', psym = 10, _extra = extra
endif
return
end