def afriedmanchisquare(*args):
    k = len(args)
    if k < 3:
        raise ValueError, '\nLess than 3 levels.  Friedman test not appropriate.\n'
    n = len(args[0])
    data = apply(pstats.aabut,args)
    data = data.astype(N.float_)
    for i in range(len(data)):
        data[i] = arankdata(data[i])
    ssbn = asum(asum(args,1)**2)
    chisq = 12.0 / (k*n*(k+1)) * ssbn - 3*n*(k+1)
    return chisq, achisqprob(chisq,k-1)


#####################################
####  APROBABILITY CALCULATIONS  ####
#####################################
Friedman Chi-Square is a non-parametric, one-way within-subjects
dataset/ETHPy150Open radlab/sparrow/src/main/python/third_party/stats.py/afriedmanchisquare