# ============================================================
# BAB 8 - UJI T BERPASANGAN (PAIRED T-TEST)
# ============================================================

# 1. Input Data Sebelum (X) dan Sesudah (Y)
data <- data.frame(
  X = c(78, 75, 67, 77, 70, 72, 78, 74, 77),
  Y = c(100, 95, 70, 90, 90, 90, 89, 90, 100)
)
data
##    X   Y
## 1 78 100
## 2 75  95
## 3 67  70
## 4 77  90
## 5 70  90
## 6 72  90
## 7 78  89
## 8 74  90
## 9 77 100
# 2. Menghitung Selisih (Difference)
selisih <- data$Y - data$X
selisih
## [1] 22 20  3 13 20 18 11 16 23
# 3. Grafik Q-Q Plot Normalitas Selisih
qqnorm(selisih)
qqline(selisih)

# 4. Uji Normalitas Selisih (Lilliefors & Jarque-Bera)
library(nortest)
lillie.test(selisih)
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  selisih
## D = 0.1682, p-value = 0.6544
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
jarque.bera.test(selisih)
## 
##  Jarque Bera Test
## 
## data:  selisih
## X-squared = 1.3935, df = 2, p-value = 0.4982
# 5. Uji T Berpasangan (Paired T-Test)
t.test(data$Y, data$X, paired = TRUE)
## 
##  Paired t-test
## 
## data:  data$Y and data$X
## t = 7.6525, df = 8, p-value = 6.003e-05
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  11.33381 21.11064
## sample estimates:
## mean difference 
##        16.22222