def tansey_linear_regression(points): """ to be commented. @param points is a list of tuples (x,y) of float values. @return intercept,slope """ if len(points)==0: return 0. sumOfXSq = 0. sumCodeviates = 0. n = len(points) for x,y in points: sumCodeviates += (x*y) sumOfXSq += (x*x) sum_x = central.fsum( [x for x,y in points] ) sum_y = central.fsum( [y for x,y in points] ) mean_x = central.fmean( [x for x,y in points] ) mean_y = central.fmean( [y for x,y in points] ) ssx = sumOfXSq - ((sum_x*sum_x) / n) sco = sumCodeviates - ((sum_x * sum_y) / n) b = mean_y - ((sco / ssx) * mean_x) m = sco / ssx return b, m
def rPVI(items): """ Calculates the Raw Pairwise Variability Index @param items (list) list of data values @return (float) """ if len(items) < 2: return 0.0 n = len(items) - 1 sumd = central.fsum([math.fabs(items[i] - items[i + 1]) for i in range(n)]) return sumd / n
def lvariance(items): """ Calculates the variance of the data values, using N for the denominator. The variance is a measure of dispersion near the mean. @param items (list) list of data values @return (float) """ if len(items) < 2: return 0.0 mn = central.fmean(items) return central.fsum(pow(i - mn, 2) for i in items) / (len(items))