Package install

Packages <- c("tidyverse", "car", "dunn.test","onewaytests","FSA","ggpubr")
lapply(Packages, library, character.only = TRUE)

Data import

Data structure

str(d1)
## 'data.frame':    36 obs. of  3 variables:
##  $ subject: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ group  : Factor w/ 2 levels "post","pre": 2 2 2 2 2 2 2 2 2 2 ...
##  $ time   : num  289 295 294 191 274 ...

Explorative data analysis with graphics

d1$group <-factor(d1$group,levels=c("pre","post"))

ggpaired(d1,x="group", y="time",
         color = "group", line.color = "gray", line.size = 0.6,palette = "jco") +
   ylab("Time (sec)") + theme(legend.title = element_blank())

  # stat_compare_means(paired = TRUE) 

Easystat function for paired_data developed by S. Park & B. Hong (available at https://rpubs.com/koho0127)

paired_easystat=function(d1){
  d1=data.frame(d1) # dataframe으로 전환
  d1[,2]=as.factor(d1[,2]) # 2행을 factor변수로 변환
  lmd=lm(d1[,3]~d1[,2],data=d1) # 선형모형
  swd=shapiro.test(lmd$resid) # 정규성 검정
  if (swd$p.value<0.05){      # p-value가 0.05보다 작다면(정규성 가정 위반)
    cat("1. Normality assumption test by Shapiro_Wilk test is", "\n",
        "p =", paste(format(round(swd$p.value,3), nsamll=3)), "\n",
        "Normality assumption was rejected", "\n")   #
    wt=wilcox.test(d1[,3]~d1[,2],data=d1)             # 비모수 검정인 wilcox test 시행
    if (wt$p.value<0.05){                           
      cat("2. The result of Wilcoxon test is ","\n",
          "p =", paste(format(round(wt$p.value,3), nsmall=3)), "\n",
           "A statistically significant difference exist between groups")
         } else {                                        
      cat( "2. The result of Wilcoxon test is ","\n",
           "p =", paste(format(round(kwd$p.value,3), nsmall=3)), "\n",
           "A statistically significant difference do not exist between groups")
    }
  } 
  else {                      # 정규성 가정을 만족하는 경우
    cat("1. Normality assumption test by Shapiro_Wilk test is", "\n",
        "p =", paste(format(round(swd$p.value,3), nsamll=3)), "\n",
        "Normality assumption was not rejected", "\n")     # 
    pt=t.test(d1[,3]~d1[,2],data=d1, paired =T)                  
    if (pt$p.value<0.05) {                                
      cat("2. The result of paired t-test is", "\n",  
          "p =", paste(format(round(pt$p.value,3), nsmall=3)), "\n",
          "A statistically significant difference exist between groups","\n")
            } 
      else {                                            
        cat("2. The result of paired t-test is",  "\n",   
            "p =", paste(format(round(wtd$p.value,3), nsmall=3)), "\n",
            "A statistically significant difference do not exist between groups")
     
      } }}

Statistical Result

paired_easystat(d1)
## 1. Normality assumption test by Shapiro_Wilk test is 
##  p = 0.04 
##  Normality assumption was rejected 
## 2. The result of Wilcoxon test is  
##  p = 0.000 
##  A statistically significant difference exist between groups