def fehner_coefficient(x, y): """ Value of fehner coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of fehner coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): xa = avg.average(x) ya = avg.average(y) xlist = [] ylist = [] resulter = [] for xi in x: if xi <= xa: xlist.append("-") else: xlist.append("+") for yi in y: if yi <= ya: ylist.append("-") else: ylist.append("+") for xi, yi in zip(xlist, ylist): if xi == yi: resulter.append("A") else: resulter.append("B") return (resulter.count("A") - resulter.count("B")) / ( resulter.count("A") + resulter.count("B"))
def durbin_watson(x, y): """ Find value for Durbin-Watrson criteria :param x: list of dependent variable :param y: list of independent variable :return: value of Durbin-Watrson criteria """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): yx_list = yx(x, y) e = [] for yi, yxi in zip(y, yx_list): e.append(yi - yxi) i = 0 e_ei = [] e_2 = [] for ei in e: e_2.append(ei**2) if i == 0: i += 1 continue else: e_ei.append((e[i] - e[i - 1])**2) i += 1 return sum(e_ei) / sum(e_2)
def covariation(x, y): """Find covariation coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of covariation coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): return avg.sample_average(x, y) - (avg.average(x) * avg.average(y))
def sost(x, y): """ Find value remains :param x: list of dependent variable :param y: list of independent variable :return: value of remains """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): return total_amount(x, y) - sf(x, y)
def determination_coefficient(x, y): """ Finds determination coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of determination coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): return beta_coefficient(x, y)**2
def sost_dispersion(x, y, p=2): """ Find value of ost dispersion :param x: list of dependent variable :param y: list of independent variable :param p: number of factors :return: value of ost dispersion """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): return sost(x, y) / (p * (len(x) - 1))
def beta_coefficient(x, y): """ Finds beta coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of beta coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): return regression.pair_regression(x, y)['b'] * ( vars.sample_deviation(x) / vars.sample_deviation(y))
def elastic_coefficient(x, y): """ Finds elastic coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of elastic coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): return regression.pair_regression( x, y)['b'] * (avg.average(x) / avg.average(y))
def closure_coefficient(x, y): """Find closure indicator :param x: list of dependent variable :param y: list of independent variable :return: value of closure indicator """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): numerator = avg.sample_average( x, y) - (avg.average(x) * avg.average(y)) denumerator = vars.sample_deviation(x) * vars.sample_deviation(y) return numerator / denumerator
def approximation_error(x, y): """Find approximation error :param x: list of dependent variable :param y: list of independent variable :return: value in percent of approximation error """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): yxl = yx(x, y) a = 0 for yi, yxli in zip(y, yxl): a += (np.fabs(yi - yxli)) / yi return 100 * (a / len(y))
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 expected_value(x, p): """ Find expected value of 2 datasets :param x: list of int or float values :param p: list of float values :return: value of expected value """ if ch.check_list(x) and ch.check_list(p): if ch.check_equality(x, p): if ch.check_probability(p): m = 0 for xi, pi in zip(x, p): m += xi * pi return m
def sample_average(x, y): """ Calculate sample average :param x: list of int or float values :param y: list of int or float values :return: sample average """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): res = 0 n = len(x) for xelem, yelem in zip(x, y): res += xelem * yelem return res / n
def sf(x, y, p=2): """ Find value sum for factor dispersion :param x: list of dependent variable :param y: list of independent variable :param p: number of factors :return: value of sum for factor dispersion """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): xavg = avg.average(x) yavg = avg.average(y) xyavg = (xavg + yavg) / 2 return len(x) * (xavg**2 + yavg**2 - p * (xyavg**2))
def significance(x, y): """ Finds significance of correlation coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of significance of correlation coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): b = beta_coefficient(x, y) n = len(x) numerator = b * np.sqrt(n - 2) denumerator = np.sqrt(1 - b * b) return numerator / denumerator
def yx(x, y): """Auxiliary function for approximation error :param x: list of dependent variable :param y: list of independent variable :return: list of regression values """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): yxl = [] a = pair_regression(x, y)['a'] b = pair_regression(x, y)['b'] for xi in x: yxl.append(b * xi + a) return yxl
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 tail_coefficient(x, y): """ Find tail mismatch coefficient :param x: list of dependent variable :param y: list of independent variable :return: value of tail mismatch coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): numerator = 0 denumerator = 0 yxl = regression.yx(x, y) for yi, yxl in zip(y, yxl): numerator += (yi - yxl)**2 denumerator += yxl**2 return numerator / denumerator
def standard_deviation(data): """ Calculate simple standard deviation :param data: list of int or float values :return: standard deviation """ if ch.check_list(data): return np.sqrt(dispersion(data))
def range(data): """ Find range of data list :param data: list of int or float values :return: max value of list minus min value of list """ if ch.check_list(data): return max(data) - min(data)
def SEM(data): """ Calculate standard error of the mean :param data: list of int or float values :return: standard error of the mean """ if ch.check_list(data): return standard_deviation(data) / len(data)
def kurtosis(data): """ Calculate rate of kurtosis :param data: list of int or float values :return: value of kurtosis """ if ch.check_list(data): return (moment(data, degree=4) / vars.standard_deviation(data)**4) - 3
def asymmetry_coefficient(data): """ Calculate asymmetry coefficient :param data: list of int or float values :return: value of asymmetry coefficient """ if (ch.check_list(data) == True): return moment(data, degree=3) / (vars.standard_deviation(data)**3)
def average(data): """ Calculate average of list :param data: list of int or float values :return: average of list """ if ch.check_list(data): return sum(data) / len(data)
def frequency(data): """ Find frequencies of list :param data: list of int or float values :return: list with dictionary of frequencies and sum of frequencies """ if (ch.check_list(data) == True): return [{x: data.count(x) for x in data}, len(data)]
def sample_deviation(data): """ Calculate sample deviation :param data: list of int or float values :return: sample deviation """ if ch.check_list(data): return np.sqrt(sample_dispersion(data))
def capacity(data): """ Find length of list :param data: list of int or float values :return: list length """ if ch.check_list(data): return len(data)
def mode(data): """ Calculate most common use element in list :param data: list of int or float values :return: mode of list """ if ch.check_list(data): most = max(list(map(data.count, data))) return list(set(filter(lambda x: data.count(x) == most, data)))
def oscillation_coefficient(data): """ Calculate coefficient of oscillation :param data: list of int or float values :return: oscillation coefficient """ if ch.check_list(data): R = base.range(data) x = avg.average(data) return R / x
def coefficient_of_variation(data): """ Calculate coefficient of variation :param data: list of int or float values :return: variation coefficient """ if ch.check_list(data): b = vars.standard_deviation(data) x = avg.average(data) return b / x