Module: Fisher

Defined in:
lib/rbbt/statistics/fisher.rb

Class Method Summary collapse

Class Method Details

.test_classification(classes1, classes2, alternative = 'greater') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rbbt/statistics/fisher.rb', line 5

def self.test_classification(classes1, classes2, alternative='greater')
  matrix = [0,0,0,0]
  classes1.each_with_index do |c1,i|
    c2 = classes2[i]
    if c1 == 1 and c2 == 1
      matrix[0] += 1
    elsif c1 == 0 and c2 == 1
      matrix[1] += 1
    elsif c1 == 1 and c2 == 0
      matrix[2] += 1
    else
      matrix[3] += 1
    end
  end
  R.eval("fisher.test(matrix(#{R.ruby2R matrix}, nrow=2), alternative = #{R.ruby2R alternative})$p.value")
end