From 9f83b95c8a43f111bc5dbeb040940dac1a23d529 Mon Sep 17 00:00:00 2001 From: "Md. Manjurul Hussain Shourov" Date: Wed, 24 Jul 2019 00:03:59 +0600 Subject: [PATCH] Improving the write-up. --- Examples/Example_pyMannKendall.ipynb | 8 +-- Paper/paper.md | 33 ++++++------ README.md | 24 ++++----- pymannkendall/pymannkendall.py | 78 ++++++++++++++-------------- setup.py | 2 +- tests/test_pymannkendall.py | 8 +-- 6 files changed, 77 insertions(+), 76 deletions(-) diff --git a/Examples/Example_pyMannKendall.ipynb b/Examples/Example_pyMannKendall.ipynb index 1186272..384403b 100644 --- a/Examples/Example_pyMannKendall.ipynb +++ b/Examples/Example_pyMannKendall.ipynb @@ -14,7 +14,7 @@ "Three datasets are used here for demonstrating the use of this package. the datasets are\n", "- **Daily Female Births Dataset:** This dataset describes the number of daily female births in California in 1959. This dataset is available in [here](https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-total-female-births.csv).\n", "\n", - "- **Shampoo Sales Dataset:** This dataset describes the monthly number of sales of shampoo over a 3 year period. This dataset is available in [here](https://raw.githubusercontent.com/jbrownlee/Datasets/master/shampoo.csv)\n", + "- **Shampoo Sales Dataset:** This dataset describes the monthly number of sales of shampoo over 3 years. This dataset is available in [here](https://raw.githubusercontent.com/jbrownlee/Datasets/master/shampoo.csv)\n", "\n", "- **Air Passengers Dataset:** This famous dataset describes monthly international airline passengers (in thousands) from January 1949 to December 1960. It is widely used as a nonstationary seasonal time series. This dataset is available in [here](https://www.kaggle.com/freespirit08/time-series-for-beginners-with-arima/data)\n" ] @@ -171,7 +171,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "From this acf plot, here show slightly autocorrelation in the first lag. We can ignore it. So, in our demonstration, we *assume* that there is no autocorrelation in **Daily Female Births Dataset**. So, to check the trend in this dataset, we can use *Original Mann Kendall test*. " + "From this ACF plot, here show slightly autocorrelation in the first lag. We can ignore it. So, in our demonstration, we *assume* that there is no autocorrelation in **Daily Female Births Dataset**. So, to check the trend in this dataset, we can use the *Original Mann Kendall test*. " ] }, { @@ -334,7 +334,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "From this acf plot, here show autocorrelation in the first lag. So, modified Mann Kendall test should be applied in here. We can use **Hamed and Rao Modified MK Test**, **Yue and Wang Modified MK Test**, **Modified MK test using Pre-Whitening method** or **Modified MK test using Trend free Pre-Whitening method** for this Shampoo Sales Dataset." + "From this ACF plot, here show autocorrelation in the first lag. So, modified Mann Kendall test should be applied in here. We can use **Hamed and Rao Modified MK Test**, **Yue and Wang Modified MK Test**, **Modified MK test using Pre-Whitening method** or **Modified MK test using Trend free Pre-Whitening method** for this Shampoo Sales Dataset." ] }, { @@ -541,7 +541,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "From this figure, we clearly observed a noticeable seasonality. So we should use **Seasonal MK Test** for this monthly dataset. And Because of this dataset is monthly data, so here we use **period=12**." + "From this figure, we observed a noticeable seasonality. So we should use **Seasonal MK Test** for this monthly dataset. And Because of this dataset is monthly data, so here we use **period=12**." ] }, { diff --git a/Paper/paper.md b/Paper/paper.md index e55a2b7..b290517 100644 --- a/Paper/paper.md +++ b/Paper/paper.md @@ -22,38 +22,41 @@ bibliography: paper.bib # Summary -Trend analysis is one of the important measurements in studying time series data. Both parametric and non-parametric tests are commonly used in trend analysis. Parametric test require data to be independent and normally distributed. On the other hand, non-parametric trend tests require only that the data be independent and can tolerate outliers in the data [@hamed1998modified]. However, Parametric tests are more powerful than nonparametric ones. +Trend analysis is one of the important measurements in studying time series data. Both parametric and non-parametric tests are commonly used in trend analysis. Parametric test requires data to be independent and normally distributed. On the other hand, non-parametric trend tests require only that the data be independent and can tolerate outliers in the data [@hamed1998modified]. However, Parametric tests are more powerful than nonparametric ones. -The Mann–Kendall trend test [@mann1945nonparametric; @kendall1975rank] is one of the widely used non-parametric tests to detect significant trends in time series. However, the original Mann-Kendall test didn't consider serial correlation or seasonality effects [@bari2016analysis; @hirsch1982techniques]. But, in many real situations, the observed data are autocorrelated and this autocorrelation will result in misinterpretation of trend tests results [@hamed1998modified, @cox1955some]. Contrariwise, water quality, hydrologic, as well as climatic and other natural time series also have seasonality. To overcome those limitations of original Mann-Kendall test, various modified Mann-Kendall test have developed. +The Mann–Kendall trend test [@mann1945nonparametric; @kendall1975rank] is one of the widely used non-parametric tests to detect significant trends in time series. However, the original Mann-Kendall test didn't consider serial correlation or seasonality effects [@bari2016analysis; @hirsch1982techniques]. But, in many real situations, the observed data are autocorrelated and this autocorrelation will result in misinterpretation of trend tests results [@hamed1998modified, @cox1955some]. Contrariwise, water quality, hydrologic, as well as climatic and other natural time series also have seasonality. To overcome those limitations of original Mann-Kendall test, various modified Mann-Kendall test has developed. Again, Python is one of the widely used tools for data analysis. A large number of data analysis and research tools are also developed using python. But, till now, there is no Mann-Kendall trend relation python package available. ``pyMannKendall`` package is going to fill up this gap. ``pyMannKendall`` is written in pure python and use vectorization approach to increase its performance. Currently, this package has 11 Mann-Kendall Tests and 2 sen’s slope estimator function. Brief description of functions are below: -1. **Original Mann Kendall test (*original_test*):** Original Mann Kendall test [@mann1945nonparametric; @kendall1975rank] is a nonparametric test, which does not consider serial correlation or seasonal effects. +1. **Original Mann-Kendall test (*original_test*):** Original Mann-Kendall test is a nonparametric test, which does not consider serial correlation or seasonal effects. -2. **Hamed and Rao Modified MK Test (*hamed_rao_modification_test*):** This modified MK test proposed by Hamed and Rao [@hamed1998modified] to address serial autocorrelation issues. They suggested variance correction approach to improve trend analysis. User can consider first n significant lag by insert lag number in this function. By default, it considered all significant lags. +2. **Hamed and Rao Modified MK Test (*hamed_rao_modification_test*):** This modified MK test proposed by Hamed and Rao (1998) to address serial autocorrelation issues. They suggested a variance correction approach to improve trend analysis. User can consider first n significant lag by insert lag number in this function. By default, it considered all significant lags. -3. **Yue and Wang Modified MK Test (*yue_wang_modification_test*):** This is also a variance correction method for considered serial autocorrelation proposed by Yue, S., & Wang, C. Y. (2004) [@yue2004mann]. User can also set their desired significant n lags for the calculation. +3. **Yue and Wang Modified MK Test (*yue_wang_modification_test*):** This is also a variance correction method for considered serial autocorrelation proposed by Yue, S., & Wang, C. Y. (2004). User can also set their desired significant n lags for the calculation. -4. **Modified MK test using Pre-Whitening method (*pre_whitening_modification_test*):** This test suggested by Yue and Wang (2002) [@yue2002applicability] to using Pre-Whitening the time series prior to the application of trend test. +4. **Modified MK test using Pre-Whitening method (*pre_whitening_modification_test*):** This test suggested by Yue and Wang (2002) to using Pre-Whitening the time series before the application of trend test. -5. **Modified MK test using Trend free Pre-Whitening method (*trend_free_pre_whitening_modification_test*):** This test also proposed by Yue and Wang (2002) [@yue2002influence] to remove trend component and then Pre-Whitening the time series prior to application of trend test. +5. **Modified MK test using Trend free Pre-Whitening method (*trend_free_pre_whitening_modification_test*):** This test also proposed by Yue and Wang (2002) to remove trend component and then Pre-Whitening the time series before application of trend test. -6. **Multivariate MK Test (*multivariate_test*):** This is an MK test for multiple parameters proposed by Hirsch (1982) [@hirsch1982techniques]. Actually, he used this method for seasonal mk test, where he considered every month is a parameter. +6. **Multivariate MK Test (*multivariate_test*):** This is an MK test for multiple parameters proposed by Hirsch (1982). He used this method for seasonal mk test, where he considered every month as a parameter. -7. **Seasonal MK Test (*seasonal_test*):** For seasonal time series data, Hirsch, R.M., Slack, J.R. and Smith, R.A. (1982) [@hirsch1982techniques] proposed this test to calculate the seasonal trend. +7. **Seasonal MK Test (*seasonal_test*):** For seasonal time series data, Hirsch, R.M., Slack, J.R. and Smith, R.A. (1982) proposed this test to calculate the seasonal trend. -8. **Regional MK Test (*regional_test*):** Based on Hirsch (1982) [@hirsch1982techniques] proposed seasonal mk test, Helsel, D.R. and Frans, L.M., (2006) [@helsel2006regional] suggest regional mk test to calculate overall trend a regional scale. +8. **Regional MK Test (*regional_test*):** Based on Hirsch (1982) proposed seasonal mk test, Helsel, D.R. and Frans, L.M., (2006) suggest regional mk test to calculate the overall trend in a regional scale. -9. **Correlated Multivariate MK Test (*correlated_multivariate_test*):** This multivariate mk test proposed by Hipel (1994) [@hipel1994time] for when parameters are correlated. +9. **Correlated Multivariate MK Test (*correlated_multivariate_test*):** This multivariate mk test proposed by Hipel (1994) where the parameters are correlated. -10. **Correlated Seasonal MK Test (*correlated_seasonal_test*):** This method proposed by Hipel (1994) [@hipel1994time] used, when time series significantly correlated with the preceding one or more months/seasons. +10. **Correlated Seasonal MK Test (*correlated_seasonal_test*):** This method proposed by Hipel (1994) used, when time series significantly correlated with the preceding one or more months/seasons. -11. **Partial MK Test (*partial_test*):** In a real event, many factors are affecting the main studied response parameter, which can bias the trend results. To overcome this problem, Libiseller (2002) [@libiseller2002performance] proposed this partial mk test. It required two parameters as input, where, one is response parameter and other is an independent parameter. +11. **Partial MK Test (*partial_test*):** In a real event, many factors are affecting the main studied response parameter, which can bias the trend results. To overcome this problem, Libiseller (2002) proposed this partial mk test. It required two parameters as input, where, one is response parameter and other is an independent parameter. -12. **Theil–Sen’s Slope Estimator (*sens_slope*):** This method proposed by Theil (1950) [@theil1950rank] and Sen (1968) [@sen1968estimates] to estimate the magnitude of the monotonic trend. +12. **Theil-sen's Slope Estimator (*sens_slope*):** This method proposed by Theil (1950) and Sen (1968) to estimate the magnitude of the monotonic trend. -13. **Seasonal Sen’s Slope Estimator (*seasonal_sens_slope*):** This method proposed by Hipel (1994) [@hipel1994time] to estimate the magnitude of the monotonic trend, when data has seasonal effects. +13. **Seasonal sen's Slope Estimator (*seasonal_sens_slope*):** This method proposed by Hipel (1994) to estimate the magnitude of the monotonic trend, when data has seasonal effects. + + +`pyMannKendall` is a pure Python implemented non-parametric Mann-Kendall trend analysis package, which bring together almost all types of Mann-Kendall Test, which might help researchers to check the Mann-Kendall trend in python. # References \ No newline at end of file diff --git a/README.md b/README.md index 875a363..38495e0 100644 --- a/README.md +++ b/README.md @@ -7,28 +7,28 @@ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pymannkendall.svg)](https://pypi.org/project/pymannkendall/) [![status](http://joss.theoj.org/papers/14903dbd55343be89105112e585d262a/status.svg)](http://joss.theoj.org/papers/14903dbd55343be89105112e585d262a) -## What is the Mann Kendall Test ? -The Mann Kendall Trend Test (sometimes called the MK test) is used to analyze time series data for consistently increasing or decreasing trends (monotonic trends). It is a non-parametric test, which means it works for all distributions (i.e. data doesn't have to meet the assumption of normality), but data should have no serial correlation. If data has a serial correlation, it could be affected in significant level (p-value). That's why results might be misinterpreted. To overcome this problem, researchers proposed several modified Mann Kendall tests (Hamed and Rao Modified MK Test, Yue and Wang Modified MK Test, Modified MK test using Pre-Whitening method etc.). Seasonal Mann Kendall test also developed to remove the effect of seasonality. +## What is the Mann-Kendall Test ? +The Mann-Kendall Trend Test (sometimes called the MK test) is used to analyze time series data for consistently increasing or decreasing trends (monotonic trends). It is a non-parametric test, which means it works for all distributions (i.e. data doesn't have to meet the assumption of normality), but data should have no serial correlation. If the data has a serial correlation, it could affect in significant level (p-value). It could lead to misinterpretation. To overcome this problem, researchers proposed several modified Mann-Kendall tests (Hamed and Rao Modified MK Test, Yue and Wang Modified MK Test, Modified MK test using Pre-Whitening method, etc.). Seasonal Mann-Kendall test also developed to remove the effect of seasonality. -Mann Kendall Test is a powerful trend test, so several others modified Mann Kendall tests like Multivariate MK Test, Regional MK Test, Correlated MK test, Partial MK Test etc. were developed for the spacial condition. `pyMannkendal` is a pure Python implementation of non-parametric Mann Kendall trend analysis, which bring together almost all types of Mann Kendall Test. Currently, this package has 11 Mann-Kendall Tests and 2 sen's slope estimator function. Brief description of functions are below: +Mann-Kendall Test is a powerful trend test, so several others modified Mann-Kendall tests like Multivariate MK Test, Regional MK Test, Correlated MK test, Partial MK Test, etc. were developed for the spacial condition. `pyMannkendal` is a pure Python implementation of non-parametric Mann-Kendall trend analysis, which bring together almost all types of Mann-Kendall Test. Currently, this package has 11 Mann-Kendall Tests and 2 sen's slope estimator function. Brief description of functions are below: -1. **Original Mann Kendall test (*original_test*):** Original Mann Kendall test is a nonparametric test, which does not consider serial correlation or seasonal effects. +1. **Original Mann-Kendall test (*original_test*):** Original Mann-Kendall test is a nonparametric test, which does not consider serial correlation or seasonal effects. -2. **Hamed and Rao Modified MK Test (*hamed_rao_modification_test*):** This modified MK test proposed by Hamed and Rao (1998) to address serial autocorrelation issues. They suggested variance correction approach to improve trend analysis. User can consider first n significant lag by insert lag number in this function. By default, it considered all significant lags. +2. **Hamed and Rao Modified MK Test (*hamed_rao_modification_test*):** This modified MK test proposed by Hamed and Rao (1998) to address serial autocorrelation issues. They suggested a variance correction approach to improve trend analysis. User can consider first n significant lag by insert lag number in this function. By default, it considered all significant lags. 3. **Yue and Wang Modified MK Test (*yue_wang_modification_test*):** This is also a variance correction method for considered serial autocorrelation proposed by Yue, S., & Wang, C. Y. (2004). User can also set their desired significant n lags for the calculation. -4. **Modified MK test using Pre-Whitening method (*pre_whitening_modification_test*):** This test suggested by Yue and Wang (2002) to using Pre-Whitening the time series prior to the application of trend test. +4. **Modified MK test using Pre-Whitening method (*pre_whitening_modification_test*):** This test suggested by Yue and Wang (2002) to using Pre-Whitening the time series before the application of trend test. -5. **Modified MK test using Trend free Pre-Whitening method (*trend_free_pre_whitening_modification_test*):** This test also proposed by Yue and Wang (2002) to remove trend component and then Pre-Whitening the time series prior to application of trend test. +5. **Modified MK test using Trend free Pre-Whitening method (*trend_free_pre_whitening_modification_test*):** This test also proposed by Yue and Wang (2002) to remove trend component and then Pre-Whitening the time series before application of trend test. -6. **Multivariate MK Test (*multivariate_test*):** This is an MK test for multiple parameters proposed by Hirsch (1982). Actually, he used this method for seasonal mk test, where he considered every month is a parameter. +6. **Multivariate MK Test (*multivariate_test*):** This is an MK test for multiple parameters proposed by Hirsch (1982). He used this method for seasonal mk test, where he considered every month as a parameter. 7. **Seasonal MK Test (*seasonal_test*):** For seasonal time series data, Hirsch, R.M., Slack, J.R. and Smith, R.A. (1982) proposed this test to calculate the seasonal trend. -8. **Regional MK Test (*regional_test*):** Based on Hirsch (1982) proposed seasonal mk test, Helsel, D.R. and Frans, L.M., (2006) suggest regional mk test to calculate overall trend a regional scale. +8. **Regional MK Test (*regional_test*):** Based on Hirsch (1982) proposed seasonal mk test, Helsel, D.R. and Frans, L.M., (2006) suggest regional mk test to calculate the overall trend in a regional scale. -9. **Correlated Multivariate MK Test (*correlated_multivariate_test*):** This multivariate mk test proposed by Hipel (1994) for when parameters are correlated. +9. **Correlated Multivariate MK Test (*correlated_multivariate_test*):** This multivariate mk test proposed by Hipel (1994) where the parameters are correlated. 10. **Correlated Seasonal MK Test (*correlated_seasonal_test*):** This method proposed by Hipel (1994) used, when time series significantly correlated with the preceding one or more months/seasons. @@ -40,14 +40,14 @@ Mann Kendall Test is a powerful trend test, so several others modified Mann Kend ## Function details: -All Mann-kendall test functions has almost similer input parameters. Those are: +All Mann-Kendall test functions have almost similar input parameters. Those are: - **x**: a vector of data - **alpha**: significance level (0.05 default) - **lag**: No. of First Significant Lags (Only available in hamed_rao_modification_test and yue_wang_modification_test) - **period**: seasonal cycle. For monthly data it is 12, weekly data it is 52 (Only available in seasonal tests) -And all Mann-kendall tests return a named tuple which contained: +And all Mann-Kendall tests return a named tuple which contained: - **trend**: tells the trend (increasing, decreasing or no trend) - **h**: True (if trend is present) or False (if trend is absence) diff --git a/pymannkendall/pymannkendall.py b/pymannkendall/pymannkendall.py index 5fbf3f7..55085bb 100644 --- a/pymannkendall/pymannkendall.py +++ b/pymannkendall/pymannkendall.py @@ -1,11 +1,9 @@ """ Created on 05 March 2018 -Update on 30 June 2019 +Update on 23 July 2019 @author: Md. Manjurul Hussain Shourov -version: 1.0 +version: 1.1 Approach: Vectorisation - -Remark: Full 11 mk test and 2 sens slope funtion is complete. Need to optimaze and speed up this code, """ from __future__ import division @@ -72,7 +70,7 @@ def __mk_score(x, n): return s -# original mann-kendal's variance S calculation +# original Mann-Kendal's variance S calculation def __variance_s(x, n): # calculate the unique data unique_x = np.unique(x) @@ -163,7 +161,7 @@ def sens_slope(x): """ This method proposed by Theil (1950) and Sen (1968) to estimate the magnitude of the monotonic trend. Input: - x: a one dimentional vector (list, numpy array or pandas series) data + x: a one dimensional vector (list, numpy array or pandas series) data Output: slope: sen's slope Examples @@ -181,8 +179,8 @@ def seasonal_sens_slope(x, period=12): """ This method proposed by Hipel (1994) to estimate the magnitude of the monotonic trend, when data has seasonal effects. Input: - x: a one dimentional vector (list, numpy array or pandas series) data - period: seasonal cycle. For monthly data it is 12, weekly data it is 52 (12 is default) + x: a vector (list, numpy array or pandas series) data + period: seasonal cycle. For monthly data it is 12, weekly data it is 52 (12 is the default) Output: slope: sen's slope Examples @@ -210,14 +208,14 @@ def seasonal_sens_slope(x, period=12): def original_test(x, alpha = 0.05): """ - This function check Mann-Kendall (MK) test (Mann 1945, Kendall 1975, Gilbert 1987). + This function checks the Mann-Kendall (MK) test (Mann 1945, Kendall 1975, Gilbert 1987). Input: - x: a one dimentional vector (list, numpy array or pandas series) data + x: a vector (list, numpy array or pandas series) data alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -245,15 +243,15 @@ def original_test(x, alpha = 0.05): def hamed_rao_modification_test(x, alpha = 0.05, lag=None): """ - This function check Modified Mann-Kendall (MK) test using Hamed and Rao (1998) method. + This function checks the Modified Mann-Kendall (MK) test using Hamed and Rao (1998) method. Input: - x: a vector of data + x: a vector (list, numpy array or pandas series) data alpha: significance level (0.05 default) lag: No. of First Significant Lags (default None, You can use 3 for considering first 3 lags, which also proposed by Hamed and Rao(1998)) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -308,14 +306,14 @@ def hamed_rao_modification_test(x, alpha = 0.05, lag=None): def yue_wang_modification_test(x, alpha = 0.05, lag=None): """ - Input: This function check Modified Mann-Kendall (MK) test using Yue and Wang (2004) method. - x: a vector of data + Input: This function checks the Modified Mann-Kendall (MK) test using Yue and Wang (2004) method. + x: a vector (list, numpy array or pandas series) data alpha: significance level (0.05 default) lag: No. of First Significant Lags (default None, You can use 1 for considering first 1 lags, which also proposed by Yue and Wang (2004)) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -360,14 +358,14 @@ def yue_wang_modification_test(x, alpha = 0.05, lag=None): def pre_whitening_modification_test(x, alpha = 0.05): """ - This function check Modified Mann-Kendall (MK) test using Pre-Whitening method proposed by Yue and Wang (2002). + This function checks the Modified Mann-Kendall (MK) test using Pre-Whitening method proposed by Yue and Wang (2002). Input: - x: a vector of data + x: a vector (list, numpy array or pandas series) data alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics s: Mann-Kendal's score var_s: Variance S @@ -402,14 +400,14 @@ def pre_whitening_modification_test(x, alpha = 0.05): def trend_free_pre_whitening_modification_test(x, alpha = 0.05): """ - This function check Modified Mann-Kendall (MK) test using trend-free Pre-Whitening method proposed by Yue and Wang (2002). + This function checks the Modified Mann-Kendall (MK) test using the trend-free Pre-Whitening method proposed by Yue and Wang (2002). Input: - x: a vector of data + x: a vector (list, numpy array or pandas series) data alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics s: Mann-Kendal's score var_s: Variance S @@ -451,14 +449,14 @@ def trend_free_pre_whitening_modification_test(x, alpha = 0.05): def multivariate_test(x, alpha = 0.05): """ - This function check Multivariate Mann-Kendall (MK) test, which is originally proposed by R. M. Hirsch and J. R. Slack (1984) for seasonal Mann-Kendall test. Later this method also used Helsel (2006) for Regional Mann-Kendall test + This function checks the Multivariate Mann-Kendall (MK) test, which is originally proposed by R. M. Hirsch and J. R. Slack (1984) for the seasonal Mann-Kendall test. Later this method also used Helsel (2006) for Regional Mann-Kendall test. Input: x: a matrix of data alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -476,13 +474,13 @@ def multivariate_test(x, alpha = 0.05): denom = 0 x, c = __preprocessing(x) -# x, n = __missing_values_analysis(x, method = 'skip') # It make same column size +# x, n = __missing_values_analysis(x, method = 'skip') # It makes all column at the same size for i in range(c): if c == 1: - x_new, n = __missing_values_analysis(x, method = 'skip') # It make deferent column size + x_new, n = __missing_values_analysis(x, method = 'skip') # It makes all column at deferent size else: - x_new, n = __missing_values_analysis(x[:,i], method = 'skip') # It make deferent column size + x_new, n = __missing_values_analysis(x[:,i], method = 'skip') # It makes all column at deferent size s = s + __mk_score(x_new, n) var_s = var_s + __variance_s(x_new, n) @@ -500,15 +498,15 @@ def multivariate_test(x, alpha = 0.05): def seasonal_test(x, period = 12, alpha = 0.05): """ - This function check Seasonal Mann-Kendall (MK) test (Hirsch, R. M., Slack, J. R. 1984). + This function checks the Seasonal Mann-Kendall (MK) test (Hirsch, R. M., Slack, J. R. 1984). Input: x: a vector of data - period: seasonal cycle. For monthly data it is 12, weekly data it is 52 (12 is default) - alpha: significance level (0.05 default) + period: seasonal cycle. For monthly data it is 12, weekly data it is 52 (12 is the default) + alpha: significance level (0.05 is the default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -537,14 +535,14 @@ def seasonal_test(x, period = 12, alpha = 0.05): def regional_test(x, alpha = 0.05): """ - This function check Regional Mann-Kendall (MK) test (Helsel 2006). + This function checks the Regional Mann-Kendall (MK) test (Helsel 2006). Input: x: a matrix of data alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -565,14 +563,14 @@ def regional_test(x, alpha = 0.05): def correlated_multivariate_test(x, alpha = 0.05): """ - This function check Correlated Multivariate Mann-Kendall (MK) test (Libiseller and Grimvall (2002)). + This function checks the Correlated Multivariate Mann-Kendall (MK) test (Libiseller and Grimvall (2002)). Input: x: a matrix of data alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -626,7 +624,7 @@ def correlated_multivariate_test(x, alpha = 0.05): def correlated_seasonal_test(x, period = 12 ,alpha = 0.05): """ - This function check Correlated Seasonal Mann-Kendall (MK) test (Hipel [1994] ). + This function checks the Correlated Seasonal Mann-Kendall (MK) test (Hipel [1994] ). Input: x: a matrix of data period: seasonal cycle. For monthly data it is 12, weekly data it is 52 (12 is default) @@ -634,7 +632,7 @@ def correlated_seasonal_test(x, period = 12 ,alpha = 0.05): Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score @@ -664,14 +662,14 @@ def correlated_seasonal_test(x, period = 12 ,alpha = 0.05): def partial_test(x, alpha = 0.05): """ - This function check Partial Mann-Kendall (MK) test (Libiseller and Grimvall (2002)). + This function checks the Partial Mann-Kendall (MK) test (Libiseller and Grimvall (2002)). Input: x: a matrix with 2 columns alpha: significance level (0.05 default) Output: trend: tells the trend (increasing, decreasing or no trend) h: True (if trend is present) or False (if trend is absence) - p: p value of the significance test + p: p-value of the significance test z: normalized test statistics Tau: Kendall Tau s: Mann-Kendal's score diff --git a/setup.py b/setup.py index 20e65b3..72b433f 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ version = __version__, author = __author__, author_email = __email__, - description = ("A python package for non parametric mann kendall family of trend tests."), + description = ("A python package for non-parametric Mann-Kendall family of trend tests."), long_description = long_description, long_description_content_type = "text/markdown", url = "https://github.com/mmhs013/pymannkendall", diff --git a/tests/test_pymannkendall.py b/tests/test_pymannkendall.py index f3eb05b..c9874a1 100644 --- a/tests/test_pymannkendall.py +++ b/tests/test_pymannkendall.py @@ -1,4 +1,4 @@ -# In this unit test file, we check all functions with randomly generated No trendy, trendy, arbitrary data. Those results are compire with R package - modifiedmk, fume, rkt, trend. +# In this unit test file, we check all functions with randomly generated No trendy, trendy, arbitrary data. Those results are compared with R package - modifiedmk, fume, rkt, trend. import os import pytest @@ -7,13 +7,13 @@ @pytest.fixture def NoTrendData(): - # Generate 360 random value with same number + # Generate 360 random value with the same number NoTrendData = np.ones(360)*np.random.randint(10) return NoTrendData @pytest.fixture def NoTrend2dData(): - # Generate 2 dimentional 360 random value with same number + # Generate 2 dimensional 360 random value with same number NoTrend2dData = np.ones((360,2))*np.random.randint(10) return NoTrend2dData @@ -63,7 +63,7 @@ def arbitrary_1d_data(): @pytest.fixture def arbitrary_2d_data(): - # Generate arbitrary 80, 2 dimentional data + # Generate arbitrary 80, 2 dimensional data arbitrary_2d_data = np.array([[ 490., 458.], [ 540., 469.], [ 220., 4630.], [ 390., 321.], [ 450., 541.], [ 230., 1640.], [ 360., 1060.], [ 460., 264.], [ 430., 665.], [ 430., 680.], [ 620., 650.], [ 460., np.nan], [ 450., 380.], [ 580., 325.], [ 350., 1020.],