I have the following dataset (This is just a reduction of the dataset but it has all the characteristics of the bigger one)
df <- structure(list(Modality = c("IMU", "IMU", "IMU", "IMU", "EMG",
"EMG", "EMG", "EMG", "EMG", "EMG", "MULTIMODAL", "MULTIMODAL",
"MULTIMODAL", "MULTIMODAL", "MULTIMODAL", "MULTIMODAL"), Accuracy = c(0.890994094,
0.932236205, 0.920874879, 0.808366656, 0.736169166, 0.727917473,
0.76442499, 0.766358025, 0.672936004, 0.544758539, 0.922476135,
0.958934517, 0.889652539, 0.878411911, 0.800769442, 0.9035499
), Precision = c(0.910120428, 0.935881939, 0.930419589, 0.858438788,
0.783804275, 0.803642164, 0.867418091, 0.826140299, 0.651388637,
0.683146414, 0.931054424, 0.960414109, 0.913705853, 0.892099619,
0.827661119, 0.917972446), Recall = c(0.890994094, 0.932236205,
0.920874879, 0.808366656, 0.736169166, 0.727917473, 0.76442499,
0.766358025, 0.672936004, 0.544758539, 0.922476135, 0.958934517,
0.889652539, 0.878411911, 0.800769442, 0.9035499), F1_Score = c(0.895340797,
0.929767228, 0.923515392, 0.820549586, 0.740460186, 0.743306797,
0.771715283, 0.778685153, 0.654271508, 0.562382109, 0.923856378,
0.958423427, 0.894510388, 0.881315329, 0.804600327, 0.905468385
), Model = c("CNN", "CNN", "LSTM", "CNN-LSTM", "LSTM-CNN", "CNN",
"LSTM", "LSTM-CNN", "CNN-LSTM", "CNN", "CNN", "LSTM", "CNN",
"LSTM-CNN", "CNN-LSTM", "CNN-LSTM")), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -16L))
I want to do boxplot where I compare the modalities and group by Model. I am using the following code:
library(ggpubr)
library(dplyr)
p <-ggboxplot(df, x = "Model", y = "Accuracy", color = "Modality",
palette = "jco",
add = "jitter", ylab = "Accuracy",
width = 0.7,
lwd = 1.35,
xlab = "Model", legend = "right") +
ggtitle("Boxplot of Accuracy by Model and Modality") +
theme_minimal()
anyNA(df)
The plot is correct. I get 3 boxplots for each Model where the Modality are compared. Now I would like to add a statistical comparison between the Modality within the same model. To do so, I am adding the following line of code:
p + stat_compare_means(comparisons = list(c("EMG", "IMU")), method = "wilcox.test", label = "p.signif")
But no statistical test is appearing. The problem is that I can't add statistical test within the same model with respect to the modality.
I think the issue has to do with the layout of your boxplot. The ?stat_compare_means
help file describes the expected input to the comparisons
argument as follows:
A list of length-2 vectors. The entries in the vector are either the names of 2 values on the x-axis or the 2 integers that correspond to the index of the groups of interest, to be compared.
So, it sounds like the groups you want to compare need to be displayed on the x-axis, but your original plot has Modality represented in the legend.
This code flips the position of Model and Mode. With this adjustment the comparison of interest is displayed as expected.
p <-ggboxplot(df, x = "Modality", y = "Accuracy", color = "Model",
palette = "jco",
add = "jitter", ylab = "Accuracy",
width = 0.7,
lwd = 1.35,
xlab = "Modality", legend = "right") +
ggtitle("Boxplot of Accuracy by Model and Modality") +
theme_minimal()+
stat_compare_means(comparisons = list(c("EMG", "IMU")), method = "wilcox.test", label = "p.signif")