# Doing normal Q-Q plots in R: # generating some normal data: norm.data <- rnorm(300) qqnorm(norm.data) # generating some heavy-tailed data: t.data <- rt(300, df=2) qqnorm(t.data) # generating some light-tailed data: unif.data <- runif(300, min=-1, max=1) qqnorm(unif.data) # generating some right-skewed data: expon.data <- rexp(300) qqnorm(expon.data) # generating some left-skewed data: neg.expon.data <- -rexp(300) qqnorm(neg.expon.data) ### Note the characteristic shape of the Q-Q plot for each data set. #### Wilcoxon Signed Rank Test: ## Data from Example 1, Page 355: first<-c(86,71,77,68,91,72,77,91,70,71,88,87) second<-c(88,77,76,64,96,72,65,90,65,80,81,72) wilcox.test(second,first,paired=T, alternative="less", exact=T) # Note that it gives the T+ value of 24.5 (see the last paragraph of the example) # and says it can't give the exact p-value because of the ties. # The p-value it does give is very close to the 0.238 that the example reports using equation 7. # The same answer could have been gotten using the differences instead of the paired option: diffs <- second-first wilcox.test(diffs,alternative="less") ## Data from Problem 1, page 365: before <- c(.68,.64,.68,.82,.58,.80,.72,.65,.84,.73,.65,.59,.78,.67,.65,.76,.61,.86,.74,.88) after <- c(.73,.62,.66,.92,.68,.87,.77,.70,.88,.79,.72,.60,.78,.66,.68,.77,.72,.86,.72,.97) qqnorm(after-before) wilcox.test(after,before, paired=TRUE, alternative="two.sided", exact=T) #### Example 3: # Data on pollution around a chemical plant, from Rao (p. 137). # Two independent samples of river water were taken, # one upstream and one downstream. # Pollution level was measured in ppm. downstream <- c(32.8,30.4,32.3,26.4,27.8,26.9,29.0,31.5,31.2,26.7,25.6,25.1,32.8,34.3,35.4) wilcox.test(downstream,mu=34,alternative="less",exact=T) ### A function to calculate the CI as described on p. 360-361: WSRci<-function(d,conf.level=.95){ d<-sort(d) n<-length(d) alpha<-1-conf.level thematrix<-matrix(d,ncol=n,nrow=n,byrow=T)+matrix(d,ncol=n,nrow=n,byrow=F) thematrix<-thematrix[!upper.tri(thematrix)]/2 tablevalue<-qsignrank(alpha/2,n) estimator<-median(thematrix) clow<-sort(thematrix)[tablevalue] chi<-sort(thematrix)[n*(n+1)/2+1-tablevalue] list(matrix.values=thematrix,table.value=tablevalue,estimator=estimator,interval=c(clow,chi))} ## Example 2 data: WSRci(after-before, conf.level=0.95) ## Example 3 data: WSRci(downstream, conf.level=0.95)