Mann-Kendall Test

Basic Concepts

The Mann-Kendall Test is used to determine whether a time series has a monotonic upward or downward trend. It does not require that the data be normally distributed or linear. It does require that there is no autocorrelation.

The null hypothesis for this test is that there is no trend, and the alternative hypothesis is that there is a trend in the two-sided test or that there is an upward trend (or downward trend) in the one-sided test. For the time series x1, .., xn, the MK Test uses the following statistic:

MK statistic

Note that if S > 0 then later observations in the time series tend to be larger than those that appear earlier in the time series, while the reverse is true if S < 0.

The variance of S is given by

 Mann-Kendall variance

where t varies over the set of tied ranks and ft is the number of times (i.e. frequency) that the rank t appears.

The MK Test uses the following test statistic:

z statistic

where se = the square root of var. If there is no monotonic trend (the null hypothesis), then for a time series with more than 10 elements, zN(0, 1), i.e. z has a standard normal distribution.

Examples

Example 1: Determine whether the time series in range A4:A15 of Figure 1 has a monotonic trend.

Mann-Kendall (part 1)

Figure 1 – Mann-Kendall Test (part 1)

We build a table in range D4:O15 so that the row and column headings consist of the data elements in the time series and the cells in the lower triangular part of the table consist of the values in S. In particular, we insert the following formula in cell D4, highlight range D4:O15, and press Ctrl-D and Ctrl-R.

=IF(ROW(D4)-ROW(D$4)>COLUMN(D4)-COLUMN($D4),SIGN($C4-D$3),””)

S is now the sum of the elements in this table. In fact, the MK Test, based on this table is shown in Figure 2.

Mann-Kendall (part 2)

Figure 2 – Mann-Kendall Test (part 2) 

Note that S = -44 (cell R7), which indicates the potential for a downward trend. This is consistent with the line chart of the time series data shown in Figure 3.

Time series plot

Figure 3 – Downward trend

The analysis shown in Figure 2 confirms that there is significant evidence for the claim that the data has a trend based on a two-sided test. Actually, if we had conducted a one-sided test we would reject the null hypothesis that there is either no trend or an upward trend, and conclude that there is a downward trend (the p-value for this test is half of the value shown in cell R10).

Ties Correction

Note that the ties correction used in the formula in cell R8 is based on the value in cell P19. This is calculated based on the values shown in range D17:N19. To create the values in this range, first insert formula =COUNTIF(E3:$O3,D3) in cell D17 and then highlight range D17:N17 and press Ctrl-R. Cells in this row (labeled preliminary ties counts) that are not zero correspond to time series values that are tied. The only problem is that when the ties count is bigger than 1 (i.e. two values are tied) there is some double counting.

This double counting is eliminated in the next row (labeled ties counts). This is accomplished by inserting the formula =D17 in cell D18, the formula =IF(COUNTIF($D3:D3,E3)=0,E17,0) in cell E18, highlighting the range E18:N18 and pressing Ctrl-R. This row shows that there are 2 data elements with the value 5.5 (the column heading above cell G18) and 3 elements with the value 4.5 (the column heading above cell I18). The values shown in cells G18 and G20 are one less than the number of ties.

The following row contains the ties corrections where cell P19 contains the sum of these corrections. This is done by inserting the formula =IF(D18=0,0,D18*(D18+1)*(2*D18+7)) in cell D19, highlighting the range D19:N19, pressing Ctrl-R and, inserting the formula =SUM(D19:N19) in cell P19.

Worksheet Function

Real Statistics Function: The Real Statistics Resource Pack supplies the following array function to automate the steps required to perform the Mann-Kendall Test.

MK_TEST(R1, lab, tails, alpha): returns a column array with the values S, s.e., z-stat, p-value, and trend.

R1 is a column array containing the time series values, if lab = TRUE then an extra column of labels is appended to the output (default FALSE), tails = 1 or 2 (default), and alpha is the significance level (default .05).

trend takes the values “yes” or “no” in the two-tailed test, and “upward” or “no” in the one-tailed case where S > 0 and “downward” or “no” in the one-tailed case where S < 0.

For Example 1, =MK_TEST(A4:A15,TRUE) outputs the results shown in range Q7:R11 of Figure 2.

Data Analysis Tool

The Mann-Kendall Test can also be performed using the Mann-Kendall and Sen’s Slope data analysis tool, as demonstrated in Sen’s Slope.

Seasonal Test

See Seasonal Kendall’s Test for a seasonal version of the Mann-Kendall Test.

Examples Workbook

Click here to download the Excel workbook with the examples described on this webpage.

Reference

Gocic, M. and Trajkovic, S. (2012) Analysis of changes in meteorological variables using Mann-Kendall and Sen’s slope estimator statistical tests in Serbia. Elsevier
https://www.academia.edu/6955354/Trend_Analysis_MK_Sen_Slope

46 thoughts on “Mann-Kendall Test”

  1. Can you please tell me in the experiments of Theil-Sen Median slope estimation and Mann-Kendall trend analysis, there are some points in my raster data where some of the year’s values are missing, do I need to go ahead and ignore the value of this point in the whole time series or do I have to calculate it by taking the mean or by keeping the NaN.

    Reply
  2. Thanks for this wonderful article! I’m still reviewing the equations for the Mann-Kendall test and am a bit confused still on tied values and how variance in my data will affect how the test determines trend. For example, if I’m looking to determine if there’s a trend in monthly or seasonal volumes of a river (i.e. calculating volume for a specific month or season for each year and then running the Mann-Kendall test), will the trend be more easily determined in months where there are lower volumes and therefore lower variance in the dataset like in the summer versus say May where flows and therefore variance is much higher during spring runoff?

    Reply
    • Nick,
      This seems to be a judgement call, and depends on which approach better captures the study you are undertaking. You can also provide multiple approaches. The most important thing is to not perform multiple tests and pick the one that confirms your preconceived hypothesis.
      Charles

      Reply
  3. Hi Charles,

    Great example – thanks!

    I had a question though regarding the example shown. If the alpha is 0.05 but in the example you are performing a two sided test, should the trend formula not be comparing it against 0.025? Apologies if I’ve got this totally mixed up.

    Reply
  4. Hi Charles

    There is a typo in the first equation – should be “i” instead of “k”.
    Otherwise, great article and great project.
    Very helpful for “homemade wannabe experts in statistics” like me.

    Kind regards
    Valentine

    Reply
  5. Hello,
    I have a general question about the Mann-Kendall test. I use the SeasonalMannKendall test in R to calcualte the tau statistics and 2-sided p-value, and Thiel-San slope to evaluate long term environemtnal trends. The seasonal flavor of the test eliminates the issue of autocorrelation. There is an argument about the need to calculate the gamma statistic (see for example page 4 in https://www.sciencedirect.com/science/article/pii/S1470160X22004617?via%3Dihub. Given that Mann-Kendall is a non-parametric, ranking method, do you think this is necessary?

    Reply
  6. Dear Charles,
    I’m using the Mann-Kendall Sens slope routine and have a few questions/comments (got the program to load fine after troubleshooting – thanks!).

    1. Is the MK Stat in the output equivalent to S?
    2. How is the MK Stat related to tau?
    3. How is either tau or the MK Stat related to Sen’s slope?
    4. When I downloaded your example file Mann-Kendall-Test there are quite a few #NAME? entries.
    5, Also, your algorithm assumes points are equidistant right? Mine are, but others might not be.

    Reply
  7. Hi Charles . I wonder if you could help me. I have downloaded the excel spreadsheet for Mann-Kendal Test but I am getting” #name” in cells that are supposed to show calculations? What I am doing wrong? I check the formulas , they seem to be correct. hanks

    Reply
  8. Dear Charles,

    I have 30 year period rainfall data and Can I use monthly data for MK test or do I use daily data for the MK test?

    Reply
  9. Dear Charles
    I want to learn Mann Kendall test for my data. Could you suggest me some video links where step by step demonstrations with explanation is there?
    Thank you
    Pranamika

    Reply
  10. Hi Charles,
    Can you explain how do we “read” the formula =IF(ROW(D4)-ROW(D$4)>COLUMN(D4)-COLUMN($D4),SIGN($C4-D$3),””)?
    thanks

    Reply
    • Hi Natalia,
      The formula =IF(ROW(D4)-ROW(D$4)>COLUMN(D4)-COLUMN($D4),SIGN($C4-D$3),””) is equivalent to =IF(0>0,SIGN($C4-D$3),””), which takes the value “” since 0>0 is clearly false.
      The important thing about this formula is that when it is copied into the other cells in the range under consideration it does what is needed.
      Charles

      Reply
  11. Hello Charles,
    Thank you so much for making these tools available. My question:
    I have the following data:
    9.61
    9.64
    9.7
    9.98
    9.88
    9.58
    9.98
    10.15
    The p-value produced by the data analysis tool is 0.080905; no trend. My understanding from above is that the p-value for the one-sided test is 1/2 that number, which is less than alpha 0.05 and would indicate a trend, would it not?

    Thank you,
    Cheryl

    Reply
    • Hi Cheryl,
      Yes, but you need to decide in advance whether you have ruled out one of the directions for the trend (either upward or downward). You can’t do this after the fact; otherwise, you would always use a one-sided test if you preferred a significant result.
      Charles

      Reply
    • Yes, you are correct. I have now made the change on the webpage.
      Actually, I used the correct formula on the worksheet but made a mistake when copying it to the webpage.
      In any case, thank you very much for identifying this mistake and improving the accuracy of the information provided.
      Charles

      Reply
  12. Is this formula ok: =IF(D18=0,0,D18*(D18+1)*(2*D18+7))? – why is there +7
    Shouldn’t it be: =IF(D18=0,0,D18*(D18+1)*(2*D18+5)) – in article it is +5

    thanks
    Peter

    Reply
    • The formula is f(f-1)(2f+5) where f is the ties frequency. The spreadsheet uses d = f-1 and so this makes the formula
      f(f-1)(2f+5) = (d+1)d[(2(d+1)+5] = d(d+1)(2d+7).
      Charles

      Reply
      • Hi Charles,
        I am trying to look at a trend using a moving average. And I understood that by using the same values multiple times in my time series (moving average) I create an artificially high level of significance. The paper suggest to adjust the degree of freedom to increase the p value in a linear regression to reduce the problem and I was wondering how to do that with the MK test.

        Reply
    • Sorry, there is a typo. Cell D18 contains the formula =D17 (not E17).
      I have now corrected this on the webpage.
      Thank you for finding this error. I appreciate your help in improving the accuracy of the Real Statistics website.
      Charles

      Reply

Leave a Comment