Home » How to Perform a Mann-Kendall Trend Test in R

How to Perform a Mann-Kendall Trend Test in R

by Tutor Aspire

A Mann-Kendall Trend Test is used to determine whether or not a trend exists in time series data. It is a non-parametric test, meaning there is no underlying assumption made about the normality of the data.

The hypotheses for the test are as follows:

H0 (null hypothesis): There is no trend present in the data.

HA (alternative hypothesis): A trend is present in the data. (This could be a positive or negative trend)

If the p-value of the test is lower than some significance level (common choices are 0.10, 0.05, and 0.01), then there is statistically significant evidence that a trend is present in the time series data.

This tutorial explains how to perform a Mann-Kendall Trend Test in R.

Example: Mann-Kendall Trend Test in R

To perform a Mann-Kendall Trend Test in R, we will use the MannKendall() function from the Kendall library, which uses the following syntax:

MannKendall(x)

where:

  • x = a vector of data, often a time series

To illustrate how to perform the test, we will use the built-in PrecipGL dataset from the Kendall library, which contains information about the annual precipitation for all of the Great Lakes from the years 1900 to 1986:

#load Kendall library and PrecipGL dataset
library(Kendall)
data(PrecipGL)

#view dataset
PrecipGL

Time Series:
Start = 1900 
End = 1986 
Frequency = 1 
[1] 31.69 29.77 31.70 33.06 31.31 32.72 31.18 29.90 29.17 31.48 28.11 32.61
[13] 31.31 30.96 28.40 30.68 33.67 28.65 30.62 30.21 28.79 30.92 30.92 28.13
[25] 30.51 27.63 34.80 32.10 33.86 32.33 25.69 30.60 32.85 30.31 27.71 30.34
[37] 29.14 33.41 33.51 29.90 32.69 32.34 35.01 33.05 31.15 36.36 29.83 33.70
[49] 29.81 32.41 35.90 37.45 30.39 31.15 35.75 31.14 30.06 32.40 28.44 36.38
[61] 31.73 31.27 28.51 26.01 31.27 35.57 30.85 33.35 35.82 31.78 34.25 31.43
[73] 35.97 33.87 28.94 34.62 31.06 38.84 32.25 35.86 32.93 32.69 34.39 33.97
[85] 32.15 40.16 36.32
attr(,"title")
[1] Annual precipitation, 1900-1986, Entire Great Lakes

To see if there is a trend in the data, we can perform the Mann-Kendall Trend Test:

#Perform the Mann-Kendall Trend Test
MannKendall(PrecipGL)

tau = 0.265, 2-sided pvalue =0.00029206

The test statistic is 0.265 and the corresponding two-sided p-value is 0.00029206. Because this p-value is less than 0.05, we will reject the null hypothesis of the test and conclude that a trend is present in the data.

To visualize the trend, we can create a time series plot of the annual precipitation by year and add a smooth line to depict the trend:

#Plot the time series data
plot(PrecipGL)

#Add a smooth line to visualize the trend 
lines(lowess(time(PrecipGL),PrecipGL), col='blue')

Time series plot with smooth line

Note that we can also perform a seasonally-adjusted Mann-Kendall Trend Test to account for any seasonality in the data by using the SeasonalMannKendall(x) command:

#Perform a seasonally-adjusted Mann-Kendall Trend Test
SeasonalMannKendall(PrecipGL)

tau = 0.265, 2-sided pvalue =0.00028797

The test statistic is 0.265 and the corresponding two-sided p-value is 0.00028797. Once again this p-value is less than 0.05, so we will reject the null hypothesis of the test and conclude that a trend is present in the data.

You may also like