pdf("g06.pdf");options(width=64) #setwd("C:\\Users\\kolassa\\Class555") setwd("~/Taught1/960-555/Data")
#********************************************************/ #* Yarn strength data from Example Q of Cox & Snell */ #* (1981). Variables represent strength of two types of*/ #* yarn collected from six different bobbins. */ #********************************************************/ yarn<-as.data.frame(scan("yarn.dat",what= list(strength=0, bobbin=0,type=""))) # Block 1 yarna<-yarn[yarn$type=="A",] cat('\nMultiple Comparisons for Yarn with No Correction\n') pairwise.wilcox.test(yarna$strength,yarna$bobbin,exact=F, p.adjust.method="none") # Block 2 library(MultNonParam)#For higgins.fisher.kruskal.test higgins.fisher.kruskal.test(yarna$strength,yarna$bobbin) # Block 3 # pairwise.wilcox.test corrects for multiple comparisons # methods using only on p-values. This requirement # excludes methods of Tukey and Scheffe. cat('\nBonferroni Comparisons for Yarn Type A Data\n') pairwise.wilcox.test(yarna$strength,yarna$bobbin, exact=F,p.ajust.method="bonferroni") # Block 4 library(MultNonParam)#For tukey.kruskal.test tukey.kruskal.test(yarna$strength,yarna$bobbin) # The data at HTTP://lib.stat.cmu.edu/datasets/Andrews/T58.1 # represent corn (maize) yields resulting from various fertilizer # treatments. Test the null hypothesis that corn weights # associated with various fertilizer combinations have the same # distribution, vs. the alternative hypothesis that a measure of # location varies among these groups. Treatment is a three-digit # string representing three fertilizer components. Fields in this # file are separated by space. The first three fields are example, # table, and observation number. The fourth and following fields # are location, block, plot, treatment, ears of corn, and corn weight. # Location TEAN has no ties; restrict attention to that location. # The yield for one of the original observations 36 was missing # (denoted by -9999 in the file), and is omitted in this analysis. # We calculate the Kruskal-Wallis test, with 12 groups, and hence maize<-as.data.frame(scan("T58.1",what=list(exno=0,tabno=0, lineno=0,loc="",block="",plot=0,trt="",ears=0, wght=0))) maize$wght[maize$wght==-9999]<-NA maize$nitrogen<-as.numeric(substring(maize$trt,1,1)) # Block 5 library(clinfun)# For jonckheere.test maize$wght[maize$wght==-9999]<-NA #Location TEAN has no tied values. R treats ranks of #missing values nonintuitively. Remove missing values. maize$nitrogen<-as.numeric(substring(maize$trt,1,1)) tean<-maize[(maize$loc=="TEAN")&(!is.na(maize$wght)),] # Perform the Jonckheere-Terpstra test jonckheere.test(tean$wght,tean$nitrogen) cat('\n K-W Test for Maize, to compare with JT \n') kruskal.test(tean$wght,tean$nitrogen) # Block 6 library(MultNonParam)#For terpstrapower, kwpower, kwsamplesize, kweffectsize terpstrapower(rep(20,3),(0:2)/2,"normal") # Block 7 kwpower(rep(20,3),(0:2)/2,"normal") # Block 8 kwsamplesize((0:2)/2,"normal") # Block 9 kwsamplesize((0:2)/2,"normal",taylor=TRUE) # Block 10 kweffectsize(60,(0:2)/2,"normal") # Block 11 library(MultNonParam)#For powerplot #powerplot uses Monte Carlo, and the default #sample size is large enough to make it slow. powerplot()