import itertools


def _TieCorrectionFactor(rankvals):
  """Tie correction factor for ties in the Mann-Whitney U test."""
  arr = sorted(rankvals)
  cnt = [len(list(group)) for _, group in itertools.groupby(arr)]
  size = len(arr)
  if size < 2:
    return 1.0
  else:
    return 1.0 - sum(x**3 - x for x in cnt) / float(size**3 - size)