The univariate Mann-Kendall (MK) test is used to detect monotonic trends in a univariate data series.
It tests the null hypothesis (\(h_0\)) of no trend, against an alternative.
Let \((x_1, x_2, ..., x_n)\) be a data series of length \(n\), the MK test statistic is
given by:
$$M = \sum_{i=1}^{n-1} \sum_{j=i+1}^{n} sgn(x_j-x_i)$$
where \(sgn(\cdot)\) is the sign function:
$$
sgn(x)=\begin{cases}
-1 \quad \text{if } x<0, \\
0 \quad \text{if } x=0, \\
+1 \quad \text{if } x>0
\end{cases}
$$
Under \(H_0\) the test statistic is asymptotically normally distributed with mean and
variance:
$$E(M) = 0$$
$$\text{Var}(M)=\frac{n(n-1)(n+5)}{18}$$