Rank-based tests
A brief review:
Note
✅ Key idea from last lecture
A t-test’s p-value is only trustworthy if its assumptions hold. Today is about what to do when they don’t.

What we will cover today:
Let’s work with the lake trout data, as the weights are pretty cool and the assumptions may or may not hold. This easily translates to any of the other data frames you might want to use.

# A tibble: 6 × 5
sampling_site species length_mm mass_g lake
<chr> <chr> <dbl> <dbl> <chr>
1 I8 lake trout 515 1400 I8
2 I8 lake trout 468 1100 I8
3 I8 lake trout 527 1550 I8
4 I8 lake trout 525 1350 I8
5 I8 lake trout 517 1300 I8
6 I8 lake trout 607 2100 I8
Tip
🖐 Notice
Six lakes’ worth of trout: sampling_site, species, length_mm, mass_g, lake.
# A tibble: 6 × 2
# Groups: lake [6]
lake mode_mass
<chr> <dbl>
1 I8 1000
2 Island Lake 2200
3 N 01 1000
4 NE 12 90
5 NE 14 1150
6 Toolik 340
Note
📖 New pattern
R has no built-in mode() function for statistical mode — this group_by() + count + slice(1) pattern is the standard workaround.
T-tests are parametric tests.
Note
📖 Reference
Whitlock & Schluter, Analysis of Biological Data, Ch. 13 — Handling Violations of Assumptions, is the core reference for this whole lecture.


Basic assumptions of parametric t-tests: random sampling, normality, equal variance, no outliers.
Random sampling:

Note
🔮 Predict first: We’re about to look at histogram, dotplot, boxplot, and QQ-plot views of the same NE 12 mass data. Which of the four do you expect to be most convincing about normality?
Let’s test normality for one lake — NE 12 — as if we were going to run a one-sample t-test. We need a new data frame with only NE 12 data, called ne12_data.
Normality: samples from a normally distributed population

“Null hypothesis is that data is normally distributed.”
Shapiro-Wilk normality test
data: ne12_data$length_mm
W = 0.94528, p-value = 1.56e-09
Equal variance: samples are from populations with a similar degree of variability.

No outliers: no “extreme” values very different from the rest of the sample.
Warning
⚠️ Watch out!
Outliers are a problem for non-parametric tests as well — switching to a rank-based test doesn’t make an outlier stop mattering.

What if t-test assumptions fail? Alternative tests, with more relaxed assumptions, are available. In which case would you use each?

QQ-plots: a tool for assessing normality.

In some cases, data can be mathematically “transformed” to meet the assumptions of parametric tests. This can be done in R and usually involves:

Welch’s t-test:

Let’s compare a parametric t-test to a Welch’s t-test:
t.test(y1, y2, var.equal = TRUE, paired = FALSE)t.test(y1, y2, var.equal = FALSE, paired = FALSE)[1] "Standard t-test results for mass_g:"
Two Sample t-test
data: mass_g by lake
t = 14.181, df = 330, p-value < 2.2e-16
alternative hypothesis: true difference in means between group Island Lake and group NE 12 is not equal to 0
95 percent confidence interval:
2266.304 2996.360
sample estimates:
mean in group Island Lake mean in group NE 12
3165.0000 533.6677
[1] "Welch's t-test results for mass_g:"
Welch Two Sample t-test
data: mass_g by lake
t = 5.1368, df = 9.0578, p-value = 0.0006016
alternative hypothesis: true difference in means between group Island Lake and group NE 12 is not equal to 0
95 percent confidence interval:
1473.676 3788.989
sample estimates:
mean in group Island Lake mean in group NE 12
3165.0000 533.6677
Rank-based tests: no assumptions about distribution (non-parametric).
Note
📖 Reference
Whitlock & Schluter, Ch. 13, covers the Mann-Whitney U test and Wilcoxon signed-rank test as the standard rank-based alternatives.
[1] "Mann-Whitney U test results mass_g:"
Wilcoxon rank sum test with continuity correction
data: mass_g by lake
W = 3205.5, p-value = 9.506e-08
alternative hypothesis: true location shift is not equal to 0
Tip
🖐 Notice
The test statistic is W, not t — a signal you’re reading rank-based test output, not a t-test.
perm package
Tip
🖐 For a graphical explanation
In R, using the perm package. Assumptions: both groups have a similar distribution; equal variance.
library(perm)
ne12_perm_data <- isl_ne12_df %>%
filter(lake == "NE 12") %>%
pull(length_mm)
# Randomly sample exactly 25 observations from NE 12
set.seed(123)
ne12_perm_data <- sample(ne12_perm_data, size = 25, replace = FALSE)
island_perm_data <- isl_ne12_df %>%
filter(lake == "Island Lake") %>%
pull(length_mm)
observed_diff <- mean(ne12_perm_data, na.rm = TRUE) - mean(island_perm_data, na.rm = TRUE)
Exact Permutation Test Estimated by Monte Carlo
data: GROUP 1 and GROUP 2
p-value = 2e-04
alternative hypothesis: true mean GROUP 1 - mean GROUP 2 is not equal to 0
sample estimates:
mean GROUP 1 - mean GROUP 2
-333.08
p-value estimated from 10000 Monte Carlo replications
99 percent confidence interval on p-value:
0.000000000 0.001059383
Key assumptions:
Note
Assessing assumptions
When assumptions aren’t met, transformations may help normalize data:
log10(x) — useful for right-skewed data, multiplicative effectssqrt(x) — useful for count data, moderately right-skewed distributionsTip
🖐 Recall
We saw log10() shrink the gap between the NE 12 and Island Lake boxplots earlier — that’s the transformation working.
1. Standard t-test
Strengths:
Weaknesses:
2. Welch’s t-test
Strengths:
Weaknesses:
3. Mann-Whitney-Wilcoxon test
Strengths:
Weaknesses:
4. Permutation tests
Strengths:
Weaknesses:
Statistical tests have different strengths and assumptions. The choice should be guided by your data’s characteristics, not just convenience.
Always visualize your data before deciding on the appropriate test.
Note
✅ Key idea
Standard t-test → Welch’s → Mann-Whitney/Permutation isn’t a strict ladder of “better” tests — each answers a slightly different question (means vs. medians) under different assumptions. Pick based on what your data actually looks like.