X <- read.csv("Spock.csv", header = TRUE) # replace by your own path here attach(X) lm1 <- lm(PERCENT ~ JUDGE) summary(lm1) mean.Spock <- mean(X[X[,2]=="SPOCK'S",1]) mean.Others <- mean(X[X[,2]!="SPOCK'S",1]) n.Spock <- sum(X[,2]=="SPOCK'S") n.Others <- sum(X[,2]!="SPOCK'S") center <- mean.Others - mean.Spock # Residual standard error: 6.914 on 39 degrees of freedom # the following will do the comparison based on ANOVA's s_p half.width <- qt(0.975, df= 39)*6.914*sqrt(1/n.Spock + 1/n.Others) CI <- c(center-half.width, center + half.width) print( paste("95% C.I. for difference Spock vs Others", CI )) t.test(X[X[,2]=="SPOCK'S",1], X[X[,2]!="SPOCK'S",1]) # are the other judges different? boxplot(PERCENT ~ JUDGE) lm.other <- lm(X[X[,2]!="SPOCK'S",1] ~ X[X[,2]!="SPOCK'S",2]) summary(lm.other) n.B <- sum(X[,2]=="B") n.A <- sum(X[,2]=="A") sp <- 7.321 sp*sqrt(1/n.B + 1/n.A) # compare the result with p. 130 detach(X)