LECTURE 10
COURSE CHECK-IN
ANOVA RECAP
RANK-BASED TESTS
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
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)
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.
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.
Only a few significant differences? You might consider adding p-value annotation (maybe with the ggsignif package)
Assumptions of t-tests and ANOVAs (parametric):
What if our data DO NOT satisfy these assumptions?
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)
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
THIS IS WHY IT’S CRUCIAL TO:
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
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.
Advantages:
Potential Advantages of Rank-Based Tests
Disadvantages:
Potential Disadvantages of Rank-Based Tests
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 |
How do we compare ranks?
Usually, using some comparison of the sums of the rankings (while taking into account sample sizes, etc.)
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.
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 |
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
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
Critical values for U statistic (95%)
We could use a table…
Or we could have R do the work for us…
Same as U
What does this mean?
What do we conclude?
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 |
✓
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)
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
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 |
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)
What do we conclude?
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
Without even knowing anything else about the test statistic calculation:
What do you think is going to be compared?
What do we conclude?
Then what might we want to do?