eye<-c(0.4, 4.6, 2.2, 1.2, 4.5, 5.7, 8.0, 2.1, 4.8, 3.0, 8.8, 11.4, 1.3, 1.4, 2.1, 1.3, 12.5, 2.4, 4.6, 2.8) plot(density(eye)) ##### signed test B<-sum(eye >= 5) binom.test(B, length(eye), 0.5, alternative="less") ####### One sample test x<-rnorm(10, mean=6) wilcox.test(x, mu=5, alternative="less") ####### two-sample test: Wilcoxon Rank Sum test # Two-sample test. ## Hollander & Wolfe (1973), 69f. ## Permeability constants of the human chorioamnion (a placental ## membrane) at term (x) and between 12 to 26 weeks gestational ## age (y). The alternative of interest is greater permeability ## of the human chorioamnion for the term pregnancy. x <- c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46) y <- c(1.15, 0.88, 0.90, 0.74, 1.21) wilcox.test(x, y, alternative = "greater", exact = FALSE, correct = FALSE) # H&W large sample hel# approximation ##### Permutation Test x<-rnorm(10, mean=10, sd=1) y<-rnorm(20 , mean=11.2, sd=1) group<-rep(c(0,1), c(10, 20)) dat<-data.frame(c(x,y), group) stripchart(dat[,1] ~ dat[,2], pch=16, method="jitter", jitter=0.2, vertical=TRUE, ylab="Score", xlab="group", ylim=c(min(dat[,1]), max(dat[,1]))) abline(v=1, col="grey", lty=2) abline(v=2, col="grey", lty=2) lines(x=c(0.9, 1.1), rep(mean(dat[dat$group==0,1]),2), col=4) lines(x=c(1.9, 2.1), rep(mean(dat[dat$group==1,1]),2), col=4) tout<-t.test(x,y) names(tout) tobs<-t.test(x,y)$statistic perm<-10000 tstar<-rep(NA, perm) for (i in 1:perm){ group<-sample(c(rep("x", length(x)), rep("y", length(y)))) px<-c(x,y)[group=="x"] py<-c(x,y)[group=="y"] tstar[i]<-t.test(px, py)$statistic } plot(density(tstar), main="Permuted Null Distribution") x<-seq(-4,4, by=0.01) lines(x,dt(x, df=tout$parameter), lty=2) pvalue<-mean(abs(tstar) >= abs(tobs)) pvalue