###### R command for section 4.6 ## Example 4.6-3 # before the short course y = scan() 43 82 77 39 51 66 55 61 79 43 # after the short course x = scan() 51 84 74 48 53 61 59 75 82 48 # one-sided paired t test t.test(x, y, alternative="greater", paired=T) # one-sided equal-variance t test t.test(x, y, alternative="greater", var.equal=T) # one-sided nonequal-variance t test t.test(x, y, alternative="greater") ## read data from a file, if data file is in the working folder data = read.table("example463.dat", head=T) y = data$y x = data$x t.test(x, y, alternative="greater", paired=T) ## do t test step by step w = x - y wvar = var(w) # sample variance of w wbar = mean(w) # sample mean of w n = 10 tstat = wbar/sqrt(wvar/n) # t statistic pvalue = pt(tstat, df=n-1, lower.tail = F) ## check for other kinds of available test in R ??test