# R Example for Generalized Random Block Design # We analyze the Task Completion data in Section 21.7. # Save the data file into a directory and # use the full path name: taskcomp.data <- read.table(file = "z:/My Documents/teaching/stat_705/taskcompletiondata.txt", header=FALSE, col.names = c('time', 'gender', 'distract', 'subject')) # attaching the data frame: attach(taskcomp.data) # Making "gender" and "distract" factors: gender <- factor(gender) distract <- factor(distract) # The response is time required to complete a task. # Gender will serve as the blocking factor here. # In the data above, 1 = male and 2 = female. # Distraction level is the treatment factor of primary interest. # In the data, 1 = low distraction, 2 = high distraction. # There are d = 4 observations per trt-block combination, # so we use a generalized random block model. # The block levels are clearly fixed in this case (why?). # The distraction levels are also fixed. # We analyze the data with the lm() and anova() functions as usual: # Fitting the ANOVA model and producing the ANOVA table: taskcomp.fit <- lm(time ~ distract + gender + distract:gender); anova(taskcomp.fit) # We see a significant effect due to distraction # (F* = 20.17, P-value = .0007). # Since there are only 2 levels of distraction, # there is no need for further comparisons.