Someone plotted this data for me in prism using KW and Dunn’s and I wanted to do it in R, but I’m getting way different R results. For instance, in prism there are sig differences between the control and treatments in all three facets. Also I’m getting an error of:
Warning messages:
1: Computation failed in stat_signif()
.
Caused by error in kruskal.test.default()
:
! all observations are in the same group
2: Computation failed in stat_signif()
.
Caused by error in kruskal.test.default()
:
! all observations are in the same group
library(tidyverse)
library(ggpubr)
library(FSA)
library(rcompanion)
DTData <- read.csv("C:/Users/Coral HD/R/Amox/LiquidInhibition/LiquidInhib_ZeroAmox.csv")
data$Day <- as.factor(data$Day)
data$Treatment <- as.factor(data$Treatment)
# Create a faceted bar plot
p <- ggplot(data, aes(x=Treatment, y=CFUs, fill=Treatment)) +
geom_bar(stat="summary", fun=mean) +
facet_wrap(~ Day, scales="fixed") +
labs(title="CFUs by Treatment across Different Days", y="Mean CFUs", x="Treatment") +
theme_bw()
print(p)
# Perform Kruskal-Wallis Test by Day
kw_results <- data %>%
group_by(Day) %>%
summarise(Kruskal_Wallis = kruskal.test(CFUs ~ Treatment)$p.value)
# Print Kruskal-Wallis results
print(kw_results)
# Perform Dunn's Test for multiple comparisons
dunn_results <- list()
for (day in unique(data$Day)) {
subset_data <- data[data$Day == day,]
dunn_test <- dunnTest(CFUs ~ Treatment, data = subset_data, method = "bonferroni")
dunn_results[[as.character(day)]] <- dunn_test
}
# Print Dunn's Test results
print(dunn_results)
# Adding significance brackets
# Please note: Adjusting manually as per p-values might be necessary
p + stat_compare_means(label = "p.signif", method = "kruskal.test",
comparisons = list(c("0", "100"), c("0", "400"), c("100", "400")),
label.y = c(300, 400, 500))
structure(list(Day = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L), levels = c("1", "14", "28"), class = "factor"),
Treatment = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L), levels = c("0", "100", "400"), class = "factor"),
CFUs = c(138L, 148L, 141L, 0L, 0L, 0L, 0L, 0L, 0L, 348L,
290L, 321L, 0L, 0L, 0L, 0L, 0L, 0L, 250L, 215L, 218L, 28L,
45L, 34L, 35L, 41L, 28L)), row.names = c(NA, -27L), class = "data.frame")