Two sample T - test

library(readxl)
## Warning: package 'readxl' was built under R version 3.5.2
Promotion <- read_excel(file.choose())
View(Promotion)
attach(Promotion)
Promotion2 <- Promotion[,4:5]
View(Promotion2)
colnames(Promotion2)
## [1] "Interest Rate Waiver ($ spent)" "Standard Promotion ($ spent)"
colnames(Promotion2) <- c("IDAY","CHR")
#changing column names
View(Promotion2)
attach(Promotion2)
##Normality Test##
qqnorm(IDAY)

# This is the Plot which shows the Normality test.
shapiro.test(IDAY)
## 
##  Shapiro-Wilk normality test
## 
## data:  IDAY
## W = 0.99237, p-value = 0.2246
# P value = 0.2246 > 0.05 so p high null fly => It follows normal distribution
shapiro.test(CHR)
## 
##  Shapiro-Wilk normality test
## 
## data:  CHR
## W = 0.99198, p-value = 0.1916
# P value = 0.1916 > 0.05 so p high null fly => it follows normal distribution


#####variance test####
var.test(IDAY,CHR)
## 
##  F test to compare two variances
## 
## data:  IDAY and CHR
## F = 1.0587, num df = 249, denom df = 249, p-value = 0.653
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.8253538 1.3580188
## sample estimates:
## ratio of variances 
##             1.0587
## p- value = 0.653 > 0.05 so p high null fly => equal variance

t.test(IDAY,CHR)
## 
##  Welch Two Sample t-test
## 
## data:  IDAY and CHR
## t = 2.2604, df = 497.6, p-value = 0.02423
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##    9.301912 132.920168
## sample estimates:
## mean of x mean of y 
##  1637.500  1566.389
## The below code is not mandatory in update version
t.test(IDAY,CHR,alternative = "two.side",conf.level = 0.95,correct = TRUE)
## 
##  Welch Two Sample t-test
## 
## data:  IDAY and CHR
## t = 2.2604, df = 497.6, p-value = 0.02423
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##    9.301912 132.920168
## sample estimates:
## mean of x mean of y 
##  1637.500  1566.389
# alternative ="two.sided" means we are checking for equal and unequal
# Means
# null Hypothesis -> Equal means
# alternative hypotheis -> unequal hypothesis
# P-Value = 0.02423 < 0.05 accept alternate hypothesis
# unequal means

#?t.test
t.test(IDAY,CHR,alternative = "greater",var.equal = T)
## 
##  Two Sample t-test
## 
## data:  IDAY and CHR
## t = 2.2604, df = 498, p-value = 0.01211
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  19.26892      Inf
## sample estimates:
## mean of x mean of y 
##  1637.500  1566.389
# alternative ="greater means true difference is greater than 0
# Null hypothesis -> (IDAY-CHR) < 0
# Alternative Hypothesis -> (CHR-IDAY)>0
# P value = 0.01211 < 0.05 => p low null go => accept alternate hypothesis
# IDAY better than  CHR sales.