 ## Summary and Analysis of Extension Program Evaluation in R

Salvatore S. Mangiafico

# Mood’s Median Test for Two-sample Data

Mood’s median test compares the medians of two or more groups.  The test can be conducted with the mood.medtest function in the RVAideMemoire package or with the median_test function in the coin package.

##### Appropriate data

•  One-way data with two or more groups

•  Dependent variable is ordinal, interval, or ratio

•  Independent variable is a factor with levels indicating groups

•  Observations between groups are independent.  That is, not paired or repeated measures data

##### Hypotheses

•  Null hypothesis:  The medians of the populations from which the groups were sampled are equal.

•  Alternative hypothesis (two-sided): The medians of the populations from which the groups were sampled are not equal.

##### Interpretation

Significant results can be reported as “The median value of group A was significantly different from group B.”

### Packages used in this chapter

The packages used in this chapter include:

•  RVAideMemoire

•  coin

The following commands will install these packages if they are not already installed:

if(!require(RVAideMemoire)){install.packages("RVAideMemoire")}
if(!require(coin)){install.packages("coin")}

### Example using the RVAideMemoire package

This example uses the formula notation indicating that Likert is the dependent variable and Speaker is the independent variable.  The data= option indicates the data frame that contains the variables.  For the meaning of other options, see ?mood.medtest.

For appropriate plots and summary statistics, see the Two-sample Mann–Whitney U Test chapter.

Input =("
Speaker  Likert
Pooh      3
Pooh      5
Pooh      4
Pooh      4
Pooh      4
Pooh      4
Pooh      4
Pooh      4
Pooh      5
Pooh      5
Piglet    2
Piglet    4
Piglet    2
Piglet    2
Piglet    1
Piglet    2
Piglet    3
Piglet    2
Piglet    2
Piglet    3
")

###  Check the data frame

library(psych)

str(Data)

summary(Data)

### Remove unnecessary objects

rm(Input)

### Mood’s Median Test

library(RVAideMemoire)

mood.medtest(Likert ~ Speaker,
data  = Data,
exact = FALSE)

Mood's median test

X-squared = 9.8, df = 1, p-value = 0.001745

### Median test by Monte Carlo simulation

library(coin)

median_test(Likert ~ Speaker,
data = Data,
distribution = approximate(B = 10000))

Approximative Two-Sample Brown-Mood Median Test

Z = -3.4871, p-value = 0.0011