class Rsquared::KSTest

KSTest implements the Kolomogorov-Smirnov test for normality kstest = Rsquared::KSTest.new(data) kstest.normal? => Boolean, indicates normality of data at 5% confidence

Public Class Methods

new(data) click to toggle source

Intitializes the test object with an array of numerical data

# 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

Public Instance Methods

inspect() click to toggle source
# File lib/Rsquared/KSTest.rb, line 48
def inspect
    significant?
end
normal?() click to toggle source

Returns logical opposite of significance

# File lib/Rsquared/KSTest.rb, line 44
def normal?
    !self.significant?
end
significant?() click to toggle source

Returns a boolean indiciating the significance of the test a the 5% level

# File lib/Rsquared/KSTest.rb, line 32
def significant?
    if @ksstat > Helper::kscv(@data.length) then
      return true
    else
       return false
    end
end
statistic() click to toggle source

Returns the test statistic

# File lib/Rsquared/KSTest.rb, line 56
def statistic
    @ksstat
end