pdf("ex0603.pdf") ex0603dat <- read.fwf("http://www.stat.ufl.edu/~winner/data/biostat/ex0603.dat", width=c(10,10,10), col.names=c("subj", "intagnt", "thcl")) # Create qulitative factor variable for intagnt, and assign names to levels fintagnt <- factor(ex0603dat$intagnt, levels=1:3) levels(fintagnt) <- c("placebo", "pepcid", "tagamet") # We have to assign subj (Subject id) as a factor level or the linear model will treat # it as a numeric (continuous) variable and fit a regression ex0603 <- data.frame(thcl=ex0603dat$thcl, fintagnt, subj=factor(ex0603dat$subj)) attach(ex0603) tapply(thcl, fintagnt, mean) # marginal mean for interacting agent tapply(thcl, subj, mean) # marginal mean for subject # Fit the ANOVA for the RBD with subject and interacting agent as independent variables ex0603.rbd <- aov(thcl ~ subj + fintagnt) anova(ex0603.rbd) TukeyHSD(ex0603.rbd,"fintagnt") dev.off()