STT2640-Lab 11
Comparison of Two Population Means
Part I Tutorial Portion
In Lab 10, we used function t.test() to conduct one-sample t test. This function can also be used to perform two-sample t test. Here, we use the same data set from Example 9.4 on page 417 of our textbook to explain how we conduct a two-sample t test in R. Here we use “New” to indicate the reading test scores for Slow Learners who used the new method, “Standard” to indicate the reading scores for Slow Learners who used the standard method.
Step 1. Create data sets “New” and “Standard”
> New=c(80,80,79,81,76,66,71,76,70,85)
> Standard=c(79,62,70,68,73,76,86,73,72,68,75,66)
> New
[1] 80 80 79 81 76 66 71 76 70 85
> Standard
[1] 79 62 70 68 73 76 86 73 72 68 75 66
Step 2. Perform a two-sample t test.
Make boxplots for two groups of data to see some pattern:
> boxplot(New, Standard)
Test whether or not the two population variances are the same using function var.test():
> var.test(New, Standard)
F test to compare two variances
data: New and Standard
F = 0.846, num df = 9, denom df = 11, p-value = 0.8148
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.2357881 3.3095522
sample estimates:
ratio of variances
0.8459839
Note that the above test results in p-value is 0.8148, we fail to reject the null hypothesis. Hence, the equal variance assumption is met. Therefore, we perform two-sample test with equal variance case to compare the two population means.
> t.test(New, Standard, var.equal=TRUE)
Two Sample t-test
data: New and Standard
t = 1.5519, df = 20, p-value = 0.1364
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1.399371 9.532705
sample estimates:
mean of x mean of y
76.40000 72.33333
We get the exact same result as our textbook which uses Minitab software.
Step 3. R uses the significance level 0.05 by default. If we use 0.01 as the significance level or equivalently, use 0.99 as the confidence level to conduct upper-tailed test. Then, we use option “conf.level=0.99” and “alternative=”greater””:
> t.test(New, Standard, alternative="greater", conf.level=0.99, var.equal=TRUE)
Two Sample t-test
data: New and Standard
t = 1.5519, df = 20, p-value = 0.06818
alternative hypothesis: true difference in means is greater than 0
99 percent confidence interval:
-2.557619 Inf
sample estimates:
mean of x mean of y
76.40000 72.33333
Please note that the output contains 99% one-sided confidence interval if we perform one-tailed test. The symbol “inf” means infinity.
Part II. Lab Portion
Now we work problem 9.9 from our textbook.
Problem #1. Do Problem 9.9 by hand.
Problem #2. Use R to conduct a hypothesis test to verify whether or not the mean of population 1 is less than population 2 mean. Use significance level 0.10.
Lab report should include the following:
1. Solution to Problem #1 in Part II
2. R script for Problem #2
3. Solution to Problem #2.