Professional Documents
Culture Documents
Carrie Madden
Paired Data
Paired Data
The term paired data means that the data have been observed in natural
pairs. There are several ways in which paired data can occur:
Example – Mileage
Many drivers buy premium gasoline instead of regular in the belief that
they will get better gas mileage. To test this belief, we obtain a sample of
8 cars. Each car is run for one tank on regular gas and one tank on
premium gas, with the order randomly determined. The mileage (in miles
per gallon) is measured for each car for each type of gasoline.
reg<-c(20,26,23,22,23,19,22,26)
prem<-c(24,26,25,23,25,18,27,29)
diff<- prem-reg
diff
## [1] 4 0 2 1 2 -1 5 3
mean(diff)
## [1] 2
sd(diff)
## [1] 2
Carrie Madden STAT 2000 – Unit 2 10 / 99
Unit 2 – Inference for the Mean of a Two Populations
We will construct a 95% confidence interval for the true mean difference in
mileage between cars run with regular and premium gas.
To do this we assume the differences follow a normal distribution.
We estimate the population mean difference µd by the sample mean
difference x̄d and the population standard deviation σd by the sample
standard deviation of differences sd .
mean<-mean(diff)
sd<-sd(diff)
cv<-qt(0.975,7)
moe<-cv*(sd/sqrt(8))
left<-mean-moe
left
## [1] 0.3279582
right<-mean+moe
right
## [1] 3.672042
Interpretation
If we took repeated samples of eight cars and calculated the interval in a
similar manner, then 95% of all such intervals would contain the true
mean difference in fuel economy for premium and regular gasoline.
Note that we could have define the difference the other way (i.e., Regular -
Premium). The signs of the differences (positive or negative) would simply
switch in this case, and the interval would give us the same information.
Now suppose we would like to test whether these data provide convincing
evidence that premium gasoline provides better fuel economy on average.
We will use the P-value method.
1 Let α = 0.05
2
H0 : µ d = 0
Ha : µ d > 0
Since 2.517 < t = 2.83 < 2.998, the P-value is between 0.01 and
0.02.
For any P-value between 0.01 and 0.02, we reject the null hypothesis.
6 We have sufficient evidence that premium gasoline provides better
fuel economy on average than regular gasoline.
Carrie Madden STAT 2000 – Unit 2 16 / 99
Unit 2 – Inference for the Mean of a Two Populations
Suppose we had instead used the critical value method to conduct the
test. The decision rule would be to reject H0 if t ≥ t ∗ = 1.895. Our
conclusion would still remain the same, as we would reject H0 since
t = 2.83 > t ∗ = 1.895.
##
## One Sample t-test
##
## data: diff
## t = 2.8284, df = 7, p-value = 0.01273
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
## 0.6603306 Inf
## sample estimates:
## mean of x
## 2
## [1] 1.894579
1 Let α = 0.10.
2
H0 : µ d = 0
Ha : µ d < 0
Suppose we had instead used the P-value method to conduct the test.
The decision rule would be to reject H0 if the P-value ≤ α = 0.10.
The P-value is P T(19) ≤ −13.17 = P (T (19) ≥ 13.17) by the symmetry
of the t distributions. We see from Table 3 that
Since 13.17 > 3.883, the P-value is less than 0.0005.Therefore, we would
reject H0 .
Example – Psychology
Many psychology studies have examined the differences between the first
and second children in a family. Suppose we would like to compare their
academic performance. We examine the high school GPAs of a sample of
30 pairs of siblings and calculate the difference in GPAs,
d = first child − second child. We calculate an average difference of
x̄d = 0.12 and a standard deviation of sd = 0.31. We will assume that
difference follow a normal distribution. Calculate a 99% confidence
interval for the true mean difference in GPAs.
Example – Psychology
sd 0.31
∗
x̄d ± t √ = 0.12 ± 2.756 √
n 30
= (−0.036, 0.276)
xbard<-0.12
sd<-0.31
cv<-qt(0.005, 29, lower.tail = FALSE)
cv
## [1] 2.756386
moe<-sd/sqrt(30)
lower<-xbard-(cv*moe)
upper<-xbard+(cv*moe)
lower
## [1] -0.03600592
upper
## [1] 0.2760059
I printed out the critical value, upper and lower bound so you can see the
calculations.
Example – Psychology
We will now conduct a hypothesis test to determine whether there is
evidence of a difference in the average high school academic performance
between the first and second children in a family. We will use the P-value
method.
1 Let α = 0.01.
2
H0 : µ d = 0
Ha : µd ̸= 0
Example – Psychology
5 The P-value is 2P T(29) ≥ 2.12 . We see from Table 3 that
P T(29) ≥ 2.045 = 0.025 and P T(29) ≥ 2.150 = 0.02
Since 2.045 < t = 2.12 < 2.150, P T(29) ≥ 2.12 is between 0.02
and 0.025, so the P-value is between 2(0.02) = 0.04 and
2(0.025) = 0.05.
For any P-value between 0.04 and 0.05, we fail to reject the null
hypothesis.
6 We have insufficient evidence that there is a difference in average
high school academic performance between the first and second
children in a family.
Example – Psychology
Suppose we had instead used the critical value method to conduct the
test. The decision rule would be to reject H0 if |t| ≥ t ∗ = 2.756, i.e., if
t ≥ 2.756 of t ≤ −2.756, where t ∗ = 2.756 is the upper 0.005 critical
value for the t distribution with 29df .
Our conclusion would be the same as we fail to reject H0 , since
−2.756 < t = 2.12 < 2.756.
Example – Psychology
Practice Question
Practice Question
1 2
2 1 and 3
3 1 and 4
4 2 and 3
5 2 and 4
We will consider the difference between the means for Population 1 and
Population 2
µ1 − µ2
Two-Sample t Procedures
Two-Sample t Procedures
Two-Sample t Procedures
Two-Sample t Procedures
Two-Sample t Procedures
df = k = min{n1 − 1, n2 − 1} (1)
Two-Sample t Procedures
Two-Sample t Procedures
where t ∗ is the upper α2 critical value from the t distribution with degrees
of freedom k calculated using the formula shown in equation 1.
Two-Sample t Procedures
We can never be sure, because we don’t have information about the whole
population.
Two-Sample t Procedures
The Case of Unequal Population Standard Deviations
There are formal hypothesis tests to assess the equality of variances for two
populations. However, in this course, we will use the following simple rule:
Rule of Thumb
We divide the higher of the two sample standard deviations by the lower:
max si
(i = 1, 2)
min si
If this quantity is:
2 or less, we can assume equal population standard deviations,
σ1 = σ2 .
greater than 2, we must assume that the population standard
deviations differ, σ1 ̸= σ2 .
Two-Sample t Procedures
Example
Let X1 be the price of gas at a Winnipeg gas station and let X2 be the
price of gas for a Calgary gas station. From the data, we calculate
We see that
max si s2 2.36
= = = 2.17 > 2
min si s1 1.09
so we will conduct our inference using the method for unequal standard
deviations. We must assume that gas prices in both cities follow a normal
distribution.
Example
Example – Cont’d
A 95% confidence interval for the difference in mean gas prices for the two
cities X¯1 − X¯2 is
s
(1.09)2 (2.36)2
= (121.30 − 119.32) ± 2.776 +
8 5
= 1.98 ± 3.12 = (−1.14, 5.10)
Example (Cont’d)
Interpretation
If we were to take repeated samples of 8 Winnipeg gas stations and 5
Calgary gas stations and calculate the interval in a similar manner, then
95% of such intervals would contain the true difference in mean gas prices
for the two cities.
Two-Sample t Procedures
Example - Cont’d
H0 : µ 1 = µ 2
Ha : µ1 ̸= µ2
Example – Cont’d
Since
t = 1.76 is between these two values, if follows that
P T(4) ≥ 1.76 is between 0.05 and 0.10. But our P-value is double
this probability, and so the P-value of the test is between 0.10 and
0.20.
Example – Cont’d
Interpretation
If the true mean gas prices were the same for the two cities, the probability
of observing a difference in sample means at least as extreme as 1.98
would be between 0.10 and 0.20.
Example – Cont’d
Suppose we had instead used the critical value method to conduct the
test. The decision rule would be to reject H0 if |t| ≥ 2.776 (i.e., if
t ≤ −2.776 or t ≥ 2.776), where t ∗ = 2.776 is the upper 0.025 critical
value for the t distribution with 4df .
Our conclusion would be the same as we fail to reject H0 , since
−t ∗ = −2.776 < t = 1.76 < t ∗ = 2.776.
Example – Cont’d
Since this is a two-sided test, and since the confidence level of our
confidence interval and the significance level of our test add up to 1, we
could have used the 95% confidence interval to conduct this test.
Since the 95% confidence interval for µ1 − µ2 contains the value of 0, we
fail to reject H0 at the 5% level of significance.
Two-Sample t Procedures
Example – R-Code
We would like to estimate the difference in the mean gasoline price in
Winnipeg and Calgary.
The gasoline prices (in cents/litre) for a random sample of 8 Winnipeg gas
stations and 5 Calgary gas stations are recorded one day and are shown
below:
Example – R-Code
Example – R-Code
Hypothesis test and confidence interval for a two sided test. The degrees
of freedom are not found by min{n1 − 1, n2 − 1}
##
## Welch Two Sample t-test
##
## data: Wpg and Cgy
## t = 1.7647, df = 5.081, p-value = 0.137
## alternative hypothesis: true difference in means is not equ
## 95 percent confidence interval:
## -0.89043 4.85043
## sample estimates:
## mean of x mean of y
## 121.30
Carrie Madden 119.32 STAT 2000 – Unit 2 62 / 99
Unit 2 – Inference for the Mean of a Two Populations
Practice Question
where sp2 is called the pooled sample variance of X1 and X2 . Note that the
pooled variance is just a weighted average of the variances of x1 and X2 ,
where the weights are the respective degrees of freedom.
Under the null hypothesis, the test statistic has a t distribution with
n1 + n2 − 2 degrees of freedom.
Example – Driving
Would like to know if men drive faster on average than women. The
company took a random sample of 52 cars driven by men on a highway
and found the mean speed to be 114 km/h with a standard deviation of 10
km/h.Another sample of 30 cars driven by women on the same highway
gave a mean speed of 108 km/h with a standard deviation of 7 km/h.
Example – Driving
Let us construct a 98% confidence interval for the true difference between
the mean speeds of cars driven by men and women on this highway. Let
X1 be the speed of a car driven by a man and let X2 be the speed of a car
driven by a woman. Since
max si 10
= = 1.43 < 2
min si 7
we will use the pooled method, assuming equal population standard
deviations.
Example – Driving
Example – Driving
The 98% confidence interval for µ1 − µ2 is:
s s
1 1 1 1
∗
x¯1 − x¯2 ± t sp2 + = (114 − 108) ± 2.374 81.51 +
n1 n2 52 30
= 6 ± 4.91 = (1.09, 10.91)
where t ∗ = 2.374 is the upper 0.01 critical value for the t distribution with
52 + 30 − 2 = 80df.
Interpretation
If we took repeated sample of the same sizes from the same populations
and constructed the interval in a similar manner, then 98% of such
intervals would contain the difference in the true mean speeds from men
and women on this highway.
Carrie Madden STAT 2000 – Unit 2 71 / 99
Unit 2 – Inference for the Mean of a Two Populations
Example – Driving
We now conduct the hypothesis test to determine whether there is
sufficient evidence that the average speed for men on the highway is
greater than that for women. We will use the P-value method.
1 Let α = 0.01.
2 We are testing the hypotheses
H0 : µ 1 = µ 2
Ha : µ1 > µ2
Example – Driving
5 The P-value is P T(80) ≥ 2.90 . We see from Table 3 that
P T(80) ≥ 2.887 = 0.0025 and P T(80) ≥ 3.195 = 0.001
Since 2.887 < t = 2.90 < 3.195, it follows that the P-value is
between 0.001 and 0.0025.
Since the P-value < α = 0.01, we reject the null hypothesis.
6 We have sufficient evidence to conclude that the true mean speed of
male drivers on this highway is greater than that for females.
Interpretation
If the true mean speeds of men and women on this highway were equal,
the probability of observing a difference in sample means at least as high
as 6km/h would be between 0.001 and 0.0025.
Example – Driving
Suppose we had instead used the critical value method to conduct the
test. The decision rule would be to reject H0 if t ≥ t ∗ = 2.374, where
t ∗ = 2.374 is the upper 0.01 critical value from the t distribution with 80
degrees of freedom.
Our decision would be to reject H0 , since t = 2.90 > t ∗ = 2.374.
The reason we have p = 0.99 is because the entire area to the left of
t ∗ = 0.98 + 0.01
The R formula is qt(p, df )
cv<-qt(0.99, 80)
cv
## [1] 2.373868
Practice Question
A researcher is conducting an experiment in order to compare two drugs –
a new drug and an old drug. She would like to determine whether there is
evidence that the new drug is better than the old drug. In this experiment,
the researcher will commit a Type I Error if:
A she concludes that the drugs are equal in effectiveness when in fact
the new drug is better.
B she concludes that the drugs are equal in effectiveness when in fact
the old drug is better.
C she concludes that the old drug is better when in fact the new drug is
better.
D she concludes that the new drug is better when in fact the drugs are
equal in effectiveness.
E she concludes that the old drug is better when in fact the drugs are
equal in effectiveness.
Carrie Madden STAT 2000 – Unit 2 76 / 99
Unit 2 – Inference for the Mean of a Two Populations
Practice Question
The following are the percentages of alcohol found in samples of two
brands of beer:
An engineer suspects that a power plant in the city is increasing the air
pollution in the vicinity of the plant. A sample of measurements of carbon
monoxide (in mg/m3 of air) in the vicinity of the plant is obtained for
comparison with another sample obtained from other locations in the city.
The data are as follows:
Near plant 40 16 44 47 26 64 35 53
45 52 31 38 44 29 45 47
Other 34 28 36 43 35 37 36
locations 39 32 25 37 40 44 38
Concentrations near the plant and at other locations in the city are both
assumed to follow normal distributions. We would like to test the
suspicion of the engineer at the 5% level of significance.
Solution
Let X1 be the concentration of carbon monoxide at a location near the
plant and let X2 be the concentration of carbon monoxide at another
location in the city. We calculate
n1 = 16 x̄1 = 41 s1 = 11.71
n2 = 14 x̄2 = 36 s2 = 5.19
Since
max si 11.71
= = 2.26 > 2
min si 5.19
we will use the method for unequal standard deviations. We will use the
critical value method.
Solution
1 Let α = 0.05.
H0 : µ 1 = µ 2
Ha : µ1 > µ2
df = k = min{n1 − 1, n2 − 1}
= min{15, 13} = 13
Solution
4 We will reject H if t ≥ 1.771, where t ∗ = 1.771 is the upper critical
0
value fro the t distribution with 13 degrees of freedom.
5 The test statistic is
(x¯1 − x¯2 ) 41 − 36
t=r =q = 1.54
s12 s22 (11.71)2 (5.19)2
+
n1 + n2 16 14
##
## Welch Two Sample t-test
##
## data: np and other
## t = 1.5438, df = 21.255, p-value = 0.0687
## alternative hypothesis: true difference in means is greater
## 95 percent confidence interval:
## -0.570045 Inf
## sample estimates:
## mean of x mean of y
## 41 36
Carrie Madden STAT 2000 – Unit 2 83 / 99
Unit 2 – Inference for the Mean of a Two Populations
Practice Question
We wish to compare the carbohydrate content of two varieties of peaches
used for baby food. We take random samples of peaches of each variety.
The carbohydrate contents are measured and some summary statistics are
shown below:
Variety n mean std. dev
A 5 28.6 3.8
B 7 25.0 10.4
Example – Memory
Group 1 52 71 43 39 42 63 50 48 47 35
Group 2 30 28 53 44 31 32 27 54 43
Example – Memory
x̄1 = 49 s1 = 10.93
x̄2 = 38 s2 = 10.68
Example – Memory
A 95% confidence interval for the difference in mean scores for the two
methods µ1 − µ2 is
r r
x¯1 − x¯2 ± t ∗ sp2 1
n1 + 1
n2 = (49 − 38) ± 2.110 116.92 1
10 + 1
9
= 11 ± 10.48 = (0.52, 21.48)
Example – Memory
1 Let α = 0.05.
2 We are testing the hypotheses:
H0 : µ 1 = µ 2
Ha : µ1 ̸= µ2
Example – Memory
Example – Memory
Suppose we had instead used the P-value method to conduct the test.
The decision rule would be to reject H0 if the P-value ≤ α = 0.05.
The P-value of the test is 2P T(17) ≥ 2.21 . We see from Table 3 that
P T(17) ≥ 2.110 = 0.025 and P T(17) ≥ 2.224 = 0.02
It follows that P T(17) ≥ 2.21 is between 0.02 and 0.025, but our
P-value is double this probability, so our P-value is between 0.04 and 0.05.
Our conclusion would remain the same, as we reject H0 since the P-value
is less than α = 0.05.
Example – Memory
Since this is a two-sided test, and since the confidence level of our
confidence interval and the significance level of our test add up to 1, we
could have used the 95% confidence interval to conduct the test. Since
the 95% confidence interval for µ1 − µ2 does not contain the value 0, we
reject H0 at the 5% level of significance.
##
## F test to compare two variances
##
## data: g1 and g2
## F = 1.0487, num df = 9, denom df = 8, p-value = 0.9573
## alternative hypothesis: true ratio of variances is not equa
## 95 percent confidence interval:
## 0.2406878 4.3018561
## sample estimates:
## ratio of variances
## 1.048733
Carrie Madden STAT 2000 – Unit 2 93 / 99
Unit 2 – Inference for the Mean of a Two Populations
##
## Two Sample t-test
##
## data: g1 and g2
## t = 2.2139, df = 17, p-value = 0.04079
## alternative hypothesis: true difference in means is not equ
## 95 percent confidence interval:
## 0.5170438 21.4829562
## sample estimates:
## mean of x mean of y
## 49 38
Carrie Madden STAT 2000 – Unit 2 94 / 99
Unit 2 – Inference for the Mean of a Two Populations
You can see the 95% confidence interval is the same as the one we got by
hand. You can also see the p-value is the within the range of the p-value
we got using the tables as well.
Practice Question
Practice Question
In a survey of gas stations across Canada done on July 16, 2002, the price
(in cents/litre) of regular gasoline was recorded from 10 randomly selected
gas stations in Western Canada, and 13 in Eastern Canada. We will
assume that gas prices in both Western and Eastern Canada are normally
distributed. Some summary statistics are shown below:
A t > 1.782
B t < −2.262 or t > 2.262
C t > 1.721
D t > 2.833
E t < −2.080 of t > 2.080