Class: Statsample::Test::KolmogorovSmirnov::EmpiricDistribution

Inherits:
Object
  • Object
show all
Defined in:
lib/statsample/test/kolmogorovsmirnov.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ EmpiricDistribution

Returns a new instance of EmpiricDistribution.



43
44
45
46
47
48
# File 'lib/statsample/test/kolmogorovsmirnov.rb', line 43

def initialize(data)
  @min=data.min
  @max=data.max
  @data=data.sort
  @n=data.size
end

Instance Method Details

#cdf(x) ⇒ Object



54
55
56
57
58
59
# File 'lib/statsample/test/kolmogorovsmirnov.rb', line 54

def cdf(x)
  return 0 if x<@min
  return 1 if x>=@max
  v=@data.index{|v1| v1>=x}
  v.nil? ? 0 : (v+(x==@data[v]? 1 : 0)).quo(@n)
end

#eachObject



49
50
51
52
53
# File 'lib/statsample/test/kolmogorovsmirnov.rb', line 49

def each
  @data.each {|x|
    yield x
  }
end