Example R programs and commands 10. Homoscedasticity vs heteroscedasticity # 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 # # X1 X2 X3 # --- --- --- # 6.9 8.8 1.3 # 7.7 7.5 1.9 # 5.9 8.0 1.8 # 9.6 8.1 2.2 # 7.8 7.0 1.8 # 3.6 8.2 2.1 x1 <- c( 6.9, 7.7, 5.9, 9.6, 7.8, 3.6) x2 <- c( 8.8, 7.5, 8.0, 8.1, 7.0, 8.2) x3 <- c( 1.3, 1.9, 1.8, 2.2, 1.8, 2.1) x <- gl(3,6) # default labels 1,2,3; equal replications (6) per level y <- c(x1,x2,x3) # Bartlett's test of homoscedasticity: bartlett.test(y,x) Bartlett test of homogeneity of variances data: y and x Bartlett's K-squared = 14.4326, df = 2, p-value = 0.0007345 # ... large statistic implies low p-value implies REJECT H_0 # Formula notation gives the same result: bartlett.test(y~x) Bartlett test of homogeneity of variances data: y by x Bartlett's K-squared = 14.4326, df = 2, p-value = 0.0007345 # Nonparametric alternative to Bartlett is called Fligner's test: fligner.test(y~x) Fligner-Killeen test of homogeneity of variances data: y by x Fligner-Killeen:med chi-squared = 6.2885, df = 2, p-value = 0.0431