# Lấy dữ liệu sạch để thao tác
clean_data <- openxlsx::read.xlsx("04_Ket_qua.xlsx")
group_unhappy <- clean_data$calculated_total[clean_data$is_happy_customer == 0]
group_happy <- clean_data$calculated_total[clean_data$is_happy_customer == 1]
options(scipen = 999)
par(mfrow = c(1, 2))
qqnorm(group_unhappy, main = "Q-Q Plot: Unhappy (0)", pch = 19, col = "black")
qqline(group_unhappy, col = "red", lwd = 2)
qqnorm(group_happy, main = "Q-Q Plot: Happy (1)", pch = 19, col = "black")
qqline(group_happy, col = "red", lwd = 2)
par(mfrow = c(1, 1))
shapiro_unhappy <- shapiro.test(group_unhappy)
shapiro_happy <- shapiro.test(group_happy)
shapiro_unhappy
##
## Shapiro-Wilk normality test
##
## data: group_unhappy
## W = 0.21727, p-value < 0.00000000000000022
shapiro_happy
##
## Shapiro-Wilk normality test
##
## data: group_happy
## W = 0.2039, p-value < 0.00000000000000022
# t-test để kiểm định hai mẫu
t_test_result <- t.test(
calculated_total ~ is_happy_customer,
data = clean_data,
alternative = "less",
conf.level = 0.95
)
# Xuất kết quả
t_test_result
##
## Welch Two Sample t-test
##
## data: calculated_total by is_happy_customer
## t = -2.0509, df = 471.76, p-value = 0.02041
## alternative hypothesis: true difference in means between group 0 and group 1 is less than 0
## 95 percent confidence interval:
## -Inf -2175.879
## sample estimates:
## mean in group 0 mean in group 1
## 14839.71 25918.44