Class: Rsquared::TTest

Inherits:
StatTest show all
Defined in:
lib/Rsquared/TTest.rb

Overview

Tests for deviation of sample mean from expected mean ttest = Rsquared::TTest.new(data, mu0, sided) mu0 is the expected value of the sample mean Supply Rsquared::Upper.tail, Rsquared::Lower.tail or Rsquared::Two.sided Use Upper.tail when you suspect that the sample mean will be greater than the expected mean Use Lower.tail when you suspect that the sample mean will be smaller than the expected mean Use Two.sided when you suspect neither

Instance Attribute Summary

Attributes inherited from StatTest

#pvalue

Instance Method Summary collapse

Methods inherited from StatTest

#inspect, #setSidedness!, #significant?

Constructor Details

#initialize(data, mu0, sided) ⇒ TTest

Initializes the TTest object with the supplied arguments



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/Rsquared/TTest.rb', line 16

def initialize(data, mu0, sided)
   @data = data
	    @mu0 = mu0
   @sided = sided
   
   if KSTest.new(@data).significant? and @data.length < 40 then
      raise AssumptionError, "The data is not close enough to a normal distribution for such a small sample size"
   end
   if GrubbsTest.new(@data).outlier? then
      raise AssumptionError, "Your data has one or more outliers, which the T-Distribution cannot handle"
   end

   @tstat = (@data.mean - @mu0)/(data.stddev/Math.sqrt(@data.length))
   @pvalue = Distribution::T::cdf(@tstat, @data.length-1)
   self.setSidedness!(@sided)
end

Instance Method Details

#statisticObject

Returns the t-statistic



37
38
39
# File 'lib/Rsquared/TTest.rb', line 37

def statistic
    @tstat
end