We begin by performing some one-sample t-tests using the t.test() function. First we create 100 variables, each consisting of 10 observations. The first 50 variables have mean 0.5 and variance 1, while the others have mean 0 and variance 1.

set.seed(6)
x <- matrix(rnorm(10 * 100), nrow = 10, ncol = 100)
x[, 1:50] <- x[, 1:50] + 0.5 # mean 0.5

The t.test() function can perform a one-sample or a two-sample t-test. By default, a one-sample test is performed. First, we consider the first variable with a true mean of 0.5. To begin, we test \(H_0 : \mu_1 = 0\), the null hypothesis that the first variable has mean zero.

> t.test(x[, 1], mu = 0)
	One Sample t-test
data:  x[, 1]
t = 2.0841, df = 9, p-value = 0.06682
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 -0.05171076  1.26242719
sample estimates:
mean of x 
0.6053582 

The p-value comes out to \(0.067\), which is not quite low enough to reject the null hypothesis at level \(\alpha = 0.05\). Therefore, we have made a Type II error by failing to reject the null hypothesis when the null hypothesis is false.

Question