Class: Rsquared::GrubbsTest

Inherits:
Object
  • Object
show all
Defined in:
lib/Rsquared/GrubbsTest.rb

Overview

Tests for outliers on either side of the data grubbs = Rsquared::GrubbsTest.new(data) grubbs.significant? => Boolean

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ GrubbsTest

Initializes the Test object with an array of numerical data



13
14
15
16
# File 'lib/Rsquared/GrubbsTest.rb', line 13

def initialize(data)
   @data = data.sort
	     @gstat = [((@data.mean - @data.min)/@data.stddev).abs, ((@data.mean - @data.max)/@data.stddev).abs].max
end

Instance Method Details

#inspectObject



30
31
32
# File 'lib/Rsquared/GrubbsTest.rb', line 30

def inspect
    significant?
end

#significant?(alpha = 0.05) ⇒ Boolean Also known as: outlier?

Returns a boolean indicating the significance of the test at the 5% level

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/Rsquared/GrubbsTest.rb', line 22

def significant?(alpha=0.05)
   if @gstat > Helper::grubbscv(@data.length, alpha) then
   	return true
   else
		return false
   end
end

#statisticObject

Returns the test statistic as a float



38
39
40
# File 'lib/Rsquared/GrubbsTest.rb', line 38

def statistic
    @gstat
end