##Preliminaries
rm(list = ls())
##PART 1 ## Question 1
x.var <- seq(0, 60, 1)
probs <- dbinom(x.var, 60, .5)
plot(x.var, probs, type = "h")
##Question 2
qbinom(p = .05, 60, .5)
## [1] 24
##Question 3
set.seed(34252777)
rbinom(n = 1, 60, .5)
## [1] 28
You would fail to reject the null because in question 2 we got that you would need to have 24 or less people who have asparagus pee but in my sample I got 28 which is greater than 24.
##Question 4
set.seed(34252777)
sim = rbinom(n = 100, 60, .4)
sum(sim>28)
## [1] 12
There are 12 times that you would fail to reject the null hypothesis. You would have a type 2 error in this case because you fail to reject the null hypothesis when you should reject it.
##Question 5
x.var <- seq(0, 180, 1)
probs <- dbinom(x.var, 180, .5)
plot(x.var, probs, type = "h")
qbinom(p = .05, 180, .5)
## [1] 79
set.seed(34252777)
sim = rbinom(n = 100, 180, .4)
sum(sim>79)
## [1] 13
Out of the 100 trials, you reject the null hypothesis 87 and fail to reject it 13 times. ##Question 6 The moral here is that you need to take multiple samples in order to get a complete understanding of whether or not you should truly reject or fail to reject the null hypothesis. There is always a chance of getting a type 1 ot type 2 error if you take a small sample because the likelihood of getting an error is higher.
##PART 2: ##Question 7
x.var <- seq(0, 60, 1)
probs <- dbinom(x.var, 60, .4)
plot(x.var, probs, type = "h")
##Question 8
qbinom(p = .05, 60, .4)
## [1] 18
You would need to get 18 or less asparagus-pee-smellers out of a sample of 60 in order to receive a value of p<.05
##Question 9
set.seed(34252777)
rbinom(n = 1, 60, .4)
## [1] 26
You would fail to reject the null hypothesis because we got that you would need to have 18 or less people who have asparagus pee but in my sample I got 26 which is greater than 18.
##Question 10
set.seed(34252777)
sim = rbinom(n = 100, 60, .4)
sum(sim>26)
## [1] 27
There are 27 times that you would reject the null hypothesis. You would have a type 1 error in this case because you reject the null hypothesis when you should fail to reject it.
##Question 11 You would expect to reject the null hypothesis 5% of the time so you would expect to reject it 5 times out of the 100 samples of 60 people that are done.