-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa0d5ff
commit 92bb4db
Showing
30 changed files
with
838 additions
and
100 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-2.75 KB
R/anova_cache/html/unnamed-chunk-2_a959c7d69d77a7d483cef0c7910ca827.RData
Binary file not shown.
Binary file removed
BIN
-3.75 KB
R/anova_cache/html/unnamed-chunk-2_a959c7d69d77a7d483cef0c7910ca827.rdb
Binary file not shown.
Binary file removed
BIN
-148 Bytes
R/anova_cache/html/unnamed-chunk-2_a959c7d69d77a7d483cef0c7910ca827.rdx
Binary file not shown.
Binary file removed
BIN
-3.01 KB
R/anova_cache/html/unnamed-chunk-3_03313b7a8524dd7a7440d66f44058036.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-3_03313b7a8524dd7a7440d66f44058036.rdx
Binary file not shown.
Binary file removed
BIN
-3.16 KB
R/anova_cache/html/unnamed-chunk-4_2c39991c34fb054f157959a554b2175c.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-4_2c39991c34fb054f157959a554b2175c.rdx
Binary file not shown.
Binary file removed
BIN
-3 KB
R/anova_cache/html/unnamed-chunk-5_1e3227cddc2c5d4b92f6b3238e69038a.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-5_1e3227cddc2c5d4b92f6b3238e69038a.rdx
Binary file not shown.
Binary file removed
BIN
-3.06 KB
R/anova_cache/html/unnamed-chunk-6_87216dbd4f33263d00c668206b754202.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-6_87216dbd4f33263d00c668206b754202.rdx
Binary file not shown.
Binary file removed
BIN
-3.02 KB
R/anova_cache/html/unnamed-chunk-7_a6ade8d6f53133a4cb343d600ba67101.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-7_a6ade8d6f53133a4cb343d600ba67101.rdx
Binary file not shown.
Binary file removed
BIN
-3.02 KB
R/anova_cache/html/unnamed-chunk-8_fa270a2f00df15b12e7fd336f04352a4.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-8_fa270a2f00df15b12e7fd336f04352a4.rdx
Binary file not shown.
Binary file removed
BIN
-3.07 KB
R/anova_cache/html/unnamed-chunk-9_172a7fa3eda2baf75813b4ecc2a279ce.RData
Binary file not shown.
Empty file.
Binary file removed
BIN
-125 Bytes
R/anova_cache/html/unnamed-chunk-9_172a7fa3eda2baf75813b4ecc2a279ce.rdx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: "Wilcoxon Rank Sum (Mann Whitney-U) in R" | ||
--- | ||
|
||
```{r} | ||
#| echo: FALSE | ||
#| include: FALSE | ||
library(tidyverse) | ||
``` | ||
|
||
# Overview | ||
|
||
Wilcoxon rank sum test, or equivalently, Mann-Whitney U-test is a rank based non-paramatric method. The aim is to examine the differences between two groups. To be more specific, it tests whether the median difference between pairs is equal to zero. | ||
|
||
It is the non-parametric equivalent to two-sample t-test, where the two groups are not paired. | ||
|
||
## Available R package | ||
|
||
The `stats` package implements various classic statistical tests, including wilcoxon rank sum test. | ||
|
||
```{r} | ||
#| eval: false | ||
#| echo: true | ||
# x, y are two unpaired vectors. Do not necessary need to be of the same length. | ||
stats::wilcox.test(x, y, paired = F) | ||
``` | ||
|
||
|
||
## Example: Birth Weight | ||
|
||
*Data source: Table 30.4, Kirkwood BR. and Sterne JAC. Essentials of medical statistics. Second Edition. ISBN 978-0-86542-871-3* | ||
|
||
Comparison of birth weights (kg) of children born to 15 non-smokers with those of children born to 14 heavy smokers. | ||
|
||
```{r} | ||
#| eval: true | ||
#| echo: true | ||
# bw_ns: non smokers | ||
# bw_s: smokers | ||
bw_ns <- c(3.99, 3.89, 3.6, 3.73, 3.31, | ||
3.7, 4.08, 3.61, 3.83, 3.41, | ||
4.13, 3.36, 3.54, 3.51, 2.71) | ||
bw_s <- c(3.18, 2.74, 2.9, 3.27, 3.65, | ||
3.42, 3.23, 2.86, 3.6, 3.65, | ||
3.69, 3.53, 2.38, 2.34) | ||
``` | ||
|
||
Can visualize the data on two histograms. Red lines indicate the location of medians. | ||
|
||
```{r} | ||
#| eval: true | ||
#| echo: true | ||
par(mfrow =c(1,2)) | ||
hist(bw_ns, main = 'Birthweight: non-smokers') | ||
abline(v = median(bw_ns), col = 'red', lwd = 2) | ||
hist(bw_s, main = 'Birthweight: smokers') | ||
abline(v = median(bw_s), col = 'red', lwd = 2) | ||
``` | ||
|
||
|
||
It is possible to see that for non-smokers, the median birthweight is higher than those of smokers. Now we can formally test it with wilcoxon rank sum test. | ||
|
||
The default test is two-sided with confidence level of 0.95, and does continuity correction. | ||
|
||
```{r} | ||
#| eval: true | ||
#| echo: true | ||
# default is two sided | ||
stats::wilcox.test(bw_ns, bw_s, paired = F) | ||
``` | ||
We can also carry out a one-sided test, by specifying `alternative = greater` (if the first item is greater than the second). | ||
|
||
```{r} | ||
#| eval: true | ||
#| echo: true | ||
# default is two sided | ||
stats::wilcox.test(bw_ns, bw_s, paired = F, alternative = 'greater') | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.