def anovar2(data_group, data_y): n = len(data_group) assert n == len(data_y) group_index = {} for x in data_group: if x not in group_index: group_index[x] = len(group_index) n_groups = len(group_index) if n_groups == 0: # No data, so no notion of correlation. return float('NaN'), n_groups if n_groups == n: # No variation in any group, so no notion of correlation. return float('NaN'), n_groups if n_groups == 1: # Only one group means we can draw no information from the # choice of group, so no notion of correlation. return float('NaN'), n_groups groups = [None] * n_groups for i in xrange(n_groups): groups[i] = [] for x, y in zip(data_group, data_y): groups[group_index[x]].append(y) # Compute observed F-test statistic. F = stats.f_oneway(groups) return F, n_groups
def test_f_oneway(): data = [[6,8,4,5,3,4], [8,12,9,11,6,8], [13,9,11,8,7,12]] assert relerr(9.3, stats.f_oneway(data)) < 0.01