# Analysis of covariance; data in Table 15-10 y <- c(36, 41, 39, 42, 49, 40, 48, 39, 45, 44, 35, 37, 42, 34, 32) x <- c(20, 25, 24, 25, 32, 22, 28, 22, 30, 28, 21, 23, 26, 21, 15) X <- x - mean(x) machine <- as.factor(rep(1:3, each=5)) data <- data.frame(y, x, machine, X) data g <- lm(y ~ X + machine);anova(g) # To get the p-value and adjusted SS for machines. g0 <- lm(y ~ machine + X);anova(g0) # To get the p-value and adjusted SS for thickness. # Compute the adjusted treatments means and their standard errors: ybar.adj <- se.of.adjusted.mean <- vector(length=3) for(i in 1:3) { prediction <- predict(g, new=data.frame(machine=as.factor(i), X=0), se.fit=T) ybar.adj[i] <- prediction$fit se.of.adjusted.mean[i] <- prediction$se.fit } tau.hat <- ybar.adj - mean(y) cat("Adjusted machine means and their standard errors are", "\n");print.matrix(cbind(tau.hat, ybar.adj, se.of.adjusted.mean))