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)n1 and n2.n1 values in y belong to the
first treatment level.n2 values in y belong to the
second treatment level.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%.
nestedRanksTest, wilcox.test