# Ranking Values in the Wilcoxon Signed Rank Test

**URL:** <https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153>\
**Category:** Questions\
**Created:** [March 18, 2022, 1:35pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153 "2022-03-18T13:35:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davy\_B](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/davy_b/32/3264_2.png) [@Davy\_B](https://cl.desmos.com/u/Davy_B)\
**Post date:** [March 18, 2022, 1:35pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/1 "2022-03-18T13:35:17Z")

</div>

I’m working on a demonstration activity for the Wilcoxon Signed Rank Test. I’m stuck with a problem of ranking values in a table. For a list of values, say L = [5, 8, 13, 4, 7], I want to create a matching column ranking their distance from zero, which in the example would be R= [2, 4, 5, 1, 3] (i.e. 4 is closest to zero, then 5, then 7, and so on). I had hoped that “_sort([1…5], L)_” would give R but it actually produces [4,1,5,2,3] showing the rank order _positions_ in L (i.e. the smallest number is in position 4 in L, the second in position 1, and so on). It feels as if I’m close but not sure what to try next to produce the column I need. Can anyone nudge me in the right direction?

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [March 18, 2022, 7:55pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/2 "2022-03-18T19:55:59Z")

</div>

Someone may be able to spot something that we’re both missing, but in the meantime you can achieve what you want by running two sorts - so

```auto
sort(sort([1...5],L),L)

```

should do the trick.

---

<div class="post-metadata">

**Author:** ![Davy\_B](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/davy_b/32/3264_2.png) [@Davy\_B](https://cl.desmos.com/u/Davy_B)\
**Post date:** [March 18, 2022, 9:02pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/3 "2022-03-18T21:02:19Z")

</div>

Many thanks for the rapid response @pirsquared. Unfortunately, when I apply the double sort to the example L = [5, 8, 13, 4, 7], the result is [2, 4, 3, 1, 5]. That seems close to the expected result of [2, 4, 5, 1, 3] but that may be a coincidence, as the difference is more pronounced when I use a larger data set. It does feel that something like that should work?

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [March 18, 2022, 9:29pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/4 "2022-03-18T21:29:37Z")

</div>

Ah, yes! Sorry, didn’t spot that.

Again, someone might have a more elegant solution but I think this works:

```auto
R=[[1...length(L)][sort(L)=i][1] for i=L]

```

---

<div class="post-metadata">

**Author:** ![Davy\_B](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/davy_b/32/3264_2.png) [@Davy\_B](https://cl.desmos.com/u/Davy_B)\
**Post date:** [March 18, 2022, 10:21pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/5 "2022-03-18T22:21:51Z")

</div>

Excellent, that works! I still have a bit more adjustment to do for the Wilcoxon ranking (exclude zero values and rank identical values in a different way), which I’ll try myself, but may be back to tap further into your expertise if that’s okay. In the meantime, again thanks!

---

<div class="post-metadata">

**Author:** ![Davy\_B](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/davy_b/32/3264_2.png) [@Davy\_B](https://cl.desmos.com/u/Davy_B)\
**Post date:** [March 22, 2022, 3:38pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/6 "2022-03-22T15:38:18Z")

</div>

…Sorry @pirsquared, I’m back! I was rather hoping that I knew enough to adjust your solution

```auto
R=[[1...length(L)][sort(L)=i][1] for i=L]

```

to the form required for the Wilcoxon test but alas that hasn’t worked out. Applying your ranking to L=[8,13,13,15,19,19,19] produces R=[1,2,2,4,5,5,5] but with Wilcoxon, the required values would be R=[1,2.5,2.5,4,6,6,6]. i.e. where there are duplicates the ranking is “r+(n-1)\*0.5”, where “r” is the original rank value and “n” is the number of values with that ranking. I can identify the ranking duplicates and their frequency but I can work out how to replace the rankings in the original list with their revised values? Happy to be directed to a tutorial on this material to improve my understanding!

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [March 22, 2022, 4:21pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/7 "2022-03-22T16:21:07Z")

</div>

Here’s a workaround:

> **[Desmos | Graphing Calculator](https://www.desmos.com/calculator/jzyf8pwxul)**
>
> Explore math with our beautiful, free online graphing calculator. Graph functions, plot points, visualize algebraic equations, add sliders, animate graphs, and more.

---

<div class="post-metadata">

**Author:** ![Davy\_B](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/davy_b/32/3264_2.png) [@Davy\_B](https://cl.desmos.com/u/Davy_B)\
**Post date:** [March 22, 2022, 7:28pm UTC](https://cl.desmos.com/t/ranking-values-in-the-wilcoxon-signed-rank-test/4153/8 "2022-03-22T19:28:40Z")

</div>

Many thanks Daniel, that looks perfect! …and such a rapid response!! Hopefully, I’ll be able to finish this activity without further pleas for help, but let’s see. 😉
