Excel用の関数(VBA)*1
Public Function LogLikelihood(ByVal target As Long, comparison As Long, targetTotal As Long, comparisonTotal As Long) As Variant
a = target
b = comparison
c = targetTotal - a
d = comparisonTotal - b
If a = 0 Then aLNa = 0 Else aLNa = a * LN(a)
If b = 0 Then bLNb = 0 Else bLNb = b * LN(b)
LNLikelihood = 2 * (aLNa + bLNb + c * LN(c) + d * LN(d) - (a + b) * LN(a + b) - (a + c) * LN(a + c) - (b + d) * LN(b + d) - (c + d) * LN(c + d) + (a + b + c + d) * LN(a + b + c + d))
If target / targetTotal < comparison / comparisonTotal Then LogLikelihood = LogLikelihood * (-1)
End Function