library(readxl)
library(cowplot)
library(ggplot2)
file_path <- "/Users/jangsieun/Downloads/nonParametric.xlsx"
dat <- readxl::read_excel(file_path)
head(dat)
## # A tibble: 6 × 2
## groupA groupB
## <dbl> <dbl>
## 1 15.9 15.7
## 2 33.9 20.8
## 3 29.1 23.7
## 4 37.7 26.3
## 5 30 34.7
## 6 8.4 40.1
library(tidyr)
long_dat <- gather(dat, key = "group", value = "value")
long_dat
## # A tibble: 90 × 2
## group value
## <chr> <dbl>
## 1 groupA 15.9
## 2 groupA 33.9
## 3 groupA 29.1
## 4 groupA 37.7
## 5 groupA 30
## 6 groupA 8.4
## 7 groupA 12.5
## 8 groupA 19.8
## 9 groupA 12.1
## 10 groupA 17.5
## # ℹ 80 more rows
boxplot_A <- ggplot(long_dat[long_dat$group == "groupA", ], aes(x = value)) +
geom_boxplot(fill = "orange", color = "purple", alpha = 0.5, outliers = FALSE) +
geom_vline(aes(xintercept = mean(value)), color = "red", linetype = "solid", linewidth = 1) +
geom_vline(aes(xintercept = median(value)), color = "black", linetype = "dashed", linewidth = 1) + labs(title = "Group A Boxplot")
boxplot_A
boxplot_B <- ggplot(long_dat[long_dat$group == "groupB", ], aes(x = value)) +
geom_boxplot(fill = "green", color = "purple", alpha = 0.5, outliers = FALSE) +
geom_vline(aes(xintercept = mean(value)), color = "red", linetype = "solid", linewidth = 1) +
geom_vline(aes(xintercept = median(value)), color = "black", linetype = "dashed", linewidth = 1) + labs(title = "Group B Boxplot")
boxplot_B
plot_grid(boxplot_A, boxplot_B, nrow = 1)
shapiro.test(dat$groupA)
##
## Shapiro-Wilk normality test
##
## data: dat$groupA
## W = 0.87756, p-value = 0.0002036
shapiro.test(dat$groupB)
##
## Shapiro-Wilk normality test
##
## data: dat$groupB
## W = 0.87586, p-value = 0.0001823
wilcox.test(dat$groupA, dat$groupB, paired = TRUE)
## Warning in wilcox.test.default(dat$groupA, dat$groupB, paired = TRUE): cannot
## compute exact p-value with ties
##
## Wilcoxon signed rank test with continuity correction
##
## data: dat$groupA and dat$groupB
## V = 621, p-value = 0.245
## alternative hypothesis: true location shift is not equal to 0
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.