Example R programs and commands 8. R commands for 1-Factor ANOVA with some missing data # All lines preceded by the "#" character are my comments. # All other left-justified lines are my input. # All other indented lines are the R program output. # # Tabulated data for input to R # # ORIGINAL FORMAT # Skateboarding injuries (per 1000 board-hours.) # # Mar Jun Sep # 9.7 9.2 9.6 # 9.8 9.7 9.4 # 9.6 9.8 8.9 # 9.5 8.5 9.4 # 8.4 9.5 # # mar <- c(9.7,9.8,9.6,9.5,NA) # only 4 values jun <- c(9.2,9.7,9.8,8.5,8.4) sep <- c(9.6,9.4,8.9,9.4,9.5) month <- gl(3,5,labels=c("Mar","Jun","Sep")) injuries <- c(mar,jun,sep) result<-anova(lm(injuries~month)) result # Shows the ANOVA results Analysis of Variance Table Response: injuries Df Sum Sq Mean Sq F value Pr(>F) month 2 0.62429 0.31214 1.6749 0.2317 Residuals 11 2.05000 0.18636 # Nonparametric test for equality of densities: kruskal.test(list(mar,jun,sep)) # Kruskal-Wallis test Kruskal-Wallis rank sum test data: list(mar, jun, sep) Kruskal-Wallis chi-squared = 2.9178, df = 2, p-value = 0.2325 # Alternative, ANOVA-like interface for the Kruskal-Wallis test: kruskal.test(injuries~month) # Kruskal-Wallis test Kruskal-Wallis rank sum test data: injuries by month Kruskal-Wallis chi-squared = 2.9178, df = 2, p-value = 0.2325