nestedRanksTest_Z: Calculates Z-score from ranks.

Description Usage Arguments Details Value See Also


nestedRanksTest_Z is used by nestedRanksTest to calculate the Z-score for the ranks of responses y divided into two treatment levels.


nestedRanksTest_Z(y, n1, n2)



Values to be ranked for the test. Its length must be equal to the sum of n1 and n2.


The first n1 values in y belong to the first treatment level.


The final n2 values in y belong to the second treatment level.


Values across both treatments are ranked using the base R function rank with ties.method = "average", which assigns tied values their average rank. The Mann-Whitney-Wilcoxon test statistic is computed from these ranks. Because the value of the statistic is sample-size dependent (between -n1*n2 and n1*n2), it is scaled to be [-1,+1] by dividing by n1*n2.

The bottleneck for bootstrapping is calculation of ranks, so the most straightforward way to speed up nestedRanksTest would come from speeding up rank. Because of the checks performed prior to calling this routine, it should be sufficient to use a stripped-down function that simply does the equivalent of making an .Internal call, which is not allowed within package code. As of this writing, this is sufficient:

rank_new <- function (x) .Internal(rank(x, length(x), "average"))

For the example data this is 8-9 times faster than the base R rank, because it avoids error-checking overhead. For longer vectors, the advantage decreases such that at 10000 elements it is 20-30%.


The calculated Z-score

See Also

nestedRanksTest, wilcox.test

nestedRanksTest documentation built on May 2, 2019, 10:43 a.m.