pyMannKendall
pyMannKendall is a Python package providing a comprehensive suite of non-parametric Mann-Kendall family of trend tests. It includes 11 different Mann-Kendall tests and 2 Sen's slope estimator functions, making it suitable for analyzing monotonic trends in time series data without assumptions about data distribution. The library is actively maintained, with version 1.4.3 released in early 2023, and receives regular updates to address bugs and introduce new features.
Warnings
- gotcha The original Mann-Kendall test assumes serially independent data. Applying it to autocorrelated time series can lead to an inflated Type I error rate (i.e., detecting a trend where none exists due to correlated noise), resulting in misinterpretation of p-values.
- gotcha The original Mann-Kendall test does not account for seasonality in time series data. Applying it directly to seasonal data can lead to erroneous trend detection or misinterpretation.
- gotcha Recent versions (v1.4.2, v1.4.3) have addressed bugs related to type data conversion and integer type data arrays. While fixed, this indicates potential sensitivity to input data types or formats in older versions or edge cases.
- gotcha Reliability of the Mann-Kendall test statistics decreases with very small sample sizes (e.g., 3 or 4 observations).
Install
-
pip install pymannkendall
Imports
- pymannkendall
import pymannkendall as mk
- original_test
mk.original_test(data)
Quickstart
import numpy as np
import pymannkendall as mk
# Sample time series data
data = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5])
# Perform the original Mann-Kendall trend test
result = mk.original_test(data)
print(f"Trend: {result.trend}")
print(f"P-value: {result.p}")
print(f"Kendall Tau: {result.Tau}")
print(f"Slope: {result.slope}")
# Output will indicate if a trend is present, its p-value, Tau, and Sen's slope.