Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#getChiSqrScore(countNew, totalNew, countOld, totalOld) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fluent/plugin/log-likelihood.rb', line 4

def getChiSqrScore (countNew,totalNew,countOld,totalOld)
  
  countNew = countNew.to_f
  countOld = countOld.to_f
  totalNew = totalNew.to_f
  totalOld = totalOld.to_f
  
  
  
  p = countNew/ totalNew
  q = countOld / totalOld
  
  if ( p < q )
    return 0
  end
  
  t = (countNew + countOld) / (totalOld + totalNew)
  
  if ( t == 0)
     return nil
  end
  
  v = countNew * Math::log(p/t) + countOld  * Math::log(q/t)
  
  if ( t == 1 )
    return Statistics2..chi2X_(1,2*v)
  end
  
  if ( p < 1)
    v = v + ((totalNew - countNew) * Math::log((1-p)/(1-t)))
  end
  
  if ( q < 1)
    v = v + ((totalOld - countOld) * Math::log((1-q)/(1-t)))
  end

  return Statistics2.chi2X_(1,2*v)
  
end