-
Notifications
You must be signed in to change notification settings - Fork 18
/
01.2 non parametric (rank) test.R
79 lines (40 loc) · 1.75 KB
/
01.2 non parametric (rank) test.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
library(effectsize)
pdat <- readRDS("pdat.Rds")
head(pdat)
# Here are the most common non-parametric tests. They are all based on
# rank-transforming the data in some way (similar to Spearman's correlation).
# For example:
x <- c(1.45, 2.01, 0.47, 0.79)
rank(x) # or
ranktransform(x) # more options
# However, note that the tests themselves are parametric, it is the underlying
# models that are not. Read more here:
# https://lindeloev.github.io/tests-as-linear/
# Compare two samples -----------------------------------------------------
# These are the rank-versions of the t-test.
#
# Their effect size is the rank biserial correlation. You can read more about it
# and the other rank based effect sizes here:
# https://easystats.github.io/effectsize/articles/simple_htests.html#rank-based-tests-1
## Mann-Whitney U Test --------------
# (compare two independent samples)
wilcox.test(pdat$Depression[pdat$Group == "a"],
pdat$Depression[pdat$Group == "b"])
rank_biserial(pdat$Depression[pdat$Group == "a"],
pdat$Depression[pdat$Group == "b"])
## Wilcoxon Signed-rank Test --------
# (compare two dependent samples)
wilcox.test(pdat$Cond_B, pdat$Cond_C, paired = TRUE)
rank_biserial(pdat$Cond_B, pdat$Cond_C, paired = TRUE)
# Compare more than 2 samples ---------------------------------------------
# These are the rank-versions of the one-way anove.
## Kruskal-Wallis Test --------------
# (compare k independent samples)
kruskal.test(Depression ~ Group, data = pdat)
rank_epsilon_squared(Depression ~ Group, data = pdat)
## Friedman Test --------------------
# (compare k dependent samples)
m <- as.matrix(pdat[c("Cond_A", "Cond_B", "Cond_C")])
head(m) # row per subject, column per condition
friedman.test(m)
kendalls_w(m)