4.0

4.0 | 1 rating Rate this file 56 Downloads (last 30 days) File Size: 1.93 KB File ID: #25531

Mann-Kendall Test

by

 

Mann-Kendall non-parametric trend test.

| Watch this File

File Information
Description

The code performs original two tailed Mann-Kendall test. It tests the null hypothesis of trend absence in the vector V, against the alternative of trend.
The result of the test is returned in H = 1 indicates a rejection of the null hypothesis at the alpha significance level. H = 0 indicates a failure to reject the null hypothesis at the alpha significance level.

Required Products Statistics Toolbox
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
25 Sep 2014 Hydro

I found exactly what i was doing..however, i am getting an error message of too many output argument.Any help would be appreciated.

function [H,P] = mann_kendall(x,alpha)
if nargin<2;
alpha=0.05;
end
n=length(x);
i=0; j=0; S=0;
alpha=alpha/2;

for i = 1:n-1
for j=i+1:n
S = S + sign(x(j) - x(i));
end
end

VS=(n*(n-1))*(2*n+5)/18; % Variance
De=sqrt(VS); % Standard Deviation

if S >= 0;
Z=((S-1)/De)*(S~=0);
else
Z=((S+1)/De);
end

P=2*(1-normcdf(abs(Z),0,1)); % tail on both side
pz = norminv(1-alpha,0,1);
H=abs(Z)> pz;

end

01 Oct 2013 Roque Santos

Hello,

Is showing an error that says: "Undefined function 'Mann_Kendall_Modified' for input arguments of type 'double'."

How do I correct?

30 Mar 2013 Ehsan Jalilvand

Hi Simone,
First of all thank you. I've made some minor change to your code as follow,to include tied groups in Calculating the variance:
after line 48:
% Determining the variance (tied group included)
h=1;
while ~isempty(V)
g=find(V==V(1));
tp=length(g);
Sum(h)=tp*(tp-1)*(2*tp+5);
V(g)=[];
h=h+1;
end
VarS=((n*(n-1)*(2*n+5))-sum(Sum))/18;

Ehsan

26 Feb 2013 Brian Novak

Vectorizing the inner loop in the double sum for calculating S speeds it up significantly:

for i = 1:n-1
S = S + sum(sign(V(i+1:n) - V(i)));
end

25 May 2012 Janak

Hi Fatichi,

I want to run your code for trend analysis. I have matlab 11 and statistical tool box in my computer. Can you provide example data file for this code.

Ram

04 Mar 2011 Hari

Hi, Simone Fatichi,

I am new to Mat lab.Please tell me how to give input data and run your Mann_Kendall.m code using Mat lab.

10 Nov 2009 Hanna Modin

Thank you!

It is working very well and is very convenient to use since it returns the result of the hypothesis test, not just the test statistic. But: the alternative of S = 0 --> Z = 0 is not accounted for if I'm right.

For future updates I would also wish for a default significance level (for convenience). And perhaps a mention in the help text that there should be no autocorrelation in residuals.

Contact us