def kstatvar(data, n=2):
 data = ravel(data)
 N = len(data)
 if (n == 1):
  return ((kstat(data, n=2) * 1.0) / N)
 elif (n == 2):
  k2 = kstat(data, n=2)
  k4 = kstat(data, n=4)
  return ((((2 * N) * (k2 ** 2)) + ((N - 1) * k4)) / (N * (N + 1)))
 else:
  raise ValueError('Only n=1 or n=2 supported.')

def kstatvar ( data , n = 2 ) : data = ravel ( data ) N = len ( data ) if ( n == 1 ) : return ( ( kstat ( data , n = 2 ) * 1.0 ) / N ) elif ( n == 2 ) : k2 = kstat ( data , n = 2 ) k4 = kstat ( data , n = 4 ) return ( ( ( ( 2 * N ) * ( k2 ** 2 ) ) + ( ( N - 1 ) * k4 ) ) / ( N * ( N + 1 ) ) ) else : raise ValueError ( 'Only n=1 or n=2 supported.' )
returns an unbiased estimator of the variance of the k-statistic .