#Biostatistics 160 #ZAR EXAMPLE 8.1 ZAR=read.table("ZarEX8.1.txt", na.strings="NA") ZAR attach(ZAR) X1=na.omit(gpB) X1 X2=gpG X2 n1=length(X1) n1 n2=length(X2) n2 X1bar=mean(X1) X1bar X2bar=mean(X2) X2bar s1=sqrt(var(X1,na.rm=TRUE)) s1 s2=sqrt(var(X2)) s2 sp=((n1-1)*s1^2+(n2-1)*s2^2)/(n1+n2-2) sp #PERFORMING TWO-SAMPLE TWO SIDED t-TEST: t.test(X1,X2,alternative="two.sided",var.equal=TRUE, conf.level=0.95) detach(ZAR) #CHECK THE FOLLOWING DATASET FOR A MORE #EFFICIENT WAY TO INPUT DATA USING read.table() ZAR2=read.table("ZarEX8.1R.txt") ZAR2 attach(ZAR2) X1=data[group=="gpB"] X1 X2=data[group=="gpG"] X2 #PERFORMING TWO-SAMPLE ONE SIDED LOWER TAIL t-TEST: t.test(X1,X2,alternative="less",var.equal=TRUE, conf.level=0.95) #PERFORMING TWO-SAMPLE ONE SIDED UPPER TAIL t-TEST: t.test(X1,X2,alternative="greater",var.equal=TRUE, conf.level=0.95)