Lesson 1: Hypothesis tests and Confidence Intervals for 2 independent
samples
Key Takeaways
By the end of this lesson you should be able to:
• Determine which case of independent samples we are dealing with
• Solve for and interpret a hypothesis test for two sample experiments
• Solve for and interpret a confidence interval for two sample experiments
Section 10.1
Often experiments are performed to compare two (or more) objects, items, levels or categories to each
other. Under this scenario we create a comparison between 2 (or more) samples, each having received a
different characteristic of interest. For purposes of this course our interest will lie in comparing 2
different characteristics to each other. Hence, we now want to expand our use of Confidence Intervals
and Hypothesis tests to the comparison of the means from two independent populations.
In such applications we are typically interested in two main points:
• Is there evidence of a difference in the means of two groups? This is typically answered using
Hypothesis Tests and,
• To estimate the true difference in the means of the two groups using confidence intervals.
Section 10.2: The Sampling Distribution of the Difference in Sample Means
Notation
Let us start by expanding our notation. The easiest way to do this is to add a subscript ‘i’ to our previous
symbols where i=1,2 depending on which sample we are referring to. And so we have:
Population parameters:
• Mean: 𝝁𝒊 for 𝑖 = 1,2
• Variance: 𝝈𝟐𝒊 for 𝑖 = 1,2
Sample statistics:
• Sample of size 𝒏𝒊 for 𝑖 = 1,2
• Sample mean: 𝒙 ̅𝒊 for 𝑖 = 1,2
• Sample Variance: 𝒔𝟐𝒊 for 𝑖 = 1,2
To describe the relationship between two population means, we will look at their difference 𝝁𝟏 − 𝝁𝟐 .
Inference procedures are based on the assumption that the observations come from (approximately) a
normal distribution, or that sample sizes are large enough so that 𝑋̅𝑖 is approximately normal, 𝑖 = 1,2 by
way of the central limit theorem.
Building our Hypothesis Tests and Confidence Intervals
Recall we introduced our basic four steps in performing a hypothesis test. These are:
1. State your Hypothesis
2. Calculate the appropriate test statistic
3. Determine the significance
4. Make a conclusion
We must now adapt these steps to our new application.
To perform the hypothesis test and solve for the confidence interval we must first identify our
parameter of interest and its appropriate sample estimator. Previously we stated that we are now trying
to make inference on the difference in the population means, namely, 𝜇1 − 𝜇2 . A natural estimator of
̅𝟏 − 𝑿
𝜇1 − 𝜇2 is 𝑿 ̅ 𝟐 . It can be shown that if 𝑋̅1 and 𝑋̅2 are both normally distributed and independent
𝜎 2𝜎 2
then: 𝑋̅1 − 𝑋̅2 ~𝑁 (𝜇1 − 𝜇2 , 𝑛1 + 𝑛2 )
1 2
Section 10.4: Hypothesis Tests and Confidence Intervals for 𝝁𝟏 − 𝝁𝟐 when 𝝈𝟏 and 𝝈𝟐 are
unknown
To define our hypothesis test steps and Confidence Interval under this application we need to further
distinguish between two possible scenarios:
1. Case 1: both 𝝈𝟏 and 𝝈𝟐 are unknown and 𝝈𝟏 ≠ 𝝈𝟐
2. Case 2: both 𝝈𝟏 and 𝝈𝟐 are unknown and 𝝈𝟏 = 𝝈𝟐
Under both scenarios the hypothesis stated is the same:
Step 1 - State the Hypothesis
Again, the null hypothesis (H0) captures the statement of no difference (i.e. both samples have the same
average response). The alternate hypothesis (Ha) captures the statement of interest and can take on one
of three forms.
Null Hypothesis, 𝑯𝟎 Alternate Hypothesis, 𝑯𝒂
𝝁𝟏 = 𝝁𝟐
𝝁𝟏 ≠ 𝝁𝟐 Two-sided tests
This can also be expressed as:
𝝁𝟏 > 𝝁𝟐 One-sided Upper tail test
𝝁𝟏 − 𝝁𝟐 = 𝟎
𝝁𝟏 < 𝝁𝟐 One-sided Lower tail test
Where ‘0’ represents the hypothesized valued.
Case 1: Hypothesis Tests for 𝝁𝟏 − 𝝁𝟐 when both 𝝈𝟏 and 𝝈𝟐 are Unknown and 𝝈𝟏 ≠ 𝝈𝟐
Referred to as the Welch Approximate t Procedure
(𝒙 ̅𝟐 )−𝝁𝟎
̅𝟏 −𝒙
Step 2 - Test Statistic: 𝒕 =
𝒔 𝒔𝟐 𝟐
√ 𝟏+ 𝟐
𝒏𝟏 𝒏𝟐
Step 3 – Critical value or p-value: Determined using the t-table as previously discussed, where the
degrees of freedom are defined as,
𝟐
𝒔𝟐 𝒔𝟐
(𝒏𝟏 + 𝒏𝟐 )
𝟏 𝟐
𝒅. 𝒇. =
𝒔𝟒𝟏 𝒔𝟒𝟐
+
𝒏𝟐𝟏 (𝒏𝟏 − 𝟏) 𝒏𝟐𝟐 (𝒏𝟐 − 𝟏)
If performing the test by hand and using the t-table the degrees of freedom will be approximated as the
smaller value between 𝒏𝟏 − 𝟏 and 𝒏𝟐 − 𝟏, stated as: 𝐦𝐢𝐧 (𝒏𝟏 − 𝟏, 𝒏𝟐 − 𝟏).
Next week, we will cover some shortcuts for these calculations in R.
Step 4 – Conclusion as previously discussed
Case 1: Confidence Interval for 𝝁𝟏 − 𝝁𝟐 when 𝝈𝟏 and 𝝈𝟐 are unknown and 𝝈𝟏 ≠ 𝝈𝟐
Under this scenario, an approximate two-sided 100(1-𝛼)% CI for 𝜇1 − 𝜇2 is given by:
𝒔𝟐 𝒔𝟐
̅𝟐 ) ± 𝒕𝜶;𝒅𝒇 √ 𝟏 + 𝟐
̅𝟏 − 𝒙
(𝒙
𝟐 𝒏𝟏 𝒏𝟐
Example 1
A Bank manager has developed a new system to reduce the time customers spend waiting for teller
service during peak hours. The manager hopes the new system will reduce the waiting times from the
current nine to ten minutes to less than six minutes.
A random sample of 100 customers is drawn and their waiting time is recorded. It is found that their
average waiting time is 5.46 mins with a standard deviation of 2.475 mins.
Use this information to test whether the average waiting time is now less than 6 mins.
Soln:
This is a 1 sample hypothesis test.
Step 1: 𝐻0 : 𝜇 = 6 𝑣𝑠. 𝐻𝑎 : 𝜇 < 6
Step 2: Notice that for this investigation the standard deviation is found by using the sample of 100
customers. Hence, we are working under the scenario that 𝜎 is unknown which implies the t-test.
𝑥̅ − 𝜇0 5.46 − 6
𝑡= = = −2.1818
𝑠/√𝑛 2.475/√100
Step 3: To practice let us solve for the Critical Value and P-value.
Things to note:
• 𝛼 = 0.05
• We are performing a one-sided lower tail test
• 𝜎 is unknown and so critical value and p-value will come from the t-distribution
• Degrees of freedom are n-1=99
First let us solve for the critical value:
Critical value =−𝑡0.05;99 ≈ −𝑧0.05 = −1.645
This critical value has very large degrees of freedom. As previously stated for such large degrees of
freedom the z-distribution approximates the t-distribution very well and so we refer to the row labeled
"∞" in our t-table to find the critical value.
Now let us solve for the p-value:
Since this is a one-sided lower tail test the p-value = 𝑃(𝑇99 < −2.18) ≈ 𝑃(𝑍 < −2.18) = 0.0146. Again
because of the large degrees of freedom we can jump in to the z-table for this.
Step 4: Conclusion
let us use both methods for practice:
Critical value:
here |-2.18|>|-1.645| and so we reject the null hypothesis at a 5% level of significance. Therefore, the
data implies that the average waiting time is less than 6 minutes.
p-value:
here we have that p-value=0.0146 and is less than 𝛼 = 0.05 hence again we reject the null hypothesis at
a 5% level of significance and conclude the same as above.
Example 2
Consider again the Bank customer waiting time example. Under this example we have that the Bank
manager adopted a new system in the hope of reducing waiting time during peak times. Previously we
tested whether the average waiting time for the new system has been reduced to less than 6 mins.
Now we want to compare it directly to the average waiting time of the current system to determine
whether it has in fact been effective at reducing waiting time. Two, independent random samples each
of size 100 are drawn.
The first sample was subjected to the current waiting system and had an average waiting time of
8.79mins, with a standard deviation of 4.82mins.
The second sample was subjected to the new system and had an average waiting time of 5.14mins, with
a standard deviation of 1.79mins.
Assuming that the population variances are not equal, test at a 5% level of significance whether the new
system has in fact reduced the average waiting time.
Soln:
Let us start by summarising the information given to us in the question:
• Here we identify that we are working with two independent samples where the population
standard deviations are unknown and NOT equal (i.e. 𝝈𝟏 and 𝝈𝟐 are unknown and 𝝈𝟏 ≠ 𝝈𝟐 )
• Information on samples:
Group 1: Current Group 2: New
𝑛1 = 100 𝑛2 = 100
𝑥̅1 = 8.79 𝑥̅2 = 5.14
𝑠1 = 4.82 𝑠2 = 1.79
Step 1:𝐻0 : 𝜇1 = 𝜇2 𝑣𝑠. 𝐻𝑎 : 𝜇1 > 𝜇2
Notice with the current system being labeled group 1 our alternate is testing that the average waiting
time from the current system is larger than the new system.
(𝑥̅1 −𝑥̅2 )−𝜇0 (8.79−5.14)−0
Step 2: 𝑡 = = 2 2
= 7.099
𝑠2 𝑠2 √4.82 +1.79
√ 1+ 2 100 100
𝑛1 𝑛2
Step 3: To practice let us solve for the Critical Value and P-value.
Things to note:
• 𝛼 = 0.05
• We are performing a one-sided upper tail test
• Degrees of freedom = 𝐦𝐢 𝐧(𝒏𝟏 − 𝟏, 𝒏𝟐 − 𝟏) = 𝒎𝒊𝒏(𝟏𝟎𝟎 − 𝟏, 𝟏𝟎𝟎 − 𝟏) = 𝟗𝟗
First let us solve for the critical value:
Critical value =𝑡0.05;99 ≈ 𝑧0.05 = 1.645
This critical value has very large degrees of freedom. As previously stated for such large degrees of
freedom the z-distribution approximates the t-distribution very well and so we refer to the row labeled
"∞" in our t-table to find the critical value.
Now let us solve for the p-value:
Since this is a one-sided lower tail test the p-value = 𝑃(𝑇99 > 7.099) ≈ 𝑃(𝑍 > 7.099) ≈ 0. Again
because of the large degrees of freedom we can jump into the z-table for this.
Step 4: Conclusion
Let us use both methods for practice:
Critical value:
here 7.099 > 1.645 and so we reject the null hypothesis at a 5% level of significance. Therefore, the data
implies that on average the new system has a shorter waiting time.
p-value:
here we have that p-value≈ 0 and is less than 𝛼 = 0.05 hence again we reject the null hypothesis at a
5% level of significance and conclude the same as above.
Example 3
Solve for a 90% confidence interval for the difference in average waiting time between the two systems
in the bank. Interpret your interval.
Soln:
Let us start by listing the information given to us in the question. We have:
Group 1: Current Group 2: New
𝑛1 = 100 𝑛2 = 100
𝑥̅1 = 8.79 𝑥̅2 = 5.14
𝑠1 = 4.82 𝑠2 = 1.79
Here we want to create a 90% confidence interval, i.e 90% = (1 − 0.1)100% ⇒ 𝛼 = 0.1.
Hence, a 90% confidence interval for 𝜇1 − 𝜇2 is given by:
𝒔𝟐 𝒔𝟐
(𝒙 ̅𝟐 ) ± 𝒕𝜶;𝒅𝒇 √ 𝟏 + 𝟐
̅𝟏 − 𝒙
𝟐 𝒏𝟏 𝒏𝟐
4.822 1.792
= (8.79 − 5.14) ± 𝑡0.05;99 × √ +
100 100
= (2.8042; 4.4958)
Where 𝑡0.05;99 ≈ 𝑧0.05 = 1.645
• Therefore are 90% confident that the true but unknown average difference lies between 2.8042
and 4.4958.
• Also notice that this confidence interval is entirely positive suggesting that on average the
waiting time in the current system is larger than that of the new system.
Case 2: Hypothesis Tests for 𝝁𝟏 − 𝝁𝟐 when both 𝝈𝟏 and 𝝈𝟐 are Unknown and 𝝈𝟏 = 𝝈𝟐
1. Step 1: State the Hypothesis:
Null Hypothesis, 𝑯𝟎 Alternate Hypothesis, 𝑯𝒂
𝝁𝟏 = 𝝁𝟐
𝝁𝟏 ≠ 𝝁𝟐 Two-sided tests
This can also be expressed as:
𝝁𝟏 > 𝝁𝟐 One-sided Upper tail test
𝝁𝟏 − 𝝁𝟐 = 𝟎
𝝁𝟏 < 𝝁𝟐 One-sided Lower tail test
Where ‘0’ represents the hypothesized valued.
(𝒙 ̅𝟐 )−𝝁𝟎
̅𝟏 −𝒙
Step 2- Test Statistic: 𝒕 = 𝟏 𝟏
𝒔𝒑 √ +
𝒏𝟏 𝒏𝟐
(𝒏𝟏 −𝟏)𝒔𝟐𝟏 +(𝒏𝟐 −𝟏)𝒔𝟐𝟐
Where 𝒔𝟐𝒑 =
𝒏𝟏 +𝒏𝟐 −𝟐
And represents the Pooled Sample Variance. This gives us an estimate of the common variance and is
simply a weighted average of the two sample variances.
Step 3 - Critical value or p-value: Determined using the t-table as previously discussed, where the
degrees of freedom are defined as 𝒅𝒇 = 𝒏𝟏 + 𝒏𝟐 − 𝟐
Step 4 - Conclusion as previously discussed
Case 2: Confidence Interval for 𝝁𝟏 − 𝝁𝟐 when both 𝝈𝟏 and 𝝈𝟐 are Unknown and 𝝈𝟏 = 𝝈𝟐
Under this scenario, an approximate two-sided 100(1-𝛼)% CI for 𝜇1 − 𝜇2 is given by:
𝟏 𝟏
̅𝟏 − 𝒙
(𝒙 ̅ 𝟐 ) ± 𝒕 𝜶; 𝒏 √𝒔𝟐𝒑 ( + )
𝟐 𝟏 +𝒏𝟐 −𝟐 𝒏𝟏 𝒏𝟐
Example 4
A marketing research firm wishes to compare the prices charged by two supermarket chains- Miller’s
and Albert’s. The research firm, using a standardised one-week shopping list, makes identical purchases
at ten of each chain’s stores. The stores for each chain are randomly selected, and all purchases are
made during a single week.
Because the stores in each sample are different stores in different chains, it is reasonable to assume that
the samples are independent, and we assume that the weekly expenses at each chain are normally
distributed.
Based on the data collected it was found that the average weekly expense at Miller’s was $121.92, with
a standard deviation of 1.40 and at Albert’s it was $114,81 with a standard deviation of 1.84. Assuming
that the population variances are equal, test at a 10% level of significance the hypothesis that the
average weekly expenses is different between the two stores.
Soln:
Let us start by summarising the information given to us in the question:
• Here we identify that we are working with two independent samples where the population
standard deviations are unknown and equal (i.e. 𝝈𝟏 and 𝝈𝟐 are unknown and 𝝈𝟏 = 𝝈𝟐 )
• Information on samples:
Group 1: Current Group 2: New
𝑛1 = 10 𝑛2 = 10
𝑥̅1 = 121.92 𝑥̅2 = 114.81
𝑠1 = 1.40 𝑠2 = 1.84
Step 1: 𝐻0 : 𝜇1 = 𝜇2 𝑣𝑠. 𝐻𝑎 : 𝜇1 ≠ 𝜇2
(𝑥̅1 −𝑥̅2 )−𝜇0 (121.92−114.81)−0
Step 2: 𝑡 = 1 1
= 1 1
= 9.725
𝑠𝑝 √ + √2.6728×√10+10
𝑛1 𝑛2
(𝑛1 −1)𝑠12 +(𝑛2 −1)𝑠22 (10−1)(1.40)2 +(10−1)(1.84)2
Where 𝑠𝑝2 = = = 2.6728
𝑛1 +𝑛2 −2 10+10−2
Step 3: To practice let us solve for the Critical Value and P-value.
Things to note:
• 𝛼 = 0.1
• We are performing a two-sided test
• Degrees of freedom = 𝑛1 + 𝑛2 − 2 = 10 + 10 − 2 = 18
First let us solve for the critical value:
Critical value =±𝑡0.05;18 = ±1.734
Now let us solve for the p-value:
Since this is a two-sided test the p-value = 2 × 𝑃(𝑇18 > 9.725) < 2 × 0.0005 = 0.001.
Step 4: Conclusion
let us use both methods for practice:
Critical value:
here 9.725 > 1.734 and so we reject the null hypothesis at a 10% level of significance. Therefore, the
data implies that the average prices at the stores are different.
p-value:
here we have that p-value< 0.001 and is less than 𝛼 = 0.10 hence again we reject the null hypothesis
at a 10% level of significance and conclude the same as above.
Practice
Chapter 10: 3, 5, 6, 13, 14, 16 – 20, 25, 26, 28, 29, 32, 34
Lesson 2: Hypothesis tests and Confidence Intervals for dependent
(paired) data
Key Takeaways
By the end of this lesson you should be able to:
• Solve for and interpret a hypothesis test for paired data
• Solve for and interpret a confidence interval for paired data
Section 10.5: Paired-Difference procedures (for Dependent Samples)
Independent vs. Dependent Groups
When comparing two population means to each other we need to first determine whether the two
populations are related (dependent) or not related (independent) to each other. So far we have been
working with independent groups.
• Independent groups occur when results from one group, do not affect the other. (i.e. the
groups are said to be disjoint)
o These groups are non-paired, example; males vs. females, smokers vs. Non-smokers.
• Dependent groups occur when our pairs are related, example; Twins, Matched pairs (matched
based on certain criteria such as age e.t.c), Using the same unit (person) twice.
Dependent Samples lead to Confounding. To adjust for confounding we adopt a slightly different set-up
when creating Confidence Intervals and Hypothesis Tests.
Hypothesis Tests for a mean difference (𝜇1 − 𝜇2 ) with paired data
Let 𝝁𝑫 = 𝝁𝟏 − 𝝁𝟐 represent the population mean difference. This will be estimated by
̅=𝑿
𝒅 ̅𝟏 − 𝑿
̅𝟐
which represents the difference of the sample means of the pairs.
Step 1 – State your hypothesis
Null Hypothesis, 𝑯𝟎 Alternate Hypothesis,𝑯𝒂
Two-sided tests
𝝁𝑫 ≠ 𝝁𝟎
𝝁𝑫 = 𝝁𝟎 One-sided Upper tail test
𝝁𝑫 > 𝝁𝟎
One-sided Lower tail tests
𝝁𝑫 < 𝝁𝟎
̅ −𝝁𝟎
𝒅
Step 2 – Solve for the appropriate test statistic 𝒕 = 𝑺𝑬𝒅̅
𝒔𝒅
Where 𝑺𝑬𝒅̅ = , where 𝒔𝒅 is the standard deviation of the differences and 𝒏𝒅 is the number of
√𝒏𝒅
differences.
Step 3 – Solve for the critical value or p value: Determined using the t-table as previously, where the
degrees of freedom are defined around the number of pairs (nd): 𝒅𝒇 = 𝒏𝒅 − 𝟏
Step 4 – Make a conclusion as previously discussed.
Confidence Interval for a mean difference (𝜇1 − 𝜇2 ) with paired data
Under this scenario, an approximate two-sided 100(1-𝛼)% CI for the mean difference of paired data
̅ ± 𝒕𝜶
𝜇𝐷 = 𝜇1 − 𝜇2 is given by: 𝒅 ;𝒏 −𝟏 𝑺𝑬𝒅
̅
𝒅
𝟐
Example 1
A supermarket chain wants to know if its “buy one, get one free” campaign increases customer traffic
enough to justify the cost of the program. For each of 10 stores it selects two days at random to run the
test. For one of those days, the program will be in effect. The chain wants to test the hypothesis that
there is no mean difference in traffic against the alternative that the program increases the mean traffic.
The results from the 10 stores are presented on the next slide.
Store # Customer visits with Customer visits Difference, 𝑑𝑖
Program without program
(1) (2)
1 140 136 140 − 136 = 4
2 233 235 233 − 235 = −2
3 110 108 2
4 42 35 7
5 332 328 4
6 135 135 0
7 151 144 7
8 33 39 -6
9 178 170 8
10 147 141 6
Mean 150.1 147.1 𝑑̅ = 150.1 − 147.1 = 3
Std. dev. 86.98 86.33
Using the information provided test the null hypothesis of no difference in average traffic at a 5% level
of significance.
Soln:
Let us start by summarising the information given to us in the question:
• Here the data is paired based on the store location.
• In total we have 10 stores, i.e 10 pairs⇒ 𝑛𝑑 = 10
10
∑ 𝑑𝑖
• 𝑑̅ = 𝑖=1
10
= 150.1 − 147.1 = 3, because of the linearity properties of the mean.
∑10 ̅ 2
𝑖=1(𝑑𝑖 −𝑑 )
• 𝑠𝑑 = √ 10−1
= 4.52155
Step 1: 𝐻0 : 𝜇𝐷 = 0 𝑣𝑠. 𝐻𝑎 : 𝜇𝐷 ≠ 0
𝑑̅ −𝜇0 3−0
Step 2: 𝑡 = 𝑆𝐸𝑑
= 4.52155 = 2.09814
̅ ⁄
√10
Step 3: To practice let us solve for the Critical Value and P-value.
Things to note:
• 𝛼 = 0.05
• We are performing a two-sided test
• Degrees of freedom = 𝑛𝑑 − 1 = 10 − 1 = 9
First let us solve for the critical value: Critical value =±𝑡0.025;9 = ±2.262
Now let us solve for the p-value: Since this is a two-sided test the p-value = 2 × 𝑃(𝑇9 > 2.09814).
From the t-table at 9 degrees of freedom the t-value of 2.09814 lies between the columns highlighted by
t0.025 and t0.05. Hence, 0.025 < 𝑃(𝑇9 > 2.09814) < 0.05 ⇒ 0.05 < 𝑝 − 𝑣𝑎𝑙𝑢𝑒 < 0.1
Step 4: Conclusion let us use both methods for practice:
Critical value: here 2.098 lies between the critical values and so we do NOT reject the null hypothesis at
a 5% level of significance. Therefore, the data implies that the average difference is not different to 0.
p-value: here we have that 0.05< p-value< 0.1 and is less than 𝛼 = 0.10 hence again we do not reject
the null hypothesis at a 10% level of significance and conclude the same as above.
Have you noticed something from these examples? The paired-difference procedure is the SAME as the
one-sample procedure we learned previous, but now our data is the differences.
Practice
Chapter 10: 9, 10, 31, 40, 41