Akaike Information Criteria given data and a model

    Parameters
    ----------
    {0}
    {1}
    params : int
        Number of parameters in the model. If None, calculated from model
        object.
    corrected : bool
        If True, calculates the small-sample size correct AICC. Default True.

    Returns
    -------
    float
        AIC(C) value

    Notes
    -----
    AICC should be used when the number of observations is < 40.

    Examples
    --------

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

    >>> # Generate random data
    >>> rand_samp = md.nbinom_ztrunc.rvs(20, 0.5, size=100)

    >>> # Fit Zero-truncated NBD (Full model)
    >>> mle_nbd = md.nbinom_ztrunc.fit_mle(rand_samp)

    >>> # Fit a logseries (limiting case of Zero-truncated NBD, reduced model)
    >>> mle_logser = md.logser.fit_mle(rand_samp)

    >>> # Get AIC for ztrunc_nbinom
    >>> comp.AIC(rand_samp, md.nbinom_ztrunc(*mle_nbd))
    765.51518598676421

    >>> # Get AIC for logser
    >>> comp.AIC(rand_samp, md.logser(*mle_logser))
    777.05165086534805

    >>> # Support for for zero-truncated NBD over logseries because AIC is
    >>> # smaller

    >>> # Call AIC with params given as 2 (should be the same as above)
    >>> comp.AIC(rand_samp, md.nbinom_ztrunc(*mle_nbd), params=2)
    765.51518598676421

    >>> # Call AIC without sample size correction
    >>> comp.AIC(rand_samp, md.nbinom_ztrunc(*mle_nbd), params=2, corrected=False)
    765.39147464655798

    References
    ----------
    .. [#]
       Burnham, K and Anderson, D. (2002) Model Selection and Multimodel
       Inference: A Practical and Information-Theoretic Approach (p. 66). New
       York City, USA: Springer.

def AIC(data, model, params=None, corrected=True):
    """
    Akaike Information Criteria given data and a model

    Parameters
    ----------
    {0}
    {1}
    params : int
        Number of parameters in the model. If None, calculated from model
        object.
    corrected : bool
        If True, calculates the small-sample size correct AICC. Default True.

    Returns
    -------
    float
        AIC(C) value

    Notes
    -----
    AICC should be used when the number of observations is < 40.

    Examples
    --------

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

    >>> # Generate random data
    >>> rand_samp = md.nbinom_ztrunc.rvs(20, 0.5, size=100)

    >>> # Fit Zero-truncated NBD (Full model)
    >>> mle_nbd = md.nbinom_ztrunc.fit_mle(rand_samp)

    >>> # Fit a logseries (limiting case of Zero-truncated NBD, reduced model)
    >>> mle_logser = md.logser.fit_mle(rand_samp)

    >>> # Get AIC for ztrunc_nbinom
    >>> comp.AIC(rand_samp, md.nbinom_ztrunc(*mle_nbd))
    765.51518598676421

    >>> # Get AIC for logser
    >>> comp.AIC(rand_samp, md.logser(*mle_logser))
    777.05165086534805

    >>> # Support for for zero-truncated NBD over logseries because AIC is
    >>> # smaller

    >>> # Call AIC with params given as 2 (should be the same as above)
    >>> comp.AIC(rand_samp, md.nbinom_ztrunc(*mle_nbd), params=2)
    765.51518598676421

    >>> # Call AIC without sample size correction
    >>> comp.AIC(rand_samp, md.nbinom_ztrunc(*mle_nbd), params=2, corrected=False)
    765.39147464655798

    References
    ----------
    .. [#]
       Burnham, K and Anderson, D. (2002) Model Selection and Multimodel
       Inference: A Practical and Information-Theoretic Approach (p. 66). New
       York City, USA: Springer.

    """
    n = len(data)  # Number of observations
    L = nll(data, model)

    if not params:
        k = len(model.kwds) + len(model.args)
    else:
        k = params

    if corrected:
        aic_value = 2 * k + 2 * L + (2 * k * (k + 1)) / (n - k - 1)
    else:
        aic_value = 2 * k + 2 * L

    return aic_value