Title: R Handbook: Two-sample Mann–Whitney U Test
Headings: Two-sample Mann–Whitney U Test
Two-sample Mann–Whitney U Test
When to use this test
Packages used in this chapter
Two-sample Mann–Whitney U test example
Summarize data treating Likert scores as factors
Bar plots of data by group
Summarize data treating Likert scores as numeric
Two-sample Mann–Whitney U test example
Effect size
Optional: Comparison among effect size statistics
References
Exercises J

Content: require (effsize)) {install.packages ("effsize")}
Two-sample Mann–Whitney U test example
This example re-visits the Pooh and Piglet data from the Descriptive Statistics with the likert Package chapter. It answers the question, “Are Pooh's scores significantly different from those of Piglet?” The Mann–Whitney U test is conducted with the wilcox.test function, which produces a p -value for the hypothesis. First the data are summarized and examined using bar plots for each group. 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
")
Data = read.table (textConnection (Input),header=TRUE)
### Create a new variable which is the Likert scores as an ordered factor
Data$Likert.f = factor (Data$Likert,
ordered = TRUE)
### Check the data frame
library (psych)
headTail (Data)
str (Data)
summary (Data)
### Remove unnecessary objects
rm (Input)
Summarize data treating Likert scores as factors
Note that the variable we want to count is Likert.f , which is a factor variable. Counts for Likert.f are cross tabulated over values of Speaker . The prop.table function translates a table into proportions. The margin=1 option indicates that the proportions are calculated for each row. xtabs ( ~ Speaker + Likert.f,
data = Data)
Likert.f
Speaker 1 2 3 4 5
Piglet 1 6 2 1 0
Pooh 0 0 1 6 3
XT = xtabs ( ~ Speaker + Likert.f,
data = Data)
prop.table (XT,
margin = 1)
Likert.f
Speaker 1 2 3 4 5
Piglet 0.1 0.6 0.2 0.1 0.0
Pooh 0.0 0.0 0.1 0.6 0.3
Bar plots of data by group
library (lattice)
histogram (~ Likert.f | Speaker,
data=Data,
layout=c (1,2) # columns and rows of individual plots
)
Summarize data treating Likert scores as numeric
library (FSA)
Summarize (Likert ~ Speaker,
data=Data,
digits=3)
Speaker n mean sd min Q1 median Q3 max percZero
1 Piglet 10 2.3 0.823 1 2 2 2.75 4 0
2 Pooh 10 4.2 0.632 3 4 4 4.75 5 0
Two-sample Mann–Whitney U test example
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.