C:\Rmisc>C:\R-2.9.0\bin\Rterm --vanilla R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pdf("C:\\Rmisc\\graphs\\amoeba.pdf") > > amoeba1 <- read.fwf("C:\\data\\amoeba.txt", width=c(8,8), col.names=c("Trt", "Yield")) > > fTrt <- factor(amoeba1$Trt, levels=1:5) > levels(fTrt) <- c("None", "H", "F", "HF", "FH") > > amoeba <- data.frame(amoeba1, fTrt) > attach(amoeba) The following object(s) are masked _by_ .GlobalEnv : fTrt > > bonf <- function(y,trt,alpha) { + + ybar <- mean(y) + print("Overall Mean") + print(ybar) + ybar.trt <- as.vector(tapply(y,trt,mean)) + print("Treatment Means") + print(ybar.trt) + var.trt <- as.vector(tapply(y,trt,var)) + print("Treatment Variances") + print(var.trt) + rep.trt <- as.vector(tapply(y,trt,length)) + print("Treatment Replicates") + print(rep.trt) + num.trt <- length(ybar.trt) + print("Number of Treatments") + print(num.trt) + + sse <- 0 + num.pairs <- num.trt*(num.trt-1)/2 + + + for (i1 in 1:num.trt) { + sse <- sse + (rep.trt[i1]-1)*var.trt[i1] + } + print("Error Sum of Squares") + print(sse) + + mse=sse/(sum(rep.trt)-num.trt) + print("Mean Square Error") + print(mse) + + + + print(c("Bonferroni Simultaneous CI's","Alpha=",alpha)) + for(i1 in 1:(num.trt-1)) { + for (i2 in (i1+1):num.trt) { + bonf.msd <- qt(1-alpha/(2*num.pairs),(sum(rep.trt)-num.trt))*sqrt(mse*(1/rep.trt[i1]+1/rep.trt[i2])) + print(c("Bonferroni MSD","Alpha=",alpha)) + print(c(round(c(i1,i2,bonf.msd),2))) + print(c(round(c(i1,i2),0),round(c((ybar.trt[i1]-ybar.trt[i2])-bonf.msd,(ybar.trt[i1]-ybar.trt[i2])+bonf.msd),2))) + }} + + + } > > bonf(Yield,Trt,0.05) [1] "Overall Mean" [1] 210.72 [1] "Treatment Means" [1] 246.4 203.5 196.9 216.5 190.3 [1] "Treatment Variances" [1] 1330.2667 542.2778 256.9889 1596.9444 1146.6778 [1] "Treatment Replicates" [1] 10 10 10 10 10 [1] "Number of Treatments" [1] 5 [1] "Error Sum of Squares" [1] 43858.4 [1] "Mean Square Error" [1] 974.6311 [1] "Bonferroni Simultaneous CI's" "Alpha=" [3] "0.05" [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 1.00 2.00 41.22 [1] 1.00 2.00 1.68 84.12 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 1.00 3.00 41.22 [1] 1.00 3.00 8.28 90.72 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 1.00 4.00 41.22 [1] 1.00 4.00 -11.32 71.12 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 1.00 5.00 41.22 [1] 1.00 5.00 14.88 97.32 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 2.00 3.00 41.22 [1] 2.00 3.00 -34.62 47.82 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 2.00 4.00 41.22 [1] 2.00 4.00 -54.22 28.22 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 2.00 5.00 41.22 [1] 2.00 5.00 -28.02 54.42 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 3.00 4.00 41.22 [1] 3.00 4.00 -60.82 21.62 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 3.00 5.00 41.22 [1] 3.00 5.00 -34.62 47.82 [1] "Bonferroni MSD" "Alpha=" "0.05" [1] 4.00 5.00 41.22 [1] 4.00 5.00 -15.02 67.42 > > > > > > dev.off() null device 1 >