def kendalltau(x, y, use_ties=True, use_missing=False):
(x, y, n) = _chk_size(x, y)<EOL>(x, y) = (x.flatten(), y.flatten())<EOL>m = ma.mask_or(ma.getmask(x), ma.getmask(y))<EOL>if m is not nomask:<EOL><INDENT>x = ma.array(x, mask=m, copy=True)<EOL>y = ma.array(y, mask=m, copy=True)<EOL>n -= m.sum()<EOL><DEDENT>if n < <NUM_LIT:2>:<EOL><INDENT>return (np.nan, np.nan)<EOL><DEDENT>rx = ma.masked_equal(rankdata(x, use_missing=use_missing), <NUM_LIT:0>)<EOL>ry = ma.masked_equal(rankdata(y, use_missing=use_missing), <NUM_LIT:0>)<EOL>idx = rx.argsort()<EOL>(rx, ry) = (rx[idx], ry[idx])<EOL>C = np.sum([((ry[i+<NUM_LIT:1>:] > ry[i]) * (rx[i+<NUM_LIT:1>:] > rx[i])).filled(<NUM_LIT:0>).sum()<EOL>for i in range(len(ry)-<NUM_LIT:1>)], dtype=float)<EOL>D = np.sum([((ry[i+<NUM_LIT:1>:] < ry[i])*(rx[i+<NUM_LIT:1>:] > rx[i])).filled(<NUM_LIT:0>).sum()<EOL>for i in range(len(ry)-<NUM_LIT:1>)], dtype=float)<EOL>if use_ties:<EOL><INDENT>xties = count_tied_groups(x)<EOL>yties = count_tied_groups(y)<EOL>corr_x = np.sum([v*k*(k-<NUM_LIT:1>) for (k,v) in iteritems(xties)], dtype=float)<EOL>corr_y = np.sum([v*k*(k-<NUM_LIT:1>) for (k,v) in iteritems(yties)], dtype=float)<EOL>denom = ma.sqrt((n*(n-<NUM_LIT:1>)-corr_x)/<NUM_LIT> * (n*(n-<NUM_LIT:1>)-corr_y)/<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>denom = n*(n-<NUM_LIT:1>)/<NUM_LIT><EOL><DEDENT>tau = (C-D) / denom<EOL>var_s = n*(n-<NUM_LIT:1>)*(<NUM_LIT:2>*n+<NUM_LIT:5>)<EOL>if use_ties:<EOL><INDENT>var_s -= np.sum(v*k*(k-<NUM_LIT:1>)*(<NUM_LIT:2>*k+<NUM_LIT:5>)*<NUM_LIT:1.> for (k,v) in iteritems(xties))<EOL>var_s -= np.sum(v*k*(k-<NUM_LIT:1>)*(<NUM_LIT:2>*k+<NUM_LIT:5>)*<NUM_LIT:1.> for (k,v) in iteritems(yties))<EOL>v1 = np.sum([v*k*(k-<NUM_LIT:1>) for (k, v) in iteritems(xties)], dtype=float) *np.sum([v*k*(k-<NUM_LIT:1>) for (k, v) in iteritems(yties)], dtype=float)<EOL>v1 /= <NUM_LIT>*n*(n-<NUM_LIT:1>)<EOL>if n > <NUM_LIT:2>:<EOL><INDENT>v2 = np.sum([v*k*(k-<NUM_LIT:1>)*(k-<NUM_LIT:2>) for (k,v) in iteritems(xties)],<EOL>dtype=float) *np.sum([v*k*(k-<NUM_LIT:1>)*(k-<NUM_LIT:2>) for (k,v) in iteritems(yties)],<EOL>dtype=float)<EOL>v2 /= <NUM_LIT>*n*(n-<NUM_LIT:1>)*(n-<NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>v2 = <NUM_LIT:0><EOL><DEDENT><DEDENT>else:<EOL><INDENT>v1 = v2 = <NUM_LIT:0><EOL><DEDENT>var_s /= <NUM_LIT><EOL>var_s += (v1 + v2)<EOL>z = (C-D)/np.sqrt(var_s)<EOL>prob = special.erfc(abs(z)/np.sqrt(<NUM_LIT:2>))<EOL>return (tau, prob)<EOL>
Computes Kendall's rank correlation tau on two variables *x* and *y*.

Parameters
----------
xdata : sequence
    First data list (for example, time).
ydata : sequence
    Second data list.
use_ties : {True, False}, optional
    Whether ties correction should be performed.
use_missing : {False, True}, optional
    Whether missing data should be allocated a rank of 0 (False) or the
    average rank (True)

Returns
-------
tau : float
    Kendall tau
prob : float
    Approximate 2-side p-value.