# Solution to BPS Exercise 15.16 score.change = c(0,0,0,0,24,24,24,24) #15.16a groups = sample(c(1,1,1,1,2,2,2,2)) agroup = score.change[groups == 1] bgroup = score.change[groups == 2] print("a group mean:") print(mean(agroup)) print("b group mean:") print(mean(bgroup)) print("difference of means") print(mean(agroup) - mean(bgroup)) #15.16b n = 10000 trials = replicate(n,{ groups = sample(c(1,1,1,1,2,2,2,2)); agroup = score.change[groups == 1]; bgroup = score.change[groups == 2]; mean(agroup) - mean(bgroup); }) barplot(table(trials))