# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- treated = c( 121, 118, 110, 90 ) untreated = c( 95, 34, 22, 12 ) # We lump both data sets together and then randomly select four items to be the "treated" # (the others are the untreated): # data = c( treated, untreated ) # The statistic is the sum of the life lengths of the treated # X = sum( treated ) # Generate the needed combinations of the total data and apply our statistic function to each combination: Perm_Test_Data = combn( data, length(treated), sum ) #postscript("../../WriteUp/Graphics/Chapter3/ex_1_permutation_test.eps", onefile=FALSE, horizontal=FALSE) hist( Perm_Test_Data, breaks=20, xlab="sum of samples labeled treated", main="Possible Values for the Test Statistic under the Null Hypothesis" ) abline( v=X, col='red' ) #dev.off() # What is the probability of getting the value obtained (or a larger one): # alpha = sum( Perm_Test_Data >= X ) / length( Perm_Test_Data ) print( sprintf("alpha (prob. type I error): %10.6f", alpha) )