#21 X <- read.csv("umpires.csv", header = TRUE) n <- length(X[,1]) # this trick will do subsetting Y1unc <- X[X[,2] == 0,1] Y2unc <- X[X[,2] == 0,3] boxplot(Y1unc, Y2unc) t.test(Y1unc, Y2unc) # this is wrong on two levels: # 1) the variances are widely different # 2) the samples are not independent! plot(Y2unc, Y1unc) cor(Y2unc, Y1unc) ## correct way Y <- X[,1] - X[,3] # we recognize this as a paired sample # Y <- X[,1]/X[,3] another possibility Yunc <- Y1unc - Y2unc # only uncensored data hist(Yunc) t.test(Yunc) # this test is invalid, however, due to censoring wilcox.test(Yunc) # t.test(Yunc, mu = 1) # these are for Y <- X[,1]/X[,3] option # wilcox.test(Yunc, mu = 1) #22 y1 <- c(5.79, 1579.52, 2323.70) y2 <- c(68.8, 108.29, 110.29, 426.07, 1067.60) # these are ridiculously accurate! y1 <- log(y1) y2 <- log(y2) sp <- sqrt( (var(y1)*2 + var(y2)*4 )/6) print(sp) #26 X <- read.csv("dioxin.csv", header = TRUE) logD <- log(X[,1]+0.5) boxplot(logD ~ X[,2]) t.test(logD ~ X[,2], var.equal = TRUE) # this option will perform the "pooled" t-test favored by the book #32 X <- read.csv("tuition_3-32.csv", header = TRUE) par(mfrow =c(1,2)) # will create two plots in the same window boxplot(X[,1], X[,2], X[,3]) X <- log(X) boxplot(X[,1], X[,2], X[,3]) # this is done for a multiplicative effect # part (a) t.test(X[,3], X[,2], paired=TRUE) exp(c(0.926, 1.224)) # this is the C.I. for the ratio # out of state: in state is 2.52 to 3.40 times plot(X[,2], X[,3]) lines( c(0,mean(X[,2])), c(0, mean(X[,3])) ) # this is a naive fit for the X3 = X*beta equation plot(exp(X[,2]), exp(X[,3]), xlim=c(0,3500), ylim=c(0,10000)) # however, original data could also follow a linear relationship plot(exp(X[,2]), exp(X[,3])) # part (b) t.test(X[,1], X[,3]) exp(c(0.339, 0.804)) # this is the C.I. for the ratio # private: public(out of state) is 1.40 to 2.23 times