Multiple Factor Nonparametric Tests - R
Contents
Multiple Factor Nonparametric Tests - R#
Aligned Rank Transform for Between Subjects (ART)#
Samples:
≥2Levels:
≥2Between or Within Subjects: Between
Reporting: “Figure 10 shows boxplots for all levels of X1×X2. A nonparametric analysis of variance based on the Aligned Rank Transform indicated no statistically significant effect on Y of X1 (F(1, 56) = 1.98, n.s.), or of X2 (F(1, 56) = 0.81, n.s.), but there was a statistically significant X1×X2 interaction (F(1, 56) = 13.65, p < .001).”
# Example data
# df has subjects (S), two between-Ss factors (X1,X2) each w/levels (a,b), and continuous response (Y)
df <- read.csv("data/2F2LBs.csv")
head(df, 20)
| S | X1 | X2 | Y | |
|---|---|---|---|---|
| <int> | <chr> | <chr> | <dbl> | |
| 1 | 1 | a | a | 8.236467 |
| 2 | 2 | a | b | 12.965256 |
| 3 | 3 | b | a | 10.782947 |
| 4 | 4 | b | b | 7.385979 |
| 5 | 5 | a | a | 12.041681 |
| 6 | 6 | a | b | 12.779924 |
| 7 | 7 | b | a | 11.581190 |
| 8 | 8 | b | b | 9.529899 |
| 9 | 9 | a | a | 12.658464 |
| 10 | 10 | a | b | 14.159172 |
| 11 | 11 | b | a | 9.548367 |
| 12 | 12 | b | b | 7.859910 |
| 13 | 13 | a | a | 10.395678 |
| 14 | 14 | a | b | 10.385932 |
| 15 | 15 | b | a | 12.512831 |
| 16 | 16 | b | b | 8.080291 |
| 17 | 17 | a | a | 10.252031 |
| 18 | 18 | a | b | 12.052793 |
| 19 | 19 | b | a | 13.768800 |
| 20 | 20 | b | b | 11.417579 |
# library(ARTool)
# df$S = factor(df$S) # Subject id is nominal (unused)
# df$X1 = factor(df$X1) # X1 is a 2-level factor
# df$X2 = factor(df$X2) # X2 is a 2-level factor
# m = art(Y ~ X1*X2, data=df)
# anova(m)
Generalized Linear Model (GLM)#
Samples:
≥2Levels:
≥2Between or Within Subjects: Between
Reporting: “The median of ‘a’ was 11.92 (IQR = 2.35) and of ‘b’ was 10.74 (IQR = 2.29). This difference was statistically significant according to a Wilcoxon signed-rank test (Z = 2.11, p < .05).”
See Generalized Linear (Mixed) Models: Distributions and Canonical Links
Aligned Rank Transform for Within Subjects (ART)#
Samples:
≥2Levels:
≥2Between or Within Subjects: Within
Reporting: “Figure 11 shows boxplots for all levels of X1×X2. A nonparametric analysis of variance based on the Aligned Rank Transform indicated no statistically significant effect on Y of X1 (F(1, 42) = 1.85, n.s.) or of the X1×X2 interaction (F(1, 42) = 1.93, n.s.), but there was a statistically significant effect of X2 (F(1, 42) = 24.97, p < .0001).”
# Example data
# df has subjects (S), two within-Ss factors (X1,X2) each w/levels (a,b), and continuous response (Y)
df <- read.csv("data/2F2LWs.csv")
head(df, 20)
| S | X1 | X2 | Y | |
|---|---|---|---|---|
| <int> | <chr> | <chr> | <dbl> | |
| 1 | 1 | a | a | 13.177771 |
| 2 | 1 | a | b | 13.299755 |
| 3 | 1 | b | a | 9.909350 |
| 4 | 1 | b | b | 16.457684 |
| 5 | 2 | a | a | 11.770180 |
| 6 | 2 | a | b | 14.804296 |
| 7 | 2 | b | a | 9.819264 |
| 8 | 2 | b | b | 13.907344 |
| 9 | 3 | a | a | 8.535872 |
| 10 | 3 | a | b | 12.210064 |
| 11 | 3 | b | a | 12.448765 |
| 12 | 3 | b | b | 12.204888 |
| 13 | 4 | a | a | 10.287867 |
| 14 | 4 | a | b | 16.082883 |
| 15 | 4 | b | a | 9.196968 |
| 16 | 4 | b | b | 9.614437 |
| 17 | 5 | a | a | 9.040155 |
| 18 | 5 | a | b | 16.885613 |
| 19 | 5 | b | a | 10.184381 |
| 20 | 5 | b | b | 14.435134 |
# library(ARTool)
# df$S = factor(df$S) # Subject id is nominal
# df$X1 = factor(df$X1) # X1 is a 2-level factor
# df$X2 = factor(df$X2) # X2 is a 2-level factor
# m = art(Y ~ X1*X2 + (1|S), data=df) # S is a random factor
# anova(m)
Generalized Linear Mixed Model (GLMM)#
Samples:
≥2Levels:
≥2Between or Within Subjects: Within
Reporting: “The median of ‘a’ was 11.92 (IQR = 2.35) and of ‘b’ was 10.74 (IQR = 2.29). This difference was statistically significant according to a Wilcoxon signed-rank test (Z = 2.11, p < .05).”
See Generalized Linear (Mixed) Models: Distributions and Canonical Links