Non-parametric Tests
Practice
A note on AI tools: You may use AI assistants
(ChatGPT, Claude, etc.) to help debug your R code — that’s a realistic
professional skill. You may not use AI to generate your interpretations.
Every write-up sentence must reflect your own reading of the output. If
you use AI for any part of this assignment, note where at the end.
This assignment uses three datasets that ship with base R — no
downloading required.
Part 1:
Wilcoxon Rank-Sum (Two Independent Groups)
PlantGrowth records dried weight for plants under a
control condition and two treatments.
data(PlantGrowth)
str(PlantGrowth)
boxplot(weight ~ group, data = PlantGrowth)
- Why might a researcher hesitate to assume normality here, with only
10 plants per group? (You don’t need to run a formal test — just reason
from the sample size.)
Compare just the control and treatment 2 groups first:
ctrl_trt2 <- subset(PlantGrowth, group %in% c("ctrl", "trt2"))
wilcox.test(weight ~ group, data = ctrl_trt2, exact = FALSE)
- Report the test statistic, p-value, and your conclusion at
α = .05. R labels the statistic W — what does the F5 course
convention say you should call it in your APA write-up, and does that
conversion apply here or only to a specific test type? (Check the
chapter before answering — this is a common trap.)
Part 2:
Kruskal-Wallis (Three or More Groups)
Now compare all three groups at once instead of picking pairs.
kruskal.test(weight ~ group, data = PlantGrowth)
- Report the χ², df, and p-value. Is the omnibus test
significant at α = .05?
pairwise.wilcox.test(PlantGrowth$weight, PlantGrowth$group, p.adjust.method = "BH")
aggregate(weight ~ group, data = PlantGrowth, FUN = median)
- Report the three pairwise (BH-corrected) p-values. Which
specific pair(s) differ significantly? Is your answer “all three groups
differ from each other,” or something more precise? Why does this
matter?
Part 3: Wilcoxon
Signed-Rank (Paired Data)
sleep records the extra hours of sleep gained under two
drugs, in the same 10 patients (paired by ID).
data(sleep)
str(sleep)
g1 <- sleep$extra[sleep$group == 1]
g2 <- sleep$extra[sleep$group == 2]
wilcox.test(g1, g2, paired = TRUE, exact = FALSE)
median(g2 - g1)
- Report the test statistic (V), p-value, and the
median difference. Is the effect significant?
- Try running
wilcox.test(extra ~ group, data = sleep, paired = TRUE) —
the formula version — instead. What happens, and what does that tell you
about when you can and can’t use formula syntax with
paired = TRUE?
Part 4: Spearman’s Rank
Correlation
cars records speed (mph) and stopping distance (ft) for
50 cars.
data(cars)
plot(cars$speed, cars$dist)
cor.test(cars$speed, cars$dist, method = "spearman")
- Report ρ (rho) and the p-value. Describe the relationship
in plain language.
- R may print a warning about not being able to compute an exact
p-value. Look up (or reason out from the chapter) why ties in
the data cause this, and what R does instead.
Part 5: Reporting
- Write one complete APA-style sentence reporting the Kruskal-Wallis
result from Part 2, including the follow-up pairwise pattern from Part
2, Question 4.
- This chapter also covers the Friedman test (three or more repeated
measures on the same subjects). None of today’s three datasets fit that
design. In your own words, what would the data need to look like — in
terms of rows, columns, and how many measurements per subject — for
Friedman to be the right test?