Non-parametric hypothesis tests

Dr. Peng Zhao (✉ peng.zhao@xjtlu.edu.cn)

Department of Health and Environmental Sciences
Xi’an Jiaotong-Liverpool University

1 Learning objectives

  1. Understand the difference between parametric and nonparametric tests.
  2. Use the Wilcoxon Rank Sum test, Wilcoxon signed-rank test, Kruskal-Wallis test, Friedman’s test for scientific questions.

2 Definition

Nonparametric test:

A hypothesis test that does not require any specific conditions concerning the shapes of population distributions or the values of population parameters, i.e. the distribution of the population is not always known. Easier to perform than corresponding parametric tests. Less efficient than parametric tests.

Rank:

x <- c(1, 5, 4, 5, 7)
rank(x)

3 Wilcoxon Rank-Sum test

3.1 Usage

Wilcoxon Rank Sum test (Mann-Whitney U-test, Wilcoxon test, Mann-Whitney-Wilcoxon test, Wilcoxon-Mann-Whitney test):

Test whether the medians of two independent samples are different enough to conclude that they were drawn from different populations. One-sample, two-sample, one-tailed, and two-tailed. Roughly a non-parametric version of unpaired two-sample t-test.

3.2 Hypotheses

  • H0: the medians of the two populations are equal.

3.3 Assumptions

  • Both samples are drawn randomly and independently.
  • The measures within the two samples are able to be ranked and hence must be continuous, discrete or ordinal.

3.4 Example

The insect spray dataset for C and D. The number of insects that survived when treated with insecticide treatments.

insect <- read.csv("data/InsectSprays.csv")
insect <- insect[insect$spray %in% c("C", "D"), ]

Q: Does the insecticide C have the same effect as D?

boxplot(bugs ~ spray, data = insect, horizontal = TRUE)

We could test whether the two means are different. What hypothesis test?

But…

shapiro.test(insect$bugs[insect$spray == "C"])
shapiro.test(insect$bugs[insect$spray == "D"])

Instead, we could test whether the two medians are different.

tapply(insect$bugs, insect$spray, median)
  • H0: The median of the survived insects treated by C is equal to that by D.
wilcox.test(bugs ~ spray, data = insect, conf.int=TRUE)
  • W: the Wilcoxon test statistic U.
  • We are 95% certain that the median difference between spray D and C across the population will be between 1 and 4 bugs.
  • It does not estimate the difference in medians but rather the median of the difference (between the two samples)
median(outer(insect$bugs[insect$spray == 'C'], insect$bugs[insect$spray == 'D'], "-"))
  • Is Spray C more effective than spray D?

Decision: Reject H0,

Conclusion: There is a significant difference in insecticide effectiveness.

4 Wilcoxon Signed-Rank test

4.1 Usage

  • Test whether the median of the observed differences deviates enough from zero, based on paired samples.
  • Roughly a non-parametric version of paired t-test.

4.2 Hypotheses

  • H0: the medians of the two populations are equal.

4.3 Example

Weight-loss program.

Ten people take part in a weight-loss program. They weigh before starting the program, and weigh again after the one-month program. Does the program have effect on the weight?

wl <- data.frame(
  id = LETTERS[1:10],
  before = c(198, 201, 210, 185, 204, 156, 167, 197, 220, 186),
  after = c(194, 203, 200, 183, 200, 153, 166, 197, 215, 184))

wilcox.test(wl$before, wl$after, paired = TRUE, conf.int = TRUE, correct = FALSE)

Decision: As \(p < 0.05\), reject H0.

Conclusion: The two population medians are different at \(\alpha = 0.05\). The program has effect on the weight.

5 Kruskal-Wallis test

5.1 Usage

  • Test whether three or more population medians are equal.
  • Roughly a non-parametric version of ANOVA

5.2 Hypotheses

  • H0: the medians of the populations are equal.

5.3 Example

The insect spray dataset for C, D, and F. The number of insects that survived when treated with insecticide treatments.1

  • 1 https://stat-methods.com/home/kruskal-wallis-r/

  • Q: Any difference in the number of insects that survived when treated with multiple available insecticide treatments?

    insect <- read.csv("data/InsectSprays.csv")
    
    boxplot(bugs ~ spray, data = insect, horizontal = TRUE, notch = TRUE)
    shapiro.test(insect$bugs[insect$spray == "C"])
    shapiro.test(insect$bugs[insect$spray == "D"])
    shapiro.test(insect$bugs[insect$spray == "F"])
    tapply(insect$bugs, insect$spray, median)
    
    kruskal.test(bugs ~ spray, data = insect)
    • Kruskal-Wallis chi-squared: the test statistic.

    Decision: As \(p < 0.05\), reject H0.

    Conclusion: There is a significant difference in insecticide effectiveness.

    • Post-hoc tests, such as
      • the Dunn’s multiple comparison procedure (FSA package), or
      • the Dwass, Steel, Critchlow-Fligner multiple comparisons procedure (PMCMRplus package).

    6 Friedman’s test

    6.1 Usage

    • Test whether three or more population medians are equal for repeated measures.
    • Roughly a non-parametric version of repeated measures ANOVA.
    • More powerful than ANOVA for very skewed (heavy tail) distributions.

    Test statistic:

    \[ F_{r}=\frac{12}{n k(k+1)}\left(T_{1}^{2}+T_{2}^{2}+\ldots+T_{k}^{2}\right)-3 n(k+1) \]

    6.2 Example

    dtf <- data.frame(
      # id = LETTERS[1:10],
      before = c(198, 201, 210, 185, 204, 156, 167, 197, 220, 186),
      one = c(194, 203, 200, 183, 200, 153, 166, 197, 215, 184),
      two = c(191, 200, 192, 180, 195, 150, 167, 195, 209, 179),
      three = c(188, 196, 188, 178, 191, 145, 166, 192, 205, 175)
    )
    rownames(dtf) <- LETTERS[1:10]
    
    friedman.test(as.matrix(dtf))

    7 Further readings