import math


def dunn_individual_word(total_words_in_corpus_1,
                         total_words_in_corpus_2,
                         count_of_word_in_corpus_1,
                         count_of_word_in_corpus_2):
    """
    applies Dunning log likelihood to compare individual word in two counter objects

    :param total_words_in_corpus_1: int, total wordcount in corpus 1
    :param total_words_in_corpus_2: int, total wordcount in corpus 2
    :param count_of_word_in_corpus_1: int, wordcount of one word in corpus 1
    :param count_of_word_in_corpus_2: int, wordcount of one word in corpus 2
    :return: Float representing the Dunning log likelihood of the given inputs

    >>> total_words_m_corpus = 8648489
    >>> total_words_f_corpus = 8700765
    >>> wordcount_female = 1000
    >>> wordcount_male = 50
    >>> dunn_individual_word(total_words_m_corpus,total_words_f_corpus,wordcount_male,wordcount_female)
    -1047.8610274053995

    """
    a = count_of_word_in_corpus_1
    b = count_of_word_in_corpus_2
    c = total_words_in_corpus_1
    d = total_words_in_corpus_2

    e1 = c * (a + b) / (c + d)
    e2 = d * (a + b) / (c + d)

    dunning_log_likelihood = 2 * (a * math.log(a / e1) + b * math.log(b / e2))

    if count_of_word_in_corpus_1 * math.log(count_of_word_in_corpus_1 / e1) < 0:
        dunning_log_likelihood = -dunning_log_likelihood

    return dunning_log_likelihood