# Author: Adolfo J. Rumbos # Date: 9/2/2008 # # This code performs a randomization test on a subset of the Westvaco # data found on page 5 of Statistics in Action by Watkins, Sheaffer and # Cobb. # # The subset consists of the 10 hourly workers involved the second of # the five rounds of layoffs. Three of the 10 workers were laid off # in that round. # # The 10 hourly workers involved in the 2nd round of layoffs are entered into # a vector called hourly2 # hourly2 <- c(25,38,56,48,55,64,55,55,33,35) # # This code draws random samples of size 3, without replacement, # from hourly2, and determines whether the average is >=58. # The sampling is repeated NRep times. The proportion of the # samples that have an average age or 58 or more, p_hat, is computed. # NRep <- 1000 # NRep is the number of samples drawn NYes <- 0 # NYes counts the number of samples that have mean # of 58 or more for (i in 1:NRep) # Sets up a loop from 1 to NRep { # Begins body of loop NYes <- NYes + (mean(sample(hourly2,3,replace=F))>=58) } # End of loop p_hat <- NYes/NRep # Computes observed proportion, p_hat, of samples with mean # larger than or equal to 58 p_hat # Prints p_hat