#NEWLINE# def kruskal( * args ) : #NEWLINE# #INDENT# '\n    Compute the Kruskal-Wallis H-test for independent samples\n\n    Parameters\n    ----------\n    sample1, sample2, ... : array_like\n       Two or more arrays with the sample measurements can be given as\n       arguments.\n\n    Returns\n    -------\n    statistic : float\n       The Kruskal-Wallis H statistic, corrected for ties\n    pvalue : float\n       The p-value for the test using the assumption that H has a chi\n       square distribution\n\n    Notes\n    -----\n    For more details on `kruskal`, see `stats.kruskal`.\n\n    ' #NEWLINE# output = argstoarray ( * args ) #NEWLINE# ranks = ma . masked_equal ( rankdata ( output , use_missing = False ) , 0 ) #NEWLINE# sumrk = ranks . sum ( ( - 1 ) ) #NEWLINE# ngrp = ranks . count ( ( - 1 ) ) #NEWLINE# ntot = ranks . count ( ) #NEWLINE# H = ( ( ( 12.0 / ( ntot * ( ntot + 1 ) ) ) * ( ( sumrk ** 2 ) / ngrp ) . sum ( ) ) - ( 3 * ( ntot + 1 ) ) ) #NEWLINE# ties = count_tied_groups ( ranks ) #NEWLINE# T = ( 1.0 - ( np . sum ( ( ( v * ( ( k ** 3 ) - k ) ) for ( k , v ) in iteritems ( ties ) ) ) / float ( ( ( ntot ** 3 ) - ntot ) ) ) ) #NEWLINE# if ( T == 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'All numbers are identical in kruskal' ) #NEWLINE# #UNINDENT# H /= T #NEWLINE# df = ( len ( output ) - 1 ) #NEWLINE# prob = distributions . chi2 . sf ( H , df ) #NEWLINE# return KruskalResult ( H , prob )