## Use of Binomial in Sign test n <- 15 K <- 14 pvalue <- 2*(1- pbinom(K-1, size = n, p = 0.5) ) pvalue # finding a 95% C.I. range <- 10:15 pval <- matrix(0,1,length(range)) ind <- 1 for (k in range){ pval[ind] <- 2*(1- pbinom(k-1, size = n, p = 0.5) ) ind <- ind + 1 # next entry in the array } round(rbind(range, pval), 4) # print the results afakesample <- c(1:14,-1.5) # also, do -1 to show ties S <- sum(rank(abs(afakesample))*sign(afakesample)) wilcox.test(afakesample) # Wilcoxon rank-sum test for later # later, let's input the real data; will also get the C.I. X <- read.csv("U:/public_html/588/Class6/schizo.csv") Y <- X[,1] - X[,2] wilcox.test(Y) ## the Book's illustration of the rank-sum test X <- read.csv("U:/public_html/588/Class6/cognitive.csv", header = TRUE) # replace by your own path here boxplot(X[,1] ~ X[,2]) R <- rank(X[,1]) N <- length(R) n1 <- sum(X[,2] == 'MODIFIED') n2 <- N - n1 order(X[,1]) # shows the permutation that orders X X[,1] sort(X[,1]) T <- sum(R[1:n1]) # T = rank-sum statistic # normal approximation meanT <- mean(R)*n1 SDT <- sd(R)*sqrt(n1*n2/N) Z <- (T - meanT)/SDT pvalue <- 2*(1 - pnorm(abs(Z), mean = 0, sd = 1)) # two-tailed p-value print(paste("Approximate p-value=", round(pvalue,4)," on Z-stat=", round(Z,2)) ) ## now the built-in R routine wilcox.test( c(3,4,39), c(1,5,7) ) # our first example wilcox.test(X[,1] ~ X[,2], conf.int = TRUE) # wilcox.test(X[1:14,1], X[15:28,1]) # swap the two samples wilcox.test(X[15:28,1], X[1:14,1]) # google "wilcox.exact" for a package that can do ties