# # 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. # #----- corner = c( 10, 16, 23, 23, 19, 16, 12, 18 ) side = c( 7, 10, 24, 18, 15, 18, 11, 14 ) # We lump both data sets together and then randomly select the items to be in the "corner" group # (while the others will then be in the "side" group): # data = c( corner, side ) # The statistic is the sum of the responses in the corner sample: # X = sum( corner ) # Generate the needed combinations of the total data and apply our statistic function to each combination: Perm_Test_Data = combn( data, length(corner), sum ) #postscript("../../WriteUp/Graphics/Chapter3/ex_6_permutation_test.eps", onefile=FALSE, horizontal=FALSE) hist( Perm_Test_Data, breaks=20, xlab="sum of samples labeled corner", 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) )