# Mann-Kendall test in R using 'Kendall' package: exact test or approximation?

Problem: I am trying to perform a test for trend using the MannKendall() function available in the Kendall R package. My number of data points is n=11. For this reason, I would prefer an exact test, however I am unable to find in the documentation if the MannKendall() function performs an exact test or if it uses a normal approximation.

In the literature I find that for n <=10 an exact test is done, and for n>10 an approximation is used. I'm wondering if this is what the function does?

MannKendall calls Kendall which calls the FORTRAN routine TAUK2.

You can find out the details by reading the FORTRAN source of TAUK2 at this link on Github. Based on the comments in the code, I think it performs the exact test if the data x has no ties and uses the normal approximation otherwise, but you should probably check this as I don't know anything about these methods. (It also gives a reference to a book by Kendall.)

This comment appears on line 29:

c sw is true if at least one of X or Y has no ties


(but here, one of the vectors is just 1:N and the other is the data) and then later:

C USE EXACT METHOD IF THERE ARE NO TIES
C
If (sw) Then
C
C CALCULATE P-VALUE USING EXACT METHOD
C
IS = IFIX(S)
PROB = 1.0 - PRTAUS(IS,N,IER1)
If (IER1.EQ.0) Then
SLTAU = 2.0 * PROB
If (PROB.GE.0.5) SLTAU = 2.0 * (1.0-PROB)
Return
Endif
C
C IF THERE ARE TIES, NEED ATLEAST SAMPLE SIZE OF ATLEAST 3
C
Elseif (N.GT.3) Then
C
C USE CONTINUITY CORRECTION FOR S
SCOR = 0.0
If (S.GT.0) SCOR = S - 1.0
If (S.LT.0) SCOR = S + 1.0
C CALCULATE P-VALUE USING NORMAL APPROXIMATION
ZSCORE = SCOR / SDS
PROB = ALNORM(ZSCORE,.FALSE.)
SLTAU = 2.0 * PROB
If (PROB.GE.0.5) SLTAU = 2.0 * (1.0-PROB)
Return
Endif
Endif

• This seems to be the code for the Kendall function in the package not the MannKendall function? – DanRoDuq Feb 18 '16 at 4:06
• The ManKendall function is just function (x){Kendall(1:length(x), x)} – Flounderer Feb 18 '16 at 4:13

Using the information provided by Flounderer, I think I finally understand.

By typing MannKendall into R, I indeed get that the function is really calling the Kendall function as Kendall(1:length(x), x).

The Kendall function requires various considerations. In my case, the values of X have no ties.

Case 1: No Ties:

Subcase 1: length(x)<9: In this case the probabilities are computed using a recurrence relation described in kaarsemaker and van wijngaarden 1953.

Subcase 2: length(x)>=9: In this case the probabilities are calculated using a modified edgeworth series. What is important to note here is that I don't think any asymptotics are being called, but rather you are approximating the cumulative probability density by truncating an infinite series. This method is presented in Best and Gipps (1974). In the paper, they mention that the maximum error for any probability is 0.0004.

Case2 : There are ties: This is the case in which asymptotics are called in order to use a normal approximation. The details are explained in the R CRAN package documentation.