##### SCA-31b ##### ##### Analysis of Variance, II ##### ### This gives a few more examples of ANOVA procedure ### Preamble source("http://rfs.kvasaheim.com/stat200.R") library(agricolae) dt = read.csv("http://rfs.kvasaheim.com/data/stat4013rxtimes.csv") dt$attempt = as.factor(dt$attempt) dt$group = as.factor(dt$group) summary(dt) attach(dt) ### Example 1: Distance by group shapiroTest(distance~group) kruskal.test(distance,group) print( kruskal(distance,group) ) # Conclusion: # Because the p-value of 0.0000 is less than our usual alpha # of 0.05, we reject the null hypothesis. We did detect a # difference in the average distance fallen across the 13 # groups. # # In fact, Group A fell more (on average) of any other group. ### Example 2: Distance by Person Number shapiroTest(distance~person) kruskal.test(distance~person) # Conclusion: # Because the p-value of 0.6050 is greater than our usual # alpha of 0.05, we cannot reject the null hypothesis. We # did not detect a difference in the avearge distance # fallen by the person number within the group. ### Example 3: Distance by Attempt Number shapiroTest(distance~attempt) kruskal.test(distance~attempt) print(kruskal(distance,attempt)) # Conclusion: # Because the p-value of 0.0319 is less than our usual alpha # value of 0.05, we did detect a difference in the average # drop distance based on attempt number. # # In fact, the first attempt was significantly slower than # attempts 2, 3, and 4. ### Example 4: Distance by treatment shapiroTest(distance~treatment) kruskal.test(distance~treatment) print(kruskal(distance,treatment)) # Conclusion: # Because the p-value of 0.0000 is less than the usual alpha # of 0.05, we did detect a difference in average drop # distance between the control and treatment groups. # boxplot(distance~treatment) aggregate(distance, by=list(treatment), mean) # # In fact, we are able to conclude that the control group (singing) # tends to allow the ruler to drop an average of 1.5 inches more # than the control group. # # # By the way, we can use math and physics to estimate just how much # this means in terms of car lengths... # # Since d = 1/2 gt^2, we know t = sqrt(2d/g) time = sqrt(2*distance*2.54/9.80665) aggregate(time, by=list(treatment), mean) # This tells us that the singing group is slower by an average # of 0.23s. # # If a car it traveling 65 mph, this is 65*0.23/60/60 # miles 65*0.23/60/60*5280 # feet # The difference in stopping distances at highway speeds is # 22 feet. Is this a lot? It depends on what is found in # those 22 feet.