Open lijuanyan122 opened 1 year ago
I can't see from your example
# For data with ties
x <- rep(1:4, 4)
g <- c(rep(57, 15), 59)
# The below p values based on normal approximation produced are different
DescTools::JonckheereTerpstraTest(x, g, exact=FALSE)
cor.test(x, g, method="kendall")
why the two functions should yield the same p-value. Are you aware that x is a numeric variable and g a grouping factor for JonckheereTerpstraTest and cor.test expects two variables x, y? Can you explain what you would expect? Thanks
First of all, thanks for responding to my question and sorry it took long to reply. I edited the code, so to better describe my question: https://gist.github.com/lijuanyan122/f0e3a8a520f47b238b44f30fa79d4b2c
In the documentation of DescTools::JonckheereTerpstraTest(), it is written that "the asymptotic version is equivalent to cor.test(x, g, method="k")." Therefore, I would expect that the p values produced by cor.test() and DescTools::JonckheereTerpstraTest() for the asymptotic version are the same. As expected, the JT test from another R package PMCMRplus::jonckheereTest() actually gives exactly the same result as cor.test(), no matter if the "g" is a grouping factor or integer --> I also checked the results with one standard software used for the statistical analysis of ecotoxicological data (ToxRat: https://www.toxrat.com/Home_en.html) and it gives the same p value as PMCMRplus::jonckheereTest().
So the discrepancies of results lie in the fact that "g" is treated as a factor all the time for DescTools::JonckheereTerpstraTest(), whereas it is treated as integer in PMCMRplus::jonckheereTest(), cor.test() and ToxRat??
When we have data with ties, the DescTools::JonckheereTerpstraTest() does not provide the same asymptotic p value as described in the documentation using cor.test(x, g, method="k"). Please see the code below.
https://gist.github.com/lijuanyan122/f0e3a8a520f47b238b44f30fa79d4b2c