def factorial(n): """ :return: returns the factorial of a number """ if ch.check_number(n): i = 1 fact = 1 while i <= n: fact *= i i += 1 return fact
def moment(data, degree): """ Calculate central moments :param data: list of int or float values :return: value of central moment """ if ch.check_list(data) and ch.check_number(degree): mean = avg.average(data) M = 0 for element in data: M += (element - mean)**degree return M / len(data)
def fisher_criteria(x, y, m): """ Value of fisher criteria :param x: list of dependent variable :param y: list of independent variable :param m: the number of influencing factors in the trend model :return: value of fisher criteria """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y) and ch.check_number(m): numerator = determination_coefficient(x, y) * (len(x) - m - 1) denumerator = (1 - determination_coefficient(x, y)) * m return numerator / denumerator
def dispersion_error_equation(x, y, m): """ Dispersion error equations :param x: list of dependent variable :param y: list of independent variable :param m: the number of influencing factors in the trend model :return: value of dispersion error """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y) and ch.check_number(m): numerator = 0 yxl = yx(x, y) for yi, yxl in zip(y, yxl): numerator += (yi - yxl)**2 return numerator / (len(y) - m - 1)
def accomodations_with_repeats(n, k): """ :return: value of accomodations with repeats """ if ch.check_number(n) and ch.check_number(k): return n**k
def combinations_with_repeats(n, m): """ :return: value of combinations with repeats """ if ch.check_number(n) and ch.check_number(m): return factorial(n + m - 1) / (factorial(n - 1) * factorial(m))
def accommodations(n, k): """ :return: the number of allocations of n elements in k """ if ch.check_number(n) and ch.check_number(k): return factorial(n) / factorial(n - k)
def combinations(n, m): """ :return: number of combinations of n by m """ if ch.check_number(n) and ch.check_number(m): return factorial(n) / (factorial(m) * factorial(n - m))