pdf("ex0601.pdf") # Read in data from ASCII formatted (Fixed With File) ex0601dat <- read.fwf("http://www.stat.ufl.edu/~winner/data/biostat/ex0601.dat", width=c(8,8), col.names=c("trt","cd4")) # Make trt a qualitative factor and assign names to levels treatment <- factor(ex0601dat$trt,levels=1:3) levels(treatment) = c("SZZ","SZ","ZZ") # Create a dataset (frame) from input data ex0601 <- data.frame(ex0601dat, treatment) # Attach the dataset for analysis attach(ex0601) # Conduct the One-Way ANOVA comparing change in cd4 by treatment (aov stands for analysis of variance) # cd4 is the dependent variable, trt is independent variable aov(cd4~treatment) # Obtain pairwise comparisons (Bonferroni's method) among treatment means (Prints out Bonferroni # corrected P-values = individual t-test P-value * # of comparisons) pairwise.t.test(cd4,treatment,p.adj="bonferroni") # Obtain Tukey HSD comparisons of treatment means # cd4.aov saves results from running the ANOVA cd4.aov <- aov(cd4~treatment) # Print out the ANOVA table anova(cd4.aov) # Obtain Tukey's Comparisons among levels of treatment TukeyHSD(cd4.aov, "treatment") dev.off()