How to Perform a Mann-Kendall Trend Test in R


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.

5 Replies to “How to Perform a Mann-Kendall Trend Test in R”

  1. The kendallSeasonalTrendTest from the EnvStats package is more flexible in that the time series data does not need to be in equal increments.

    1. Hi Anthony…Yes, the `kendallSeasonalTrendTest` function from the `EnvStats` package in R is quite versatile for analyzing time series data, particularly when dealing with environmental data where time intervals might not be evenly spaced. This function performs a seasonal Kendall trend test, which is a non-parametric test for identifying trends in seasonal data.

      Here’s a brief overview of how it works:

      ### Key Features:
      1. **Handles Unequal Time Increments**: Unlike some other trend analysis methods that require data to be evenly spaced in time, `kendallSeasonalTrendTest` allows for time series data with irregular intervals. This is particularly useful when dealing with real-world environmental data, where measurements may not be taken at consistent intervals.

      2. **Seasonal Adjustment**: The test accounts for seasonality by dividing the data into seasons (e.g., months, quarters) and assessing trends within each season. This helps to distinguish between seasonal effects and long-term trends.

      3. **Non-Parametric Test**: Since it’s a non-parametric test, it doesn’t assume a specific distribution for the data, making it robust to outliers and non-normality.

      ### Application:
      The `kendallSeasonalTrendTest` can be used in various fields, such as environmental science, hydrology, and ecology, where time series data often doesn’t follow regular intervals. For instance, you might have data on river flow rates measured at irregular intervals, and you want to determine if there’s a trend over time while accounting for seasonal variations.

      ### Example Usage:
      “`r
      # Example of using kendallSeasonalTrendTest
      library(EnvStats)

      # Sample data: River flow measurements at irregular intervals
      time_series_data <- data.frame( time = c(1, 2, 3, 7, 8, 10, 12, 14, 15), # Irregular time points flow_rate = c(120, 130, 125, 140, 145, 150, 155, 160, 165) # Measurements ) # Apply the kendallSeasonalTrendTest result <- kendallSeasonalTrendTest(flow_rate ~ time, data = time_series_data) # View the test result print(result) ``` This flexibility makes `kendallSeasonalTrendTest` a powerful tool for trend analysis, especially in scenarios where time series data are collected sporadically. If you have a specific dataset or scenario in mind where you'd like to apply this test, feel free to share, and I can assist further!

Leave a Reply

Your email address will not be published. Required fields are marked *