# Analysing a single ordinal variable

## 2a: Test for median (one-sample Wilcoxon signed rank test)

From the results in the previous parts we noticed in the example that not many people think accounting is scientific. However that was just based on a sample, and we would like to know how this would be in the population. Would the majority of people in the population also not see accounting as very scientific? The majority would be more than 50% of the people, so in other words, is the median (the score in the middle) in the populaiton significantly different from 2.5 (since 2 = pretty scientific, and 3 = not scientific)?

Two tests could be used for this, the first does exactly what is described above, and is known as a **sign-test**, however another test is more frequently used and has a lot scarier name: **one-sample Wilcoxon signed rank test** (Wilcoxon, 1945). This second test uses rankings (it ranks the scores) and because of this might give a slightly different result. The advantage of this second test is that it can catch some smaller differences and is the one I will explain here. If you are curious about what the Wilcoxon test does exactly I'd recommend this site. The appendix at the bottom of the page has some more information about the sign-test in case you are curious about it.

The significance of the Wilcoxon signed rank test will tell us how likely it is to have a result as in our sample, or even more extreme if the median in the population is indeed a certain value (in the example we use 2.5). If this chance is very low, the population mos likely has another median than the one expected.

In the example the significance is .000, which is usually considered very low. This indicates that the median is significantly different from 2.5, so it is unlikely that the median in the population is 2.5. In the report the results of the test could for example go like:

A one-sample Wilcoxon signed-rank test indicated that the median was significantly different from 2.5, *Z *= 11.93, *p* < .001.

**Click here to see how you can perform the test with SPSS, R (studio), Excel, Python or Manually.**

**with SPSS**

watch the video below, or download the pdf instructions (via bitly, opens in new window/tab).

click on the thumbnail below to see where to find the values used in the report.

**with Excel**

**with Python**

**Manually (formulas and example)**

**Formulas**

The unadjusted test statistic is given by:

In this formula is the number of ranks with a positive deviation from the hypothesized median, and the i-th rank of of the ranks with a positive deviation from the hypothesized median.

The ranks are based on the absolute deviation of each score with the hypothesized median, removing scores that are equal to the hypothesized median. In formula notation we could determine the sequence of ranks as:

Where d is the sequence of:

Where θ is the hypothesized median, and and y the sequence of original scores, but with the scores removed that equal θ

To adjust for ties we need a few more things.

The variance is given by:

Where n_{r} is the number of ranks.

The adjustment is given by:

In this formula t_{i} is the number of ties for each unique ranks i, and n_{f} the number of unique ranks.

The adjusted variance then becomes:

The adjusted standard error:

Another small adjustment is needed:

Finally the adjusted W statistics is then:

**Example**

We are given six scores from an ordinal scale and like to test if the median is significantly different from 3. The six scores are:

The hypothesized median was given to be 3, so:

First we now remove any score from x that is equal to the hypothesized median, which in the example is only the last score. So we set:

Then we determine the difference with the hypothesized median:

To determine the ranks, we need tha absolute values of these:

Then we rank these absolute differences. The lowest score is a 1, but this occurs twice. So they take up rank 1 and 2, or on average rank 1.5. Then we have a score of 2, but this occurs three times. So they take ranks 3, 4 and 5, or on average rank 4. It is these average ranks that we need:

To determine the unadjusted W we sum up the ranks, but only for those that had a positive deviation (from d). The fourth entry in d is negative (-2), so we do not add the rank of 4 from that score. We therefor get:

We have five ranks so n_{r} = 5, so we can also determine the variance:

We have a rank of 1.5 that occurs twice, and a rank of 4 that occurs three times. Therefore:

The adjusted variance then becomes:

The adjusted standard error:

The other small adjustment:

The adjusted W statistic becomes:

To determine the two-tailed significance either the exact Wilcoxon distribution is used, or if there is sufficient data the standard normal distribution is used.

The formula for determining the two-tailed significance using the standard normal distribution is:

The next step is to determine if the difference is also a 'big' difference, known as an effect size. This will be the topic for the next part.

**Appendix: one-sample sign test (click to expand)**

As mentioned at the start of this page, an alternative option might be a so-called one-sample sign test. This test looks only at how many scores are below the expected population median, and how many above. It then uses a binomial test to determine the chance of this. It fully ignores how far from the median each score is. So for example for a sign test with a hypothesized median of 5, it would not matter if the scores were: 3, 3, 4, 4, 4, 5, 5, 9, 10, 15, 22

or : 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7

In both examples there are five scores below the expected median, and five above.

**Click here to see how you can perform a one-sample sign test with SPSS, R (Studio) or Excel**

**with SPSS**

**with R (Studio)**

**with Excel**

**Single ordinal variable**

Google adds