# Mann Kendall Test - Sen's Slope

**URL:** <https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038>\
**Category:** Statistics\
**Tags:** package\
**Created:** [April 11, 2021, 3:08pm UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038 "2021-04-11T15:08:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mixstam1453](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mixstam1453/32/23731_2.png) [@mixstam1453](https://discourse.julialang.org/u/mixstam1453)\
**Post date:** [April 11, 2021, 3:08pm UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038/1 "2021-04-11T15:08:14Z")

</div>

Hello to everyone,

Let’s suppose we have 3-hourly fluxes of solar radiation at surface, for a period 1980-2020.  
I want to apply Mann Kendall Test to this time-series and find the Sen’s slope, intercept, p\_value and tau.  
I am new user and i don’t find any package to calculate this. Have you any Julian suggestions ? ?  
I know about python’s pymannkendall, that gives that i want, but when i PyCall it, it gives me error (too large iterator) for the whole time series period. However when i use it for the half period for example, it works fine…

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [April 22, 2021, 12:45pm UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038/2 "2021-04-22T12:45:13Z")

</div>

Hello,

just got your email 🙂

As far as I know, there is nothing coded right now in Julia. There is this Matlab Toolbox/code:

> **[Mann-Kendall Tau-b with Sen's Method (enhanced)](https://www.mathworks.com/matlabcentral/fileexchange/11190-mann-kendall-tau-b-with-sen-s-method-enhanced?s_tid=mwa_osa_a)**
>
> A non-parametric trend test including Sen's slope method using Mann-Kendall Tau technique

The license allows for redistribution in code or binary form provided you keep the copyrights, etc…

It is about 250 lines of code, so might be “straightforward” to recode it from this source?

---

<div class="post-metadata">

**Author:** ![mixstam1453](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mixstam1453/32/23731_2.png) [@mixstam1453](https://discourse.julialang.org/u/mixstam1453)\
**Post date:** [April 23, 2021, 5:46am UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038/3 "2021-04-23T05:46:57Z")

</div>

Hi,  
thanks for your advice.  
I will start to recode it.

---

<div class="post-metadata">

**Author:** ![mixstam1453](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mixstam1453/32/23731_2.png) [@mixstam1453](https://discourse.julialang.org/u/mixstam1453)\
**Post date:** [April 26, 2021, 8:09am UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038/4 "2021-04-26T08:09:38Z")

</div>

Hello,  
Here is the non parametric Mann-Kendall Test and Sen’s slope for Julia:  
[https://github.com/mixstam1821/Mann\_Kendall.jl/blob/main/Mann\_Kendall.jl](https://github.com/mixstam1821/Mann_Kendall.jl/blob/main/Mann_Kendall.jl)

As you can see input/output is sth like this:  
julia\> mk(x,y)  
(reject\_null\_hypothesis = false, p\_value = 0.4369827573849885, Tau = -0.02374739039665971, slope = -7.613151196044908e-5, intercept = 0.5150870782436969)

BUT, the issue now is that when my dataset is too large this function is too slow or give OutOfMemory Error. Too large i mean the length is ~10,000 in 1GB RAM, or 200,000 for 32 GB.

However, with the same length, the GLM.jl [lm = fit(LinearModel, @formula(y ~ x),df)] works fine !  
So, i think that with some way, someone, can modify this function in order to win these memory issues.  
I would greatly appreciate if anyone could find a solution to this.

Cheers, Michael

---

<div class="post-metadata">

**Author:** ![Eric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eric/32/25565_2.png) [@Eric](https://discourse.julialang.org/u/Eric)\
**Post date:** [May 31, 2021, 9:55pm UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038/5 "2021-05-31T21:55:58Z")

</div>

Hi Michael,  
I was intrigued by your question and tried to get information on how it was implemented. I stumbled upon the following articles:

- [Frontiers | Re-evaluation of the Power of the Mann-Kendall Test for Detecting Monotonic Trends in Hydrometeorological Time Series](https://www.frontiersin.org/articles/10.3389/feart.2020.00014/full)
- [Design Trend Mann-Kendall](https://vsp.pnnl.gov/help/vsample/design_trend_mann_kendall.htm)

They seem to indicate additional terms in the definition of the variance about the tied groups of values. (or is it what you mean by your comment in the code indicating the coefficient is not adjusted for ties?)  
If you need to modify the variance in that way, that will likely introduce some extra complexity.

I hope it helps.

Eric

---

<div class="post-metadata">

**Author:** ![mixstam1453](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mixstam1453/32/23731_2.png) [@mixstam1453](https://discourse.julialang.org/u/mixstam1453)\
**Post date:** [June 1, 2021, 3:24pm UTC](https://discourse.julialang.org/t/mann-kendall-test-sens-slope/59038/6 "2021-06-01T15:24:06Z")

</div>

Hello,  
My definition don’t use tied groups, as i wrote in the comment for coefficient. Truly they modify the variance for tied groups. My “issue” isn’t the ties, but the length of data that when it is more than 10000 i get OutOfMemory Error, while with the same length GLM.jl works fine. So i am looking how to solve this memory issue.  
Thank you for your interest and congratulations for HoeffdingD.jl !

Cheers,  
Michael
