I'm experimenting with different R packages to calculate trends using the Mann-Kendall test. However, I'm getting varying results in terms of S, tau, and p-value. I would like to understand the reasons behind this. Here's the code I've been using:

# Calculating trends with Mann-Kendall
resul1 <- MannKendall(na.exclude(valor))  

# Calculating trends using trend in Estanzuela Tx
result2 <- mk.test(na.exclude(valor), alternative = c("two.sided"), continuity = FALSE)

The results from the above code are as follows:

For the first method: Score = 3165784 , Var(Score) = 273891524608 denominator = 91198752 tau = 0.0347, 2-sided pvalue =< 2.22e-16

For the second method: Mann-Kendall trend test data: na.exclude(valor) z = 3.1231, n = 13508, p-value = 0.00179 alternative hypothesis: true S is not equal to 0 sample estimates: S varS tau 1.634429e+06 2.738855e+11 1.795539e-02

Could someone please explain why these discrepancies in results (S, tau, and p-value) occur between the two methods? Is it due to differences in implementation, handling of missing data, options, or some other factors?


1 Answer 1


You don't say what package you used to get either of the tests or the data, which makes it a bit hard.

I've found a function called MannKendall in the Kendall package and one called mk.test in the trend package. I can't find your data at all, so I used a built-in data set

> MannKendall(LakeHuron)
tau = -0.354, 2-sided pvalue =2.4718e-07
> mk.test(LakeHuron, alternative="two.sided",continuity=FALSE)

    Mann-Kendall trend test

data:  LakeHuron
z = -5.1629, n = 98, p-value = 2.432e-07
alternative hypothesis: true S is not equal to 0
sample estimates:
            S          varS           tau 
-1.682000e+03  1.061367e+05 -3.543667e-01 

These give the same values for tau and the $p$-value.

So maybe it's a missing-data issue

> a[4:17]<-NA
> mk.test(na.exclude(a))

    Mann-Kendall trend test

data:  na.exclude(a)
z = -2.5537, n = 84, p-value = 0.01066
alternative hypothesis: true S is not equal to 0
sample estimates:
            S          varS           tau 
 -662.0000000 66996.0000000    -0.1902302 

> MannKendall(a)
tau = -0.19, 2-sided pvalue =0.010657

and these still give the same answer.

Maybe if you can tell us the actual functions and data you used it will be possible to see the discrepancy you are seeing and then maybe explain it.

  • $\begingroup$ What about numerical issues? Are values on the scale of S = 3,165,784 and VarS = 273,891,524,608 "reasonable"? I'm not sure that I'd trust those numbers even if two different implementations reported them. $\endgroup$
    – dipetkov
    Aug 19, 2023 at 8:03
  • $\begingroup$ I am indeed using mk.test() from the "trends" package and Mann-Kendall from the "Kendall" package. I am analyzing a time series of daily temperature observations spanning 34 years, and I did indeed test with another dataset, and the results from both functions are nearly identical. Might be a numerical error that I might have overlooked. However, with the previous answer, I can confirm that both functions yield reliable results, and I can use either of these functions. $\endgroup$
    – Yil
    Aug 19, 2023 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.