# Merger rank test


Find this notebook on the web at
<a class="quarto-xref" href="https://resampling-stats.github.io/edition-3-r/testing_counts_2.html#nte-merger_ranks">Note <span>23.8</span></a>.

Test whether observed mean rank is plausible in the null-world where
ranks are randomly drawn from 1 through 3.

```{r}
n_iters <- 10000

# Make array to store results for each trial.
results <- numeric(n_iters)

for (i in 1:n_iters) {
    ranks <- sample(c(1, 2, 3), size=33, replace=TRUE)
    mean_rank <- mean(ranks)
    results[i] <- mean_rank
}

hist(results, breaks=20,
     main='Mean ranks from random rank sampling')

k <- sum(results <= 1.48)
kk <- k / n_iters

message('Proportion of mean ranks <= 1.48: ', kk)
```
