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 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 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 confidence_interval(data): """ Calculate confidence interval for mean :param data: list of int or float values :return: list with confidence interval """ if ch.check_list(data): return [ avg.average(data) - (1.96 * SEM(data)), avg.average(data) + (1.96 * SEM(data)) ]
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 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 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
def relative_linear_deviation(data): """ Calculate linear deviation coefficient :param data: list of int or float values :return: relative linear deviation coefficient """ if ch.check_list(data): d = vars.mean_linear_deviation(data) x = avg.average(data) return d / x
def pearson_correltaion(x, y): """Finds the Pearson correlation coefficient. :param x: list of dependent variable :param y: list of independent variable :return: value with value of correlation coefficient """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): avg_x = avg.average(x) avg_y = avg.average(y) diffprod = 0 xdiff2 = 0 ydiff2 = 0 for idx in range(len(x)): xdiff = x[idx] - avg_x ydiff = y[idx] - avg_y diffprod += xdiff * ydiff xdiff2 += xdiff * xdiff ydiff2 += ydiff * ydiff return diffprod / np.sqrt(xdiff2 * ydiff2)
def total_amount(x, y, p=2): """ Find value total amount :param x: list of dependent variable :param y: list of independent variable :param p: number of factors :return: value of total amount """ if ch.check_list(x) and ch.check_list(y): if ch.check_equality(x, y): x2 = [] y2 = [] xavg = avg.average(x) yavg = avg.average(y) xyavg = (xavg + yavg) / 2 for xi, yi in zip(x, y): x2.append(xi * xi) y2.append(yi * yi) return sum(x2) + sum(y2) - len(x) * p * (xyavg * xyavg)
def sample_dispersion(data): """ Calculate sample dispersion :param data: list of int or float values :return: S^2 """ if ch.check_list(data): n = len(data) d = 0 for element in data: d += element**2 return (d / n) - (avg.average(data)**2)
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 mean_linear_deviation(data): """ Calculate simple linear deviation :param data: list of int or float values :return: linear deviation """ if ch.check_list(data): mean = avg.average(data) n = len(data) d = 0 for element in data: d += np.fabs(element - mean) return d / n
def unbiased_variance_estimate(data): """ Calculate dispersion variance :param data: list of int or float values :return: dict with variance estimate and sqrt of dispersion variance """ if ch.check_list(data): mean = avg.average(data) n = len(data) d = 0 for element in data: d += (element - mean)**2 return {'S2': d / (n - 1), 's': np.sqrt(d / (n - 1))}
def dispersion(data): """ Calculate dispersion :param data: list of int or float values :return: (sigma^2) """ if ch.check_list(data): mean = avg.average(data) n = len(data) d = 0 for element in data: d += (element - mean)**2 return d / n