def spearmanr(x, y, use_ties=True):
    (x, y, n) = _chk_size(x, y)
    (x, y) = (x.ravel(), y.ravel())

    m = ma.mask_or(ma.getmask(x), ma.getmask(y))
    n -= m.sum()
    if m is not nomask:
        x = ma.array(x, mask=m, copy=True)
        y = ma.array(y, mask=m, copy=True)
    df = n-2
    if df < 0:
        raise ValueError("The input must have at least 3 entries!")

    # Gets the ranks and rank differences
    rankx = rankdata(x)
    ranky = rankdata(y)
    dsq = np.add.reduce((rankx-ranky)**2)
    # Tie correction
    if use_ties:
        xties = count_tied_groups(x)
        yties = count_tied_groups(y)
        corr_x = np.sum(v*k*(k**2-1) for (k,v) in iteritems(xties))/12.
        corr_y = np.sum(v*k*(k**2-1) for (k,v) in iteritems(yties))/12.
    else:
        corr_x = corr_y = 0

    denom = n*(n**2 - 1)/6.
    if corr_x != 0 or corr_y != 0:
        rho = denom - dsq - corr_x - corr_y
        rho /= ma.sqrt((denom-2*corr_x)*(denom-2*corr_y))
    else:
        rho = 1. - dsq/denom

    t = ma.sqrt(ma.divide(df,(rho+1.0)*(1.0-rho))) * rho
    if t is masked:
        prob = 0.
    else:
        prob = _betai(0.5*df, 0.5, df/(df + t * t))

    return SpearmanrResult(rho, prob)
Calculates a Spearman rank-order correlation coefficient and the p-value
dataset/ETHPy150Open scipy/scipy/scipy/stats/mstats_basic.py/spearmanr