## Lab Exercise 5 for R: Comparing 2 Independent Samples

### Exercise 1: Compare two samples

If two independent samples are obtained, then we can ask whether they may have been drawn from two different underlying distributions.

 Download and read the content from file "TroutDiet.txt" for 2000 individual trout ready to go to market. One half was fed a special diet [Diet=1], the other half received the usual grub [Diet=0]. Your goal is to test whether the new diet has been effective in promoting growth. You might consider making sure that 'Diet' is treated as a factor, rather than a number. > Trout <- read.table("http://caspar.bgsu.edu/~courses/stats/Labs/Datasets/TroutDiet.txt", header=TRUE) > summary(Trout) Break the file apart into the two diet samples, then run a Welch 2-Sample t-Test ... > normalD = Trout\$Diet == 0 > specialD = Trout\$Diet == 1 > TroutSize_normalD <- Trout[normalD,]\$stLength > TroutSize_specialD <- Trout[specialD,]\$stLength > t.test(TroutSize_normalD, TroutSize_specialD) This process is equivalent to performing the analysis with the original factor and response variable ... > t.test(Trout\$stLength ~ Trout\$Diet) Unlike most statistical packages, the default does not assume that the samples have unequal variance and therefore applies the Welsh df modification by default. If you are certain that the data are not heteroscedastic then you can set flag var.equal = TRUE > t.test(Trout\$stLength ~ Trout\$Diet, var.equal = TRUE) Unlike most statistical packages, the default does not assume that the samples have unequal variance and therefore applies the Welsh df modification by default.