The Mann-Kendall trend test, named after H. A. Mann and D. R. Kendall, It’s non-parametric test used to determine the trend to be significant overtime. The trend can be monotonically increasing or decreasing overtime. Since it is non-parametric test so we don’t have to worry about distribution of the data. But the data should not have serial correlation/Autocorrelation (the error term in time series transfer from one period to another).
The Mann-Kendall test is designed to detect monotonic trends, which are trends that consistently increase or decrease over time, without assuming any specific distribution for the data. It is particularly useful when dealing with data that may not meet the assumptions of parametric tests, such as normality.
This article was published as a part of the Data Science Blogathon.
If you have very small samples as small as 3 or 4, then there is high probability of not finding any trend. The more samples we have overtime, the more reliable will be the test statistics. Though test can be performed with very sample samples as well. The recommended data is therefore at least 10.
In this article, we study the accidents related to derailments of our train over time. Recent train derailment in Odisha has again questioned about safety in railways. Railway accidents may be classified by their accident types (examples head on collisions, rear-end collisions, explosions, side collisions, derailments, fires etc.). Over time there have been many improvements in railways technically and infrastructure-wise. With all modern advancement in place yet train accidents are common across the world. Train accidents are unfortunate incidents that occur in railway systems around the world. These accidents can have devastating consequences, leading to loss of life, injuries, and damage to property.
In this study, we will determine, overtime, have we been able to reduce the train accidents (we will study derailments category of accident here) in India given all the advancements made over the years. The data we have procured about derailments in India is time series in nature. We have data of derailments from 2001 to 2016. The data is arranged in a chronological order.
Year | Derailments |
2001 | 350 |
2002 | 280 |
2003 | 218 |
2004 | 202 |
2005 | 138 |
2006 | 131 |
2007 | 96 |
2008 | 100 |
2009 | 85 |
2010 | 80 |
2011 | 80 |
2012 | 55 |
2013 | 49 |
2014 | 53 |
2015 | 63 |
2016 | 65 |
From the above table we can clearly see a decreasing trend in the data. Since 2001 the number of derailments has reduce to a very great extent. In 2001, we had 350 derailment related accidents which has reduced to 65 in 2016. Since the data is arranged in order, we can directly feed it in python environment and work on it. Let’s have a plot to visualize the data properly in python.
!pip install seaborn
import seaborn as sns
import matplotlib.pyplot as plt
fig = plt.subplots(figsize=(20, 5))
sns.lineplot(x='Year', y='Derailments', data=df)
sns.set_theme(style='white', font_scale=3)
From the above plot, we can clearly see there is decline trend. But can we say this declining trend is significant. Though it is evident from the plot highly
likely to be significant. Let’s check the same using Mann-Kendall trend hypothesis testing.
import pandas as pd
df=pd.read_csv("C:\\Users\\DELL\\OneDrive\\Desktop\\AnalyticsVidhya\\derailment.csv")
df.head()
Year | Derailments | |
---|---|---|
0 | 2001 | 350 |
1 | 2002 | 280 |
2 | 2003 | 218 |
3 | 2004 | 202 |
4 | 2005 | 138 |
!pip install pymannkendall
import numpy as np
import pymannkendall
mk.original_test(df["Derailments"])
The trend is decreasing, P-Value is highly significant. Hence we reject the null Hypothesis and conclude that the train derailments has significantly reduced over time. The Technical advancement and Infrastructural change has lead to significant reduction of derailment related accidents.
A. The Mann-Kendall test is a non-parametric or distribution-free test, meaning it does not assume any specific probability distribution for the data. It is also not affected by outliers. Though, it assumes that the observations are independent and that there are no serial correlation in the data.
A. The test generates the no. of concordant and discordant pairs within the time series data. It uses these pairs to compute a test statistic that follows a normal distribution under the null hypothesis of no trend. The test statistic is then compared to critical values to determine if the trend is statistically significant.
A. Any time series related data can be tested for monotonously significant. For example the temperature across the world is increasing can be tested (Global warming Phenomenon), ice-berg is melting faster, the sea-level is monotonously increasing, islands has disappeared overtime. In the medical field- More number of patient are being diagnosed with diabetes, heart failure problem, obesity.
A. Yes, it can determine the direction of the trend. The sign of the test statistic (positive or negative) indicates the direction of the trend: positive for an increasing trend and negative for a decreasing trend. A test statistic of zero suggests no trend.
A. Alternative trend tests, such as the Sen’s slope estimator, the Spearman’s rank correlation test, and the Theil-Sen estimator have different assumptions. Maybe more suitable depending on the specific characteristics of the data or research question.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.