def ANOVA_one_way(a):
 group_means = []
 group_variances = []
 num_cases = 0
 all_vals = []
 for i in a:
  num_cases += len(i)
  group_means.append(mean(i))
  group_variances.append((i.var(ddof=1) * (len(i) - 1)))
  all_vals.extend(i)
 dfd = (num_cases - len(group_means))
 within_Groups = (sum(group_variances) / dfd)
 if (within_Groups == 0.0):
  return (nan, nan)
 all_vals = array(all_vals)
 grand_mean = all_vals.mean()
 between_Groups = 0
 for i in a:
  diff = (i.mean() - grand_mean)
  diff_sq = (diff * diff)
  x = (diff_sq * len(i))
  between_Groups += x
 dfn = (len(group_means) - 1)
 between_Groups = (between_Groups / dfn)
 F = (between_Groups / within_Groups)
 return (F, fprob(F, dfn, dfd, direction='high'))

def ANOVA_one_way ( a ) : group_means = [ ] group_variances = [ ] num_cases = 0 all_vals = [ ] for i in a : num_cases += len ( i ) group_means . append ( mean ( i ) ) group_variances . append ( ( i . var ( ddof = 1 ) * ( len ( i ) - 1 ) ) ) all_vals . extend ( i ) dfd = ( num_cases - len ( group_means ) ) within_Groups = ( sum ( group_variances ) / dfd ) if ( within_Groups == 0.0 ) : return ( nan , nan ) all_vals = array ( all_vals ) grand_mean = all_vals . mean ( ) between_Groups = 0 for i in a : diff = ( i . mean ( ) - grand_mean ) diff_sq = ( diff * diff ) x = ( diff_sq * len ( i ) ) between_Groups += x dfn = ( len ( group_means ) - 1 ) between_Groups = ( between_Groups / dfn ) F = ( between_Groups / within_Groups ) return ( F , fprob ( F , dfn , dfd , direction = 'high' ) )
performs a one way analysis of variance a is a list of lists of observed values .