rm(list=ls(all=TRUE)) # clear all variables # Programmed by Greg Francis (gfrancis@purdue.edu) October 2019 # Explores the multiple testing problem in hypothesis testing # sample size n = 200 numPopulations = 10 PopulationMeans = 0* c(1:numPopulations) PopulationSDs = 100+0*c(1:numPopulations) alpha = 0.05 # Type I erorr rate (must be bigger than 0 and less than 1) numRepeats = 5000 pValues <-0*c(1:numRepeats) # To hold result of t-test for(rep in c(1:numRepeats)){ # Draw a random sample from each group and run a test minPvalue = 1 for(i in c(1:numPopulations)){ Xvalues <- rnorm(n, mean= PopulationMeans[i], sd= PopulationSDs[i]) testResults <- t.test(Xvalues, mu=0, conf.level = (1-alpha)) if(testResults$p.value < minPvalue){minPvalue = testResults$p.value } } pValues[rep] <- minPvalue } # Compute proportion of significant test results propSignificant <-length(pValues[pValues <= alpha])/length(pValues) cat("------\n") cat("With", numPopulations,"populations, the probability of getting at least one significant test is: ", propSignificant, "\n")