特徴語抽出

対数尤度比 Log Likelihood Ratio

  • 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

*1 Excelシートのlog関数とはちがってVBAではlog関数が自然対数(底がe)なのに注意。Excelだとln関数

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS