1 of 31

LECTURE 10

COURSE CHECK-IN

ANOVA RECAP

RANK-BASED TESTS

2 of 31

I know what a hypothesis test does

(Z- and t-tests), and what a p-value means

One-way ANOVA

Ranked-based tests

Chi-square

Linear Regression

Multi-factor ANOVA

Logistic Regression

THE STATS TRAIN…

Tools for reproducible data science and collaboration (Rstudio, projects, scripts + markdown)

Data wrangling

Data visualization

Data analysis

Version control + collaboration (github)

Communication

…only exists within THE DATA SCIENCE WORLD

3 of 31

ANOVA Hypotheses:

Null Hypothesis (H0): All means are equal

Alternative Hypothesis (HA): At least two means are NOT equal (that means that just two could be different, or they could ALL be different)

4 of 31

Kim, TK (2017). Understanding one way ANOVA using conceptual figures. Korean Journal of Anesthesiology 70(1): 22-26.

Dashed arrows indicate within group variances (within group sum of squares). Solid arrows indicate between group variances (between group sum of squares).

When the between group variance is much larger than the within group sum of squares, then it seems more likely that the groups are different.

5 of 31

If the distance between groups is large (high between groups variance) compared to the distance between observations within groups (low within groups variance), then we might have enough evidence to conclude that samples are drawn from populations with different means.

6 of 31

Only a few significant differences? You might consider adding p-value annotation (maybe with the ggsignif package)

7 of 31

Assumptions of t-tests and ANOVAs (parametric):

  • Continuous data (interval/ratio)
  • Normality
  • Equal Variances
  • Independence

What if our data DO NOT satisfy these assumptions?

8 of 31

QUANTITATIVE DATA

INTERVAL: Data for which intervals between values are known and meaningful. Does not need to start at zero.

RATIO: Ratio data is interval data that has a starting point of zero

ORDINAL: Ordinal data has a relevant order, but intervals between values may be undefined (e.g. survey rankings)

9 of 31

Data Characteristic

Parametric Tests

Non-Parametric Tests

Distribution

Normal

No assumed shape

Data type

Interval/ratio

Ordinal data, ranked data, or interval/ratio not satisfying other assumptions

Assumed equal variances?

Yes

No

Independent observations/samples?

Yes

Not necessarily

Parametric tests: Assumptions made about parameters of data

Non-parametric tests: Assumptions are NOT made about parameters of data

10 of 31

THIS IS WHY IT’S CRUCIAL TO:

  • Think critically about the type of data you have

  • Visually explore data using histograms, qq-plots, boxplots, etc. to assess data shape, size, etc.

  • Test for equal variances (keep in mind guidelines for differences)

  • Remember: Use this information all together to make a decision – don’t choose a type of test based on a p-value!

11 of 31

Comparing…

Parametric Test

Non-Parametric Tests

Two Samples (Unpaired)

Unpaired t-test

Mann-Whitney U

Two Samples (Paired)

Paired t-test

Wilcoxon signed-rank

> 2 Samples

One-way ANOVA

Kruskal-Wallis

These compare means

These compare ranks

12 of 31

What are RANK-BASED TESTS?

Rank-based tests compared ranks of sample observations across groups being compared.

You’ll frequently hear this interpreted as a comparison of medians.

13 of 31

Advantages:

  • No assumption of normality or equal variance

  • Broader range of data types/non-normal distributions/low sample sizes can be compared

  • Can compare medians (may be a better parameter for comparison in some studies)

  • Better if you have outliers that may significantly shift the mean, even if n is high

  • OK to use if data have endpoint values at “limits of detection”

Potential Advantages of Rank-Based Tests

14 of 31

Disadvantages:

  • You might be throwing away some of the information (the actual values, replaced by ranks)

  • Less powerful than parametric tests IF assumptions for a parametric test are met (if your data satisfy assumptions for a parametric test and you want to compare means, then use a parametric test!)

Potential Disadvantages of Rank-Based Tests

15 of 31

SAMPLE 1

1.1

2.4

1.8

0.4

1.6

SAMPLE 2

5.4

3.1

2.3

1.9

4.2

Generally, how do rank-based tests work?

Original Samples

POOLED

0.4 (1)

1.1 (2)

1.6 (3)

1.8 (4)

1.9 (5)

2.3 (6)

2.4 (7)

3.1 (8)

4.2 (9)

5.4 (10)

Pool Data and Rank

Compare RANKS

SAMPLE 1

1

2

3

4

7

SAMPLE 2

5

6

8

9

10

16 of 31

How do we compare ranks?

Usually, using some comparison of the sums of the rankings (while taking into account sample sizes, etc.)

17 of 31

Mann-Whitney U

(Non-parametric alternative to UNPAIRED T-TEST)

Null Hypothesis (H0): Ranks are equal

Alternative Hypothesis (HA): Ranks are NOT equal

This is often interpreted as a comparison of medians.

18 of 31

A comparison of observation RANKS

SAMPLE 1

1.1

2.4

1.8

0.4

1.6

SAMPLE 2

5.4

3.1

2.3

1.9

4.2

Original Samples

POOLED

0.4 (1)

1.1 (2)

1.6 (3)

1.8 (4)

1.9 (5)

2.3 (6)

2.4 (7)

3.1 (8)

4.2 (9)

5.4 (10)

Pool Data and Rank

Compare RANKS

SAMPLE 1

1

2

3

4

7

SAMPLE 2

5

6

8

9

10

19 of 31

Overall RANKS

SAMPLE 1

1

2

3

4

7

SAMPLE 2

5

6

8

9

10

Find the RANK SUM (Σ ranks for each group)

Σ R1 = 1 + 2 + 3 + 4 + 7 = 17

Σ R2 = 5 + 6 + 8 + 9 + 10 = 38

20 of 31

Calculate the U statistic:

U1 = Σ R1 – n1(n1 + 1)/2 = 17 – 5(5+1)/2 = 2

U2 = Σ R2 – n2(n2 + 1)/2 = 38 – 5(5+1)/2 = 23

The LOWER of these two is the U-statistic for Mann-Whitney U. Here, U = 2.

Σ R1 = 1 + 2 + 3 + 4 + 7 = 17

Σ R2 = 5 + 6 + 8 + 9 + 10 = 38

21 of 31

Critical values for U statistic (95%)

We could use a table…

22 of 31

Or we could have R do the work for us…

Same as U

What does this mean?

What do we conclude?

23 of 31

Comparing…

Parametric Test

Non-Parametric Tests

Two Samples (Unpaired)

Unpaired t-test

Mann-Whitney U

Two Samples (Paired)

Interval/ratio

Wilcoxon signed-rank

> 2 Samples

One-way ANOVA

Kruskal-Wallis

24 of 31

Wilcoxon Signed-Rank

(Non-parametric alternative to PAIRED T-TEST)

Null Hypothesis (H0): Ranks are equal

Alternative Hypothesis (HA): Ranks are NOT equal

(only difference is that now samples are NOT independent)

25 of 31

BEFORE (1)

1.2

2.0

0.8

0.6

1.3

3.2

0.9

AFTER (2)

1.6

2.8

0.7

0.6

1.5

2.7

1.1

DIFFERENCE

- 0.4

- 0.8

0.1

0.0

- 0.2

0.5

- 0.2

x1 – x2

26 of 31

Omit differences of zero, then arrange by MAGNITUDE

ORDERED MAGNITUDE

0.1

- 0.2

- 0.2

- 0.4

0.5

-0.8

DIFFERENCE

- 0.4

- 0.8

0.1

0.0

- 0.2

0.5

- 0.2

27 of 31

ORDERED MAGNITUDE

0.1

- 0.2

- 0.2

- 0.4

0.5

-0.8

RANK, and include sign to indicate < or > 0

SIGNED RANK

+ 1

- 2

- 2

- 4

+ 5

- 6

Then sum the MAGNITUDES of the + and – values, and those will be –W and +W (the W-statistic, same as U, same as V)

+W = 6 and –W = 14 (pick the lower one)

28 of 31

What do we conclude?

29 of 31

Kruskal-Wallis

(Non-parametric alternative to ONE-WAY ANOVA)

Null Hypothesis (H0): All ranks are equal (no difference in medians)

Alternative Hypothesis (HA): At least two ranks differ (at least one difference in group medians)

*Note that it’s an omnibus test, like one-way ANOVA, and may require post-hoc testing

30 of 31

Without even knowing anything else about the test statistic calculation:

What do you think is going to be compared?

31 of 31

What do we conclude?

Then what might we want to do?