Negative log likelihood given data and a model

    Parameters
    ----------
    {0}
    {1}

    Returns
    -------
    float
        Negative log likelihood

    Examples
    ---------

    >>> import macroeco.models as md
    >>> import macroeco.compare as comp

    >>> # Generate random data
    >>> rand_samp = md.logser.rvs(p=0.9, size=100)

    >>> # Get nll for p = 0.9
    >>> comp.nll(rand_samp, md.logser(p=0.9))
    237.6871819262054

    >>> # Get the nll for the MLE for p
    >>> mle_p = md.logser.fit_mle(rand_samp)
    >>> comp.nll(rand_samp, md.logser(*mle_p))
    235.2841347820297

def nll(data, model):
    """
    Negative log likelihood given data and a model

    Parameters
    ----------
    {0}
    {1}

    Returns
    -------
    float
        Negative log likelihood

    Examples
    ---------

    >>> import macroeco.models as md
    >>> import macroeco.compare as comp

    >>> # Generate random data
    >>> rand_samp = md.logser.rvs(p=0.9, size=100)

    >>> # Get nll for p = 0.9
    >>> comp.nll(rand_samp, md.logser(p=0.9))
    237.6871819262054

    >>> # Get the nll for the MLE for p
    >>> mle_p = md.logser.fit_mle(rand_samp)
    >>> comp.nll(rand_samp, md.logser(*mle_p))
    235.2841347820297

    """

    try:
        log_lik_vals = model.logpmf(data)
    except:
        log_lik_vals = model.logpdf(data)
    return -np.sum(log_lik_vals)