Class: Statsample::Test::KolmogorovSmirnov
- Includes:
- Summarizable, Statsample::Test
- Defined in:
- lib/statsample/test/kolmogorovsmirnov.rb
Overview
Kolmogorov-Smirnov’s test of equality of distributions.
Defined Under Namespace
Classes: EmpiricDistribution
Instance Attribute Summary collapse
-
#d ⇒ Object
readonly
Returns the value of attribute d.
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(d1, d2) ⇒ KolmogorovSmirnov
constructor
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.
-
#make_cdf(v) ⇒ Object
Make a wrapper EmpiricDistribution to any method which implements each on Statsample::Vector, only uses non-missing data.
Methods included from Summarizable
Methods included from Statsample::Test
chi_square, levene, #p_using_cdf, #t_critical, t_one_sample, t_two_samples_independent, u_mannwhitney, wilcoxon_signed_rank, #z_critical
Constructor Details
#initialize(d1, d2) ⇒ KolmogorovSmirnov
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
13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |
Instance Attribute Details
#d ⇒ Object (readonly)
Returns the value of attribute d.
6 7 8 |
# File 'lib/statsample/test/kolmogorovsmirnov.rb', line 6 def d @d end |
Instance Method Details
#calculate ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/statsample/test/kolmogorovsmirnov.rb', line 26 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) ⇒ Object
Make a wrapper EmpiricDistribution to any method which implements each on Statsample::Vector, only uses non-missing data.
38 39 40 |
# File 'lib/statsample/test/kolmogorovsmirnov.rb', line 38 def make_cdf(v) v.is_a?(Daru::Vector) ? EmpiricDistribution.new(v.only_valid.to_a) : EmpiricDistribution.new(v) end |