################################################################################## # Hypothesis Testing: significance level (alpha), Type One Error mu <- 0 # population mean, mu, for the "unknown" population sigma <- 2 # population standard deviation, sigma, for the "unkown" population n <- 30 # sample size k <- 1000 # number of samples x <- matrix(rnorm(n*k,mu,sigma),n,k) # This gives a matrix with k = 1000 samples down the columns. alpha <- 0.05 # significance level Count <- 0 # count the number of times reject the null hypothesis # next is a loop that computes the one sample t test for each of the k random samples # and it computes the number of times the null hypothesis is rejected. for(j in 1:k){ x.test <- t.test(x[,j]) if(x.test$p.value < alpha) Count <- Count + 1 } alpha.est <- Count/k # estimated the significance level alpha.est # alpha.est should be approximately equal to alpha