데이터 소스: nonParametrix.xlsx

Q) groupA와 groupB의 평균이 같은지 혹은 다른지에 대하여 유의수준 5%으로 검정하시오

분석 절차

1) 가설 세우기

2) 박스 플랏으로 시각화 (실습 3에서 했던 코드 참고하여 작성)

3) 정규성 검정 (필요한 경우 수행)

4) 두집단의평균비교를위한test수행

5) 유의수준 5%에서 가설검정 결과에 대해 서술하기

  • readxl 패키지를 로드
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

Q1. 가설 세우기

Q2. 박스플랏으로 시각화

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)

Q3.정규성 검정(필요한 경우에 수행)

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

Q4. 두 집단의 평균 비교를 위한 test 수행

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

Q5. 유의수준 5%에서 가설검정 결과에 대해 서술하기

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.