class Statsample::Test::KolmogorovSmirnov
Kolmogorov-Smirnov's test of equality of distributions.¶ ↑
Kolmogorov-Smirnov's test of equality of distributions.¶ ↑
Attributes
d[R]
Public Class Methods
new(d1,d2)
click to toggle source
Creates a new Kolmogorov-Smirnov test d1 should have each method d2 could be a Distribution class, with a cdf method, a vector or a lambda
# File lib/statsample/test/kolmogorovsmirnov.rb, line 13 def initialize(d1,d2) raise "First argument should have each method" unless d1.respond_to? :each @d1=make_cdf(d1) if d2.respond_to? :cdf or d2.is_a? Proc @d2=d2 elsif d2.respond_to? :each @d2=make_cdf(d2) else raise "Second argument should respond to cdf or each" end calculate end
Public Instance Methods
calculate()
click to toggle source
# File lib/statsample/test/kolmogorovsmirnov.rb, line 25 def calculate d=0 @d1.each {|x| v1=@d1.cdf(x); v2=@d2.is_a?(Proc) ? @d2.call(x) : @d2.cdf(x) d=(v1-v2).to_f.abs if (v1-v2).abs>d } @d=d end
make_cdf(v)
click to toggle source
Make a wrapper EmpiricDistribution to any method which implements each On Statsample::Vector, only uses valid_data
# File lib/statsample/test/kolmogorovsmirnov.rb, line 37 def make_cdf(v) v.is_a?(Statsample::Vector) ? EmpiricDistribution.new(v.valid_data) : EmpiricDistribution.new(v) end