library(knitr)
opts_chunk$set(echo = TRUE )
Package install
Packages <- c("tidyverse", "car", "dunn.test","onewaytests","FSA","ggpubr")
lapply(Packages, library, character.only = TRUE)
Data import
d1<- read.csv("/Users/koho0/Desktop/amplitude.csv")
Data structure
str(d1)
## 'data.frame': 14 obs. of 3 variables:
## $ subject: int 1 2 3 4 5 6 7 1 2 3 ...
## $ group : chr "pre" "pre" "pre" "pre" ...
## $ pA : num 48.8 49.9 70.6 54.7 80.8 ...
Explorative data analysis with graphics
d1$group <-factor(d1$group,levels=c("pre","post"))
ggpaired(d1,x="group", y="pA",
color = "group", line.color = "gray", line.size = 0.6,palette = "jco") +
ylab("pA") + 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(wt$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(pt$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.479
## Normality assumption was not rejected
## 2. The result of paired t-test is
## p = 0.095
## A statistically significant difference do not exist between groups