# Path: simplestatistics/statistics/mean.py
# def mean(data):
#     """
#     The mean_, or *average*, is "the sum of values divided by the number of values".
# 
#     .. _mean: https://en.wikipedia.org/wiki/Mean
# 
#     Equation:
#         .. math::
#             \\bar{X} = \\frac{\\sum X}{n}
# 
#     Args:
#         data: A numeric built-in object, a tuple,
#             or list of numeric objects.
# 
#     Returns:
#         A float object.
# 
#     Examples:
# 
#         >>> mean([1])
#         1.0
#         >>> mean([1, 2])
#         1.5
#         >>> mean([1, 2, 3])
#         2.0
#         >>> mean([-1, 0, 1, 2, 3])
#         1.0
#     """
#     data = decimalize(copy.deepcopy(data)) # don't modify the original data
#     return float(sum(data) / len(data))
# 
# Path: simplestatistics/statistics/sum.py
# def sum(data): # pylint: disable=redefined-builtin
#     """
#     This function returns the sum of numerical values in a data set.
# 
#     To reduce floating-point errors, I am using an implementation of the
#     `Kahan summation algorithm`_.
# 
#     .. _`Kahan summation algorithm`: https://en.wikipedia.org/wiki/Kahan_summation_algorithm
# 
#     The implementation is modeled after that of `simple-statistics \
#     <https://github.com/simple-statistics/simple-statistics/blob/master/src/sum.js>`_.
# 
#     Args:
#         data: A numeric built-in object or list of numeric objects.
# 
#     Returns:
#         A numeric object.
# 
#     Examples:
#         >>> sum([1, 2, 3])
#         6
#         >>> sum([-1, 0, 1])
#         0
#         >>> sum([2.3, 0, -1.1])
#         1.2
#         >>> sum(4)
#         4
#         >>> sum((3, 2.5))
#         5.5
#         >>> sum([1.00001, 1.00002])
#         2.0
#         >>> sum([1.0001, 1.0002])
#         2.0
#         >>> sum([1.001, 1.002])
#         2.003
#         >>> sum('abc')
#         Traceback (most recent call last):
#             ...
#         TypeError: sum() expects an int, list, or tuple.
#     """
#     current_sum = 0
# 
#     error_compensation = 0
#     corrected_current_value = 0
#     next_sum = 0
# 
#     if type(data) in [int, float]:
#         return(data)
#     elif type(data) in [list, tuple]:
#         for ii, _ in enumerate(data):
#             corrected_current_value = data[ii] - error_compensation
# 
#             next_sum = current_sum + corrected_current_value
# 
#             error_compensation = next_sum - current_sum - corrected_current_value
# 
#             current_sum = next_sum
# 
#         # floating-point errors are unavoidable
#         # with all measures taken above, we will still need
#         # to round to 3 decimal points sometimes
#         return(round(current_sum, 3))
#     else:
#         raise TypeError("sum() expects an int, list, or tuple.")


from .mean import mean
from .sum import sum # pylint: disable=redefined-builtin

        :math:`s4 = \\sum(X-\\bar{X})^4`

        :math:`V(x) = \\frac{s2}{n - 1}`

    Args:
        x: A list of numerical objects. This calculation requires **at least 4 observations**.

    Returns:
        A numerical object.

    Examples:

        >>> kurtosis([1, 2, 3, 4, 5])
        -1.1999999999999993
        >>> kurtosis([1987, 1987, 1991, 1992, 1992, 1992, 1992, 1993, 1994, 1994, 1995])
        0.4466257157411544
        >>> kurtosis(2) # no kurtosis for a single number/value
        >>> kurtosis([1, 2, 3]) # this kurtosis calculation requires at least 4 observations
    """

    if type(x) in [int, float]:
        return(None)
    elif type(x) in [list, tuple] and len(x) < 5:
        return(None)

    n = len(x)
    mean_x = mean(x)

    s2 = sum([pow((value - mean_x), 2) for value in x])

# Path: simplestatistics/statistics/mean.py
# def mean(data):
#     """
#     The mean_, or *average*, is "the sum of values divided by the number of values".
# 
#     .. _mean: https://en.wikipedia.org/wiki/Mean
# 
#     Equation:
#         .. math::
#             \\bar{X} = \\frac{\\sum X}{n}
# 
#     Args:
#         data: A numeric built-in object, a tuple,
#             or list of numeric objects.
# 
#     Returns:
#         A float object.
# 
#     Examples:
# 
#         >>> mean([1])
#         1.0
#         >>> mean([1, 2])
#         1.5
#         >>> mean([1, 2, 3])
#         2.0
#         >>> mean([-1, 0, 1, 2, 3])
#         1.0
#     """
#     data = decimalize(copy.deepcopy(data)) # don't modify the original data
#     return float(sum(data) / len(data))
# 
# Path: simplestatistics/statistics/sum.py
# def sum(data): # pylint: disable=redefined-builtin
#     """
#     This function returns the sum of numerical values in a data set.
# 
#     To reduce floating-point errors, I am using an implementation of the
#     `Kahan summation algorithm`_.
# 
#     .. _`Kahan summation algorithm`: https://en.wikipedia.org/wiki/Kahan_summation_algorithm
# 
#     The implementation is modeled after that of `simple-statistics \
#     <https://github.com/simple-statistics/simple-statistics/blob/master/src/sum.js>`_.
# 
#     Args:
#         data: A numeric built-in object or list of numeric objects.
# 
#     Returns:
#         A numeric object.
# 
#     Examples:
#         >>> sum([1, 2, 3])
#         6
#         >>> sum([-1, 0, 1])
#         0
#         >>> sum([2.3, 0, -1.1])
#         1.2
#         >>> sum(4)
#         4
#         >>> sum((3, 2.5))
#         5.5
#         >>> sum([1.00001, 1.00002])
#         2.0
#         >>> sum([1.0001, 1.0002])
#         2.0
#         >>> sum([1.001, 1.002])
#         2.003
#         >>> sum('abc')
#         Traceback (most recent call last):
#             ...
#         TypeError: sum() expects an int, list, or tuple.
#     """
#     current_sum = 0
# 
#     error_compensation = 0
#     corrected_current_value = 0
#     next_sum = 0
# 
#     if type(data) in [int, float]:
#         return(data)
#     elif type(data) in [list, tuple]:
#         for ii, _ in enumerate(data):
#             corrected_current_value = data[ii] - error_compensation
# 
#             next_sum = current_sum + corrected_current_value
# 
#             error_compensation = next_sum - current_sum - corrected_current_value
# 
#             current_sum = next_sum
# 
#         # floating-point errors are unavoidable
#         # with all measures taken above, we will still need
#         # to round to 3 decimal points sometimes
#         return(round(current_sum, 3))
#     else:
#         raise TypeError("sum() expects an int, list, or tuple.")


# Path: simplestatistics/statistics/kurtosis.py
from .mean import mean
from .sum import sum # pylint: disable=redefined-builtin


        :math:`s4 = \\sum(X-\\bar{X})^4`

        :math:`V(x) = \\frac{s2}{n - 1}`

    Args:
        x: A list of numerical objects. This calculation requires **at least 4 observations**.

    Returns:
        A numerical object.

    Examples:

        >>> kurtosis([1, 2, 3, 4, 5])
        -1.1999999999999993
        >>> kurtosis([1987, 1987, 1991, 1992, 1992, 1992, 1992, 1993, 1994, 1994, 1995])
        0.4466257157411544
        >>> kurtosis(2) # no kurtosis for a single number/value
        >>> kurtosis([1, 2, 3]) # this kurtosis calculation requires at least 4 observations
    """

    if type(x) in [int, float]:
        return(None)
    elif type(x) in [list, tuple] and len(x) < 5:
        return(None)

    n = len(x)
    mean_x = mean(x)

    s2 = sum([pow((value - mean_x), 2) for value in x])

    s4 = sum([pow((value - mean_x), 4) for value in x])