$R$ gives "NA" for the p-value when I try to run Kendall's test with an "exact p-value" flag set on a larger data set (n=170 seems to be the cutoff). Is this just a computation problem or something deeper? Spearman's test with an exact p-value flag set returns a p-value.


         Kendall's rank correlation tau

 data:  sample(1:200) and sample(1:200)
 T = 10905, p-value = NA
 alternative hypothesis: true tau is not equal to 0
 sample estimates:
  • 1
    $\begingroup$ The approximation is close for large $n$. For example, if you were to start with something like set.seed(2022);n <- 170;A <- sample(1:n);B <- sample(1:n) then cor.test(A,B,method='kendall',exact=TRUE) gives p-value=0.08651 while cor.test(A,B,method='kendall',exact=FALSE) gives p-value=0.08626 $\endgroup$
    – Henry
    Jun 24, 2022 at 23:04
  • $\begingroup$ @Henry My qualm with the approximation is I couldn't tell from the man page what it was based on...if it's a CLT approximation, then my data might not be good for it. $\endgroup$
    – kara890
    Jun 25, 2022 at 4:19

1 Answer 1


I suspect it's a computational issue to do with how cor.test calculates the p-value for method = "Kendall".

If you have a look at lines 92 - 108 of the source code for cor.test, you'll notice that it calls stats:::C_pKendall to calculate the p-value.

If you then dig further and have a look at the source for C_pKendall, you'll notice that there is a division term with a denominator of gammafn(n + 1) in line 96. Now gamma(n) returns Inf for n >= 172 (for integer valued n) in R, so I suspect this division terms ends up becoming Inf / Inf = NaN for n = length(x) >= 172, resulting in a p-value of NaN.


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.