diff options
Diffstat (limited to 'report/statistical_test.rb')
-rw-r--r-- | report/statistical_test.rb | 49 |
1 files changed, 3 insertions, 46 deletions
diff --git a/report/statistical_test.rb b/report/statistical_test.rb index 8d6bd62..da46f6b 100644 --- a/report/statistical_test.rb +++ b/report/statistical_test.rb @@ -1,38 +1,6 @@ #require "rubygems" #require "rinruby" -module LIB - class StatisticalTest - - # -1 -> array1 < array2 - # 0 -> not difference - # 1 -> array2 > array1 - # - def self.pairedTTest(array1, array2, significance_level=0.95) - - @@r = RinRuby.new(true,false) unless defined?(@@r) and @@r - @@r.assign "v1",array1 - @@r.assign "v2",array2 - @@r.eval "ttest = t.test(v1,v2,paired=T)" - t = @@r.pull "ttest$statistic" - p = @@r.pull "ttest$p.value" - if (1-significance_level > p) - t - else - 0 - end - end - - def self.quit_r - begin - @@r.quit - @@r = nil - rescue - end - end - end -end - module Reports class ReportStatisticalTest @@ -69,26 +37,15 @@ module Reports def self.paired_ttest( validations1, validations2, attribute, class_value, significance_level=0.95 ) - array1 = validations1.collect{ |v| (v.send(attribute).is_a?(Hash) ? v.send(attribute)[class_value] : v.send(attribute)) } - array2 = validations2.collect{ |v| (v.send(attribute).is_a?(Hash) ? v.send(attribute)[class_value] : v.send(attribute)) } + array1 = validations1.collect{ |v| (v.send(attribute).is_a?(Hash) ? v.send(attribute)[class_value].to_f : v.send(attribute).to_f) } + array2 = validations2.collect{ |v| (v.send(attribute).is_a?(Hash) ? v.send(attribute)[class_value].to_f : v.send(attribute).to_f) } LOGGER.debug "paired-t-testing "+attribute.to_s+" "+array1.inspect+" vs "+array2.inspect - LIB::StatisticalTest.pairedTTest(array1, array2, significance_level) + Reports::r_util.paired_ttest(array1, array2, significance_level) end - def self.quit_r - LIB::StatisticalTest.quit_r - end - end end -#t1 = Time.new -#10.times do -# puts LIB::StatisticalTest.pairedTTest([1,2,3,4,5,12,4,2],[2,3,3,3,56,3,4,5]) -#end -#LIB::StatisticalTest.quitR -#t2 = Time.new -#puts t2-t1 |