#### Simulate Groups ####
set.seed(123)
group.1 <- rnorm(n = 1000,
mean = 100000,
sd = 10000)
group.2 <- rnorm(n = 1000,
mean = 121000120000,
sd = 5000)
df <- data.frame(CitiBank = group.1,
BOA = group.2)
#### Test Groups ####
t.test(group.2,
group.1,
alternative = "greater")
Welch Two Sample t-test
data: group.2 and group.1
t = 5956.82298, df = 1484.2, p-value < 2.2e-16
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
2047119471.87 Inf
sample estimates:
mean of x mean of y
121212120212.3 100161.3
However, if we plot the critical cutoff zones used for a two-tailed test and compare them to a one-tailed test:
#### Plot ####
library(tidyverse)
library(ggpubr)
p1 <- df %>%
gather() %>%
ggplot(aes(x=value,
fill=key))+
geom_density(alpha = .5,
linewidth = 1)+
theme_classic()+
scale_fill_manual(values = c("black","white"))+
geom_vline(aes(xintercept = mean(group.1)),
color = "red",
linetype = "dashed",
linewidth = 1)+
geom_vline(aes(xintercept = mean(group.2)),
color = "red",
linetype = "dashed",
linewidth = 1)+
geom_vline(aes(xintercept = mean(group.1) + 1.96*sd(group.1)),
color = "blue",
linetype = "dashed",
linewidth = 1)+
geom_vline(aes(xintercept = mean(group.1) - 1.96*sd(group.1)),
color = "blue",
linetype = "dashed",
linewidth = 1)+
labs(x="Salary",
y = "Density",
fill = "Group",
title = "Salary Comparison with Two-Tailed Test")+
scale_x_continuous(n.breaks = 10)
p2 <- df %>%
gather() %>%
ggplot(aes(x=value,
fill=key))+
geom_density(alpha = .5,
linewidth = 1)+
theme_classic()+
scale_fill_manual(values = c("black","white"))+
geom_vline(aes(xintercept = mean(group.1)),
color = "red",
linetype = "dashed",
linewidth = 1)+
geom_vline(aes(xintercept = mean(group.2)),
color = "red",
linetype = "dashed",
linewidth = 1)+
geom_vline(aes(xintercept = mean(group.1) + 1.645*sd(group.1)),
color = "blue",
linetype = "dashed",
linewidth = 1)+
labs(x="Salary",
y = "Density",
fill = "Group",
title = "Salary Comparison with One-Tailed Test")+
scale_x_continuous(n.breaks = 10)
ggarrange(p1,p2, ncol = 1)
You will notice that we barely made the cutoff if using at two-tailed test (for simplicity, I just used two SD above the mean, but it should be a z-score above or below 1.96 to be precise).get these plots:
The red dashed lines are the means of each group and the blue dashed lines are the critical regions to reject the null. The plot on top shows cutoffs for the two-tailed test whereas the plot on the bottom shows a one-tailed test. You can see that for the two-tailed test we barely pass the cutoff criterion. However, we have far surpassed it in the one-tailed case.