# 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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7711478471755981, "perplexity": 1234.7223310022775}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-34/segments/1596439738944.95/warc/CC-MAIN-20200812200445-20200812230445-00051.warc.gz"}