# # 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. # #----- twenty_dollar = c( 3, 1, 2, 4, 0, 5, 4, 5, 1, 3 ) one_dollar = c( 4, 8, 6, 9, 3, 6, 7, 10, 4, 8 ) # We lump both data sets together and then randomly select the items to be in the "twenty_dollar" group # (while the others will then be in the "one_dollar" group): # data = c( twenty_dollar, one_dollar ) # The statistic is the sum of the responses in the one_dollar sample: # X = sum( one_dollar ) # Generate the needed combinations of the total data and apply our statistic function to each combination: Perm_Test_Data = combn( data, length(one_dollar), sum ) #postscript("../../WriteUp/Graphics/Chapter3/ex_5_permutation_test.eps", onefile=FALSE, horizontal=FALSE) hist( Perm_Test_Data, breaks=20, xlab="sum of samples labeled one_dollar", 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) )