#################
# Two Sample Tests
#################
# A fake two sample t-test
#Fake because we're going to draw from the same population
pop <- rnorm(n = 100000,
mean = 125000, sd=35000)
diffs <- NA
for (i in 1:1000){
sample1 <- sample(pop, 100)
sample2 <- sample(pop, 100)
diffs[i] <- mean(sample1) - mean(sample2)
}
hist(diffs, main = "Random chance \n difference in two samples \n from the same population", xlab = "Difference in sample means")
#Its easier to interpret how the tests work if we z-score the population first
diffsZ <- (diffs - mean(diffs))/sd(diffs)
hist(diffsZ, main = "Random chance \n difference in two samples \n from the same population \n (Z-scored)", xlab = "Difference in sample means")
Count_ChanceBigDiffs <- length(diffsZ[diffsZ > 2 | diffsZ < -2])
Count_ChanceBigDiffs/1000