Class: Rsquared::KSTest
- Inherits:
-
Object
- Object
- Rsquared::KSTest
- Defined in:
- lib/Rsquared/KSTest.rb
Overview
KSTest implements the Kolomogorov-Smirnov test for normality kstest = Rsquared::KSTest.new(data) kstest.normal? => Boolean, indicates normality of data at 5% confidence
Instance Method Summary collapse
-
#initialize(data) ⇒ KSTest
constructor
Intitializes the test object with an array of numerical data.
- #inspect ⇒ Object
-
#normal? ⇒ Boolean
Returns logical opposite of significance.
-
#significant? ⇒ Boolean
Returns a boolean indiciating the significance of the test a the 5% level.
-
#statistic ⇒ Object
Returns the test statistic.
Constructor Details
#initialize(data) ⇒ KSTest
Intitializes the test object with an array of numerical data
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/Rsquared/KSTest.rb', line 13 def initialize(data) @data = data.std.sort! fn = 0 d = [] range = @data.max - @data.min @data.each_with_index do |x, i| # Calculate Fn fn = i + 1 d[i] = fn/@data.length.to_f - Distribution::Normal::cdf(x) fn = 0.0 end @ksstat = d.max return @ksstat end |
Instance Method Details
#inspect ⇒ Object
48 49 50 |
# File 'lib/Rsquared/KSTest.rb', line 48 def inspect significant? end |
#normal? ⇒ Boolean
Returns logical opposite of significance
44 45 46 |
# File 'lib/Rsquared/KSTest.rb', line 44 def normal? !self.significant? end |
#significant? ⇒ Boolean
Returns a boolean indiciating the significance of the test a the 5% level
32 33 34 35 36 37 38 |
# File 'lib/Rsquared/KSTest.rb', line 32 def significant? if @ksstat > Helper::kscv(@data.length) then return true else return false end end |
#statistic ⇒ Object
Returns the test statistic
56 57 58 |
# File 'lib/Rsquared/KSTest.rb', line 56 def statistic @ksstat end |