Hypothesis Testing For The Mean

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

27/02/2024, 23:50 Hypothesis Testing for the Mean

8.4.3 Hypothesis Testing for the Mean


Here, we would like to discuss some common hypothesis testing problems. We assume that we have a
random sample X 1,X 2,...,X n from a distribution and our goal is to make inference about the mean of the
distribution μ. We consider three hypothesis testing problems. The first one is a test to decide between the
following hypotheses:

H 0: μ = μ 0,

H 1: μ ≠ μ 0.

In this case, the null hypothesis is a simple hypothesis and the alternative hypothesis is a two-sided
hypothesis (i.e., it includes both μ < μ 0 and μ > μ 0). We call this hypothesis test a two-sided test. The second
and the third cases are one-sided tests. More specifically, the second case is

H 0: μ ≤ μ 0,

H 1: μ > μ 0.

Here, both H 0 and H 1 are one-sided, so we call this test a one-sided test. The third case is very similar to the
second case. More specifically, the third scenario is

H 0: μ ≥ μ 0,

H 1: μ < μ 0.

In all of the three cases, we use the sample mean

¯ X1 + X2 + . . . + Xn
X=
n

to define our statistic. In particular, if we know the variance of the X i's, Var(X i) = σ 2, then we define our test
statistic as the normalized sample mean (assuming H 0):

¯
X − μ0
W(X 1, X 2, ⋯, X n) = .
σ / √n

If we do not know the variance of the X i's, we use

¯
X − μ0
W(X 1, X 2, ⋯, X n) = ,
S / √n

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 1/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

where S is the sample standard deviation,

S=

1
n

∑ (X − X) =
n − 1k=1 k
¯
2
√ (∑ 1
n − 1 k=1
n
2
Xk
¯2
− nX .
)
In any case, we will be able to find the distribution of W, and thus we can design our tests by calculating error
probabilities. Let us start with the first case.

Two-sided Tests for the Mean:

Here, we are given a random sample X 1,X 2,...,X n from a distribution. Let μ = EX i. Our goal is to decide
between

H 0: μ = μ 0,

H 1: μ ≠ μ 0.

¯
Example 8.22, which we saw previously is an instance of this case. If H 0 is true, we expect X to be close to
μ 0, and so we expect W(X 1, X 2, ⋯, X n) to be close to 0 (see the definition of W above).

Therefore, we can suggest the following test. Choose a threshold, and call it c. If | W | ≤ c, accept H 0, and if
| W | > c, accept H 1. How do we choose c? If α is the required significance level, we must have

P(type I error) = P(Reject H 0 | H 0)


= P( | W | > c | H 0) ≤ α.

Thus, we can choose c such that P( | W | > c | H 0) = α. Let us look at an example.

Example 8.24
Let X 1,X 2,...,X n be a random sample from a N(μ, σ 2) distribution, where μ is unknown but σ is known. Design
a level α test to choose between

H 0: μ = μ 0,

H 1: μ ≠ μ 0.

Solution
As discussed above, we let
¯
X − μ0
W(X 1, X 2, ⋯, X n) = .
σ / √n

Note that, assuming H 0, W ∼ N(0, 1). We will choose a threshold, c. If | W | ≤ c, we accept H 0,

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 2/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

and if | W | > c, accept H 1. To choose c, we let

P( | W | > c | H 0) = α.

Since the standard normal PDF is symmetric around 0, we have

P( | W | > c | H 0) = 2P(W > c | H 0).

α
Thus, we conclude P(W > c | H 0) = 2 . Therefore,

c = z α.
2

Therefore, we accept H 0 if

| |
¯
X − μ0
≤ z α,
σ / √n 2

and reject it otherwise.

Relation to Confidence Intervals: It is interesting to examine the above acceptance region. Here, we accept
H 0 if

| |
¯
X − μ0
≤ z α.
σ / √n 2

We can rewrite the above condition as

[ ]
¯ σ ¯ σ
α
μ0 ∈ X − z , X + zα .
2
√n 2
√n
The above interval should look familiar to you. It is the (1 − α)100% confidence interval for μ 0. This is not a
coincidence as there is a general relationship between confidence interval problems and hypothesis testing
problems.

Example 8.25
For the above example (Example 8.24), find β, the probability of type II error, as a function of μ.

Solution

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 3/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

We have

β(μ) = P(type II error) = P(accept H 0 | μ)

(| | )
¯
X − μ0
=P < zα | μ .
σ / √n 2

¯ σ2
2
If X i ∼ N(μ, σ ), then X ∼ N(μ, n ). Thus,

(| | )
¯
X − μ0
β(μ) = P < zα | μ
σ / √n 2

( )
σ ¯ σ
= P μ0 − z α ≤ X ≤ μ0 + z α
2
√n 2
√n

=Φ z +
( α
2
μ0 − μ

σ / √n ) (
− Φ −z + α
2
μ0 − μ

σ / √n ) .

Unknown variance: The above results (Example 8.25) can be extended to the case when we do not know the
variance using the t-distribution. More specifically, consider the following example.

Example 8.26
Let X 1,X 2,...,X n be a random sample from a N(μ, σ 2) distribution, where μ and σ are unknown. Design a level
α test to choose between

H 0: μ = μ 0,

H 1: μ ≠ μ 0.

Solution
Let S 2 be the sample variance for this random sample. Then, the random variable W defined as
¯
X − μ0
W(X 1, X 2, ⋯, X n) =
S / √n

has a t-distribution with n − 1 degrees of freedom, i.e., W ∼ T(n − 1). Thus, we can repeat the
analysis of Example 8.24 here. The only difference is that we need to replace σ by S and z α by
2

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 4/10
27/02/2024, 23:50 Hypothesis Testing for the Mean
α
t , n − 1. Therefore, we accept H 0 if
2

| W | ≤ t α , n − 1,
2

and reject it otherwise. Let us look at a numerical example of this case.

Example 8.27
The average adult male height in a certain country is 170 cm. We suspect that the men in a certain city in that
country might have a different average height due to some environmental factors. We pick a random sample
of size 9 from the adult males in the city and obtain the following values for their heights (in cm):

176.2 157.9 160.1 180.9 165.1 167.2 162.9 155.7 166.2

Assume that the height distribution in this population is normally distributed. Here, we need to decide
between

H 0: μ = 170,

H 1: μ ≠ 170.

Based on the observed data, is there enough evidence to reject H 0 at significance level α = 0.05?

Solution
Let's first compute the sample mean and the sample standard deviation. The sample mean is

¯ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9
X=
9
= 165.8

The sample variance is given by


9
1 ¯
S2 =
9−1
∑ (X k − X) 2 = 68.01
k=1

The sample standard deviation is given by

S= √S 2 = 8.25
The following MATLAB code can be used to obtain these values:
x=[176.2,157.9,160.1,180.9,165.1,167.2,162.9,155.7,166.2];
m=mean(x);
v=var(x);
s=std(x);

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 5/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

Now, our test statistic is


¯
X − μ0
W(X 1, X 2, ⋯, X 9) =
S / √n
165.8 − 170
= = − 1.52
8.25 / 3

Thus, | W | = 1.52. Also, we have

t α , n − 1 = t 0.025 , 8 ≈ 2.31
2

The above value can be obtained in MATLAB using the command tinv(0.975, 8). Thus, we
conclude

| W | ≤ t α , n − 1.
2

Therefore, we accept H 0. In other words, we do not have enough evidence to conclude that the
average height in the city is different from the average height in the country.

What if the sample is not from a normal distribution? In the case that n is large, we can say that
¯
X − μ0
W(X 1, X 2, ⋯, X n) =
S / √n

is approximately standard normal. Therefore, we accept H 0 : μ = μ 0 if

| |
¯
X − μ0
≤ z α,
S / √n 2

and reject it otherwise (i.e., accept H 1 : μ ≠ μ 0).

Let us summarize what we have obtained for the two-sided test for the mean.

Table 8.2: Two-sided hypothesis testing for the mean: H 0 : μ = μ 0, H 1: μ ≠ μ 0.

Case Test Statistic Acceptance Region

¯
2 X − μ0 |W| ≤ zα
X i ∼ N(μ, σ ), σ known W= 2
σ / √n

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 6/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

¯
X − μ0
n large, X i non-normal |W| ≤ zα
W= 2
S / √n

¯
X − μ0
Xi ∼ N(μ, σ 2), σ unknown | W | ≤ tα ,n−1
W= 2
S / √n

One-sided Tests for the Mean:

We can provide a similar analysis when we have a one-sided test. Let's show this by an example.

Example 8.28
Let X 1,X 2,...,X n be a random sample from a N(μ, σ 2) distribution, where μ is unknown and σ is known.
Design a level α test to choose between

H 0: μ ≤ μ 0,

H 1: μ > μ 0.

Solution
As before, we define the test statistic as
¯
X − μ0
W(X 1, X 2, ⋯, X n) = .
σ / √n

¯
If H 0 is true (i.e., μ ≤ μ 0), we expect X (and thus W) to be relatively small, while if H 1 is true, we
¯
expect X (and thus W) to be larger. This suggests the following test: Choose a threshold, and call
it c. If W ≤ c, accept H 0, and if W > c, accept H 1. How do we choose c? If α is the required
significance level, we must have

P(type I error) = P(Reject H 0 | H 0)


= P(W > c | μ ≤ μ 0) ≤ α.

Here, the probability of type I error depends on μ. More specifically, for any μ ≤ μ 0, we can

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 7/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

write

P(type I error | μ) = P(Reject H 0 | μ)


= P(W > c | μ)

( )
¯
X − μ0
=P >c | μ
σ / √n

( )
¯
X−μ μ − μ0
=P + >c | μ
σ / √n σ / √n

( )
¯
X−μ μ0 − μ
=P >c+ | μ
σ / √n σ / √n

( )
¯
X−μ
≤P >c | μ ( since μ ≤ μ 0)
σ / √n

¯
X−μ
= 1 − Φ(c) ( since given μ, ∼ N(0, 1) ).
σ / √n

Thus, we can choose α = 1 − Φ(c), which results in

c = z α.

Therefore, we accept H 0 if

¯
X − μ0
≤ z α,
σ / √n

and reject it otherwise.

The above analysis can be repeated for other cases. More generally, suppose that we are given a random
sample X 1,X 2,...,X n from a distribution. Let μ = EX i. Our goal is to decide between

H 0: μ ≤ μ 0,

H 1: μ > μ 0.

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 8/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

We define the test statistic as before, i.e., we define W as


¯
X − μ0
W(X 1, X 2, ⋯, X n) = ,
σ / √n

if σ =
√Var(Xi) is known, and as
¯
X − μ0
W(X 1, X 2, ⋯, X n) = ,
S / √n

¯
if σ is unknown. If H 0 is true (i.e., μ ≤ μ 0), we expect that X (and thus W) to be relatively small, while if H 1
¯
is true, we expect X (and thus W) to be larger. This suggests the following test: Choose a threshold c. If W ≤ c
, accept H 0, and if W > c, accept H 1. To choose c, note that

P(type I error) = P(Reject H 0 | H 0)


= P(W > c | μ ≤ μ 0)
≤ P(W > c | μ = μ 0).

Note that the last inequality resulted because if we make μ larger, the probability of W > c can only increase.
In other words, we assumed the worst case scenario, i.e, μ = μ 0 for the probability of error. Thus, we can
choose c such that P(W > c | μ = μ 0) = α. By doing this procedure, we obtain the acceptance regions
reflected in Table 8.3.

Table 8.3: One-sided hypothesis testing for the mean: H 0 : μ ≤ μ 0, H 1: μ > μ 0.

Case Test Statistic Acceptance Region

¯
X − μ0
X i ∼ N(μ, σ 2), σ known W=
W ≤ zα
σ / √n

¯
X − μ0
n large, X i non-normal W= W ≤ zα
S / √n

¯
X − μ0
Xi ∼ N(μ, σ 2), σ unknown W= W ≤ tα , n − 1
S / √n

Note that the tests mentioned in Table 8.3 remain valid if we replace the null hypothesis by μ = μ 0. The
reason for this is that in choosing the threshold c, we assumed the worst case scenario, i.e, μ = μ 0. Finally, if
we need to decide between

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 9/10
27/02/2024, 23:50 Hypothesis Testing for the Mean

H 0: μ ≥ μ 0,

H 1: μ < μ 0,

we can again repeat the above analysis and we obtain the acceptance regions reflected in Table 8.4.

Table 8.4: One-sided hypothesis testing for the mean: H 0 : μ ≥ μ 0, H 1: μ < μ 0.

Case Test Statistic Acceptance Region

¯
X − μ0
X i ∼ N(μ, σ 2), σ known W=
W ≥ − zα
σ / √n

¯
X − μ0
n large, X i non-normal W ≥ − zα
W=
S / √n

¯
X − μ0
Xi ∼ N(μ, σ 2), σ unknown W= W ≥ − tα , n − 1
S / √n

← previous
next →

The print version of the book is available on Amazon.

Practical uncertainty: Useful Ideas in Decision-Making, Risk, Randomness, & AI

https://www.probabilitycourse.com/chapter8/8_4_3_hypothesis_testing_for_mean.php 10/10

You might also like