Function Repository Resource:

MannKendallZ

Source Notebook

Compute the z-statistic for the Mann-Kendall test

Contributed by: Rauan Kaldybayev

ResourceFunction["MannKendallZ"][data]

computes the z-statistic for the Mann–Kendall test.

Details

The Mann–Kendall test allows the determination of any apparent trend in a time series. A positive z-statistic indicates an upward trend, a negative z-statistic indicates a downward trend and a zero z-statistic indicates a lack of trend.
The data can be a List of real numbers or a TimeSeries object.

Examples

Basic Examples (2) 

Compute the z-statistic for a list of data points:

In[1]:=
data = {6.8, 5.9, 5.7, 5.5,  5.5, 4.5, 4.0, 5.1, 4.5, 4.5, 3.3, 4.8};
N @ ResourceFunction["MannKendallZ"][data]
Out[1]=

The statistic is negative, indicating a downward trend:

In[2]:=
ListLinePlot[data, PlotRange -> {3, 7}]
Out[2]=

Scope (2) 

Various sets of data demonstrating negative, zero and positive trends, along with their corresponding z-statistics:

In[3]:=
ListLinePlot[#, PlotLabel -> Row[{"z = ", N @ ResourceFunction["MannKendallZ"][#]}]] & /@ {{4, 9, 1, -3, 2, -2}, {0, -2, 1, 0.5, -0.8}, {1, 7, 2, 9, 4, 12}}
Out[3]=

Compute the z-statistic of a TimeSeries object:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/fefbaf17-2540-4171-a7c3-fa675ae200fc"]
Out[4]=

Applications (3) 

Use MannKendallZ to determine the general trend of the GDP of Kazakhstan from 1991 to 2019:

In[5]:=
gdpkz = CountryData["Kazakhstan", {"GDP", {1991, 2019}}]
Out[5]=
In[6]:=
zval = N @ ResourceFunction["MannKendallZ"][gdpkz]
Out[6]=

The plot confirms the generally positive trend of the data:

In[7]:=
ListLinePlot[gdpkz, PlotLabel -> Row[{"z = ", zval}]]
Out[7]=

Compute the corresponding p-value for a two-sided test:

In[8]:=
2 CDF[NormalDistribution[], -Abs[zval]]
Out[8]=

Publisher

Wolfram Summer Camp

Version History

  • 1.0.0 – 13 July 2021

Source Metadata

Related Resources

License Information