Message Boards Message Boards

1
|
4648 Views
|
3 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Mann-kendall (MK) trend test in Mathematica ?

Posted 3 years ago

Dear All,

The Mann-Kendall Test is used to determine whether a time series has a monotonic upward or downward trend. In MATLAB, Excel, and R there is a calculation command for this. I can't find any command in Mathematica for MK test. I tried to write a small code in Mathematica, but I got some errors. Any help would be appreciated.

enter image description here

data = {11.22, 12.29, 12.97, 14.15, 17.33, 17.60, 16.62, 14.43, 13.62,
    11.01};

n = Length[data]

S = \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n - 1\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = i + 1\), \(n\)]Sign[
\*SubscriptBox[\(x\), \(k\)] - 
\*SubscriptBox[\(x\), \(j\)]]\)\)

Zc = Piecewise[{{(S - 1)/Sqrt[(n (n - 1) (2 n + 5))/18], S > 0}, {0, 
    S = 0}, {(S + 1)/Sqrt[(n (n - 1) (2 n + 5))/18], S < 0}}]

\[Beta] = Median[(Subscript[x, i] - Subscript[x, j])/(i - j)]
POSTED BY: Alex Teymouri
3 Replies
Posted 3 years ago

The following is the estimate for $\beta$ (Sen's slope):

\[Beta] = Median[Flatten[Table[(data[[i]] - data[[j]])/(i - j), {i, 1, n - 1}, {j, i + 1, n}]]]

It's the median of all pairwise estimates of slope.

And you need "==" instead of "=" for "S==0" in the Piecewise function.

Also, S can be determined in the following manner:

S = Binomial[n, 2] KendallTau[Range[n], data]
POSTED BY: Jim Baldwin
Posted 3 years ago

Hi Alex,

Subscripts in WL don't translate to array indexing. You have to do this to compute S

S = Sum[Sign[data[[k]] - data[[i]]], {i, 1, n - 1}, {k, i + 1, n}]
(* 7 *)

Then Zc evaluates to 6/(5 Sqrt[5]).

I don't understand the formula for β, Median is computed on a single value which does not make sense. Can you explain?

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Thank you, Rohit.

β is the slope of n pairs of data points. If a significant trend is found, the rate of change can be calculated using the Sen slope estimator (β). In other words, computing the slope for all pairs of data that were used to compute S. enter image description here

The main reference explains as follow: enter image description here

POSTED BY: Alex Teymouri
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract