How to Perform Mood’s Median Test in R

Spread the love

When it comes to comparing the medians of two or more groups, a common approach is to use the Kruskal-Wallis test. However, another non-parametric method, less commonly mentioned but equally useful in certain scenarios, is Mood’s median test. This test compares the medians of groups without assuming any specific distribution for the data, making it robust against outliers and non-normally distributed data.

In this detailed guide, we will elucidate the principles behind Mood’s Median Test, demonstrate how to conduct the test in R, and provide guidance on result interpretation.

Understanding Mood’s Median Test

Mood’s Median Test determines whether the medians of two or more groups are the same. The procedure involves:

  1. Calculating the overall median of the combined data from all groups.
  2. Counting the number of values in each group that are above and below this overall median.
  3. Using a chi-square test to determine if the groups have different proportions of values above or below the overall median.

Preparing Your Data

Your data should be in a form where you have a numeric variable of interest, and a factor (categorical variable) which indicates group membership.Let’s assume we are comparing the median scores of three different teaching methods:

# Sample data
scores <- c(50, 52, 53, 55, 60, 62, 64, 65, 68, 70,
            55, 57, 58, 60, 63, 65, 67, 68, 70, 72,
            58, 60, 62, 65, 68, 70, 72, 75, 77, 78)
method <- factor(rep(1:3, each=10))

data <- data.frame(scores, method)

Performing Mood’s Median Test in R

Though R’s base package doesn’t include a function specifically for Mood’s median test, it’s easy to conduct using the chisq.test() function after organizing the data.

Here’s how you can perform the test:

# Calculate overall median
overall_median <- median(data$scores)

# Create a binary variable based on whether scores are above the median
data$above_median <- as.integer(data$scores > overall_median)

# Create a table of counts
table_counts <- table(data$method, data$above_median)

# Conduct the chi-square test
result <- chisq.test(table_counts)

Interpreting the Results

A typical output for the chisq.test() might look like:

Pearson's Chi-squared test

data:  table_counts
X-squared = 5.6, df = 2, p-value = 0.06

Interpreting the output:

  • X-squared: This is the test statistic for the chi-square test. A larger value indicates a stronger deviation from the expected counts.
  • df: This is the degree of freedom, calculated as (number of groups – 1).
  • p-value: The p-value helps determine the statistical significance. If the p-value is less than a chosen significance level (e.g., 0.05), you have evidence to reject the null hypothesis and infer that there’s a difference in medians among the groups.

In this example, with a p-value of 0.06 (slightly above 0.05), we might not reject the null hypothesis at the 0.05 significance level, suggesting that the groups may have similar medians.

Benefits and Limitations

  1. Non-parametric: Mood’s Median Test does not assume normally distributed data, which is useful for datasets that deviate from the normal distribution.
  2. Robust Against Outliers: Since it focuses on medians and not means, the test is not overly sensitive to outliers.
  3. Multiple Groups: It can compare two or more groups, unlike some tests which are limited to comparing only two at a time.
  4. Power: One potential limitation is that Mood’s median test might have less statistical power than alternative tests, like the Kruskal-Wallis test, especially when there are small sample sizes.


Mood’s Median Test offers a straightforward, non-parametric approach to compare medians across multiple groups. By utilizing R’s chi-square testing functions, you can efficiently evaluate if your groups significantly differ in their medians. While the test is robust and versatile, it’s always essential to consider its context and other available tests to ensure you’re drawing accurate and meaningful conclusions from your data.

Posted in RTagged

Leave a Reply