#Ho: Mean commute time for Atlanta = Mean commute time for St. Louis
#Ha: Mean commute time for Atlanta not= Mean commute time for St. Louis
library(Lock5withR)
data(CommuteAtlanta)
data(CommuteStLouis)
atlanta <- CommuteAtlanta$Time
stlouis <- CommuteStLouis$Time
teststat <- mean(atlanta) - mean(stlouis)
teststat
## [1] 7.14
m <-10^4 
sampdist <- rep(0, m) 
lengths <- c(atlanta, stlouis) 
for(i in 1:m){
    choosethese <- sample(1:1000, 500) 
    fakeatlanta <- lengths[choosethese]
    fakestlouis <- lengths[-choosethese]
    sampdist[i] <- mean(fakeatlanta) - mean(stlouis)
}
(numerator <- sum(teststat <= sampdist) + 1)
## [1] 1
denom <- m+1
lowtail <- numerator/denom
2*lowtail
## [1] 0.00019998
hist(sampdist)

boxplot(atlanta, stlouis)

#Since we got a very small p-value, we reject the null hypothesis and can say that the there is a difference in the mean commute time for the two cities.

```