Question 1

a)

data <- c(14.2, 16.1, 15.8, 17.2, 14.5, 15.3, 16.8, 15.9, 14.7, 16.4, 15.1, 17.5, 15.6, 16.2, 14.9, 15.7, 16.9, 15.4, 16.6, 15.2)

\[ H_0 : \mu = 15, \space H_\alpha : \mu \neq 15 \] \[ n = 20, \space \alpha = 0.05, \space \bar{x}=15.8\]

(mean(data) - 15)/(sd(data)/sqrt(20)) # t-value
## [1] 3.910959
qt(1 - (0.05/2), 20-1) # critical t-value
## [1] 2.093024

Because t is greater than the critical t, 3.910959 > 2.093024, we can reject the null hypothesis. The medicine does not take effect in 15 minutes

b)

(interval <- qt(1 - (0.05/2), 20-1) * (sd(data)/sqrt(20))) # Interval from mean
## [1] 0.4281352
mean(data) - interval
## [1] 15.37186
mean(data) + interval
## [1] 16.22814

The confidence interval with 95% confidence is [15.37186, 16.22814]

Question 2

a)

before <- c(72, 68, 75, 81, 69, 73, 77, 70, 74, 79)
after <- c(78, 71, 80, 85, 76, 75, 82, 76, 79, 84)
diff <- after - before

\[ H_0 : \mu \leq 0, \space H_\alpha : \mu > 0\] \[ n = 10, \space \alpha = 0.01, \space \bar{d}=4.8\]

mean(diff)/(sd(diff)/sqrt(10)) # t-value
## [1] 10.28571
qt(1 - (0.01/2), 10 - 1) # critical t-value
## [1] 3.249836

Because t is greater than critical t, 10.28571 > 3.249836, we can reject the null hypothesis. The method does improve test scores

b)

(interval <- qt(1 - (0.01/2), 10-1) * (sd(diff)/sqrt(10))) # Interval from mean
## [1] 1.51659
mean(diff) - interval
## [1] 3.28341
mean(diff) + interval
## [1] 6.31659

The confidence interval with 99% confidence is [3.28341, 6.31659]