Chapter 2: Chi-Square Tests
Section 2.1
Introduction and Goodness-of-Fit Test
for patterns/proportions/counts/ratios
Section 2.1: Introduction to Goodness-of-Fit Tests
o Introduction to the concept of a GoF test
o GoF tests for data matching a given
pattern/proportions/counts/ratios
Introduction
• Recall: The 𝜒 2 -test is used to perform hypothesis tests concerning a
population variance, 𝜎 2 .
• However, the 𝜒 2 -test can also be used for other types of hypothesis
tests:
Goodness-of-Fit Tests (one-way table)
Tests of Independence and tests for Homogeneity (two-way table)
• For Goodness-of-Fit tests, we consider one qualitative (categorical)
variable with two or more categories.
• For Tests of Independence or Homogeneity, we consider two
categorical variables with two or more categories each.
Chi-Square Goodness-of-Fit Tests
• This is used to test if a sample of data came from a population with
a specific distribution.
• In a goodness-of-fit test, we test the null hypothesis that the
observed frequencies for the different categories of the variable
follow a certain pattern or theoretical distribution.
• The test is called a goodness-of-fit test because the hypothesis
tested is:
How good the observed frequencies in an observed sample fit
the expected frequencies from a hypothesized distribution.
• This test makes use of representing the data in a one-way table.
We can test the hypothesis that the proportion of the
counts/frequencies, 𝑝𝑖 , in each category of the variable must be
equal to a specific value:
𝐻0: 𝑝1 = 𝑎1, 𝑝2 = 𝑎2, … , 𝑝𝑘 = 𝑎𝑘
These hypothesized values, 𝑎𝑖 , may not always be given, but can
easily be determined. For example:
If we want to test if a die is balanced, then each number (1 to
1
6) occurs with a probability of , and thus the expected
6 1
proportion of times each number is tossed would be .
6
The alternative hypothesis is
𝐻1: At least one 𝑝𝑖 is not equal to its specified value
Since the GoF (Goodness-of-Fit) test is based on comparing the
observed frequencies to the expected frequencies under the null
hypothesis, the expected frequencies are calculated as
𝑒𝑖 = 𝑛 × 𝑝𝑖
where:
o 𝑒𝑖 = is the expected frequency of category 𝑖,
o 𝑛 is the sample size or number of times the experiment has been
carried out, 𝑛 is also obtained by summing the observed
frequencies (this 𝑛 has nothing to do with the 𝑛 in a binomial dist)
o 𝑝𝑖 = 𝑎𝑖 is the expected proportion of counts for category 𝑖 as
specified in the null hypothesis (as per the previous slide).
Chi-square Goodness-of-Fit Test Statistic
Our Chi-square goodness-of-fit test statistic is given by:
𝑘
𝑜𝑖 − 𝑒𝑖 2 N.B: 𝑒𝑖 must be ≥ 5. If not,
2
𝜒0 = combined adjacent classes
𝑒𝑖
𝑖=1 so that 𝑒𝑖 ≥ 5.
observed frequency expected frequency
𝐻0 is rejected if:
2
𝜒02 > 𝜒𝑘−1−𝑚;𝛼 (the critical value for a right-tailed test – only one
rejection rule)
Or if P-value = 𝑃 𝜒 2 > 𝜒02 < 𝛼
𝑘 = no. of classes/groups after adjusting for 𝑒𝑖 if 𝑒𝑖 < 5 and
𝑚 = no. of unknown parameters to be estimated in the hypothesized distribution
Example 1:
Two companies, A and B, have recently conducted aggressive
advertising campaigns to maintain and possibly increase their
respective shares of the market for fabric softener. These two
companies enjoy a dominant position in the market.
Before the advertising campaigns began, the market share of
company A was 45%, whereas company B had 40% of the market.
Other competitors accounted for the remaining 15%.
To determine whether these market shares changed after the
advertising campaigns, a marketing analyst solicited the preferences
of a random sample of 200 customers of fabric softener.
…Of the 200 customers, 102 indicated a preference for company A's
product, 82 preferred company B's fabric softener, and the
remaining 16 preferred the products of one of the competitors.
Can the analyst infer at the 5% significance level that customer
preferences have changed from their levels before the advertising
campaigns were launched?
Solution:
We compare market share before and after an advertising campaign
to see if there is a difference (i.e. if the advertising was effective in
improving market share).
Let
𝑝1 = market share of company A before the advertising campaign,
𝑝2 = market share of company B before the advertising campaign,
𝑝3 = market share of the competitors before the advertising campaign.
Therefore, the hypothesized values for the parameters equal to the
before-market share, i.e.
𝐻0: 𝑝1 = 0.45, 𝑝2 = 0.40, 𝑝3 = 0.15
The alternative hypothesis is a denial of the null. That is,
𝐻1: At least one 𝑝𝑖 is not equal to its specified value
In order to calculate our test statistic, we lay-out the data in a
tabular fashion for easier calculation by hand:
Observed
Company
Frequency
A 102
B 82
Others 16
…Of the 200 customers, 102 indicated a preference for company A's
product, 82 preferred company B's fabric softener, and the
remaining 16 preferred the products of one of the competitors.
𝑒𝑖 = 𝑛𝑝𝑖
Observed Expected
Company
Frequency Frequency 𝑛 = 200
A 102 200×0.45 = 90 Expected Frequency
B 82 200×0.40 = 80 ≥ 5 ∴ no need to
combine adjacent
Others 16 200×0.15 = 30 groups
Total 200 200
Check that these are equal
𝐻0: 𝑝1 = 0.45, 𝑝2 = 0.40, 𝑝3 = 0.15
Observed Expected
Company
Frequency Frequency
A 102 90
𝑘=3 B 82 80
Others 16 30
Total 200 200
𝑘
2 2 2 2
2
𝑜𝑖 − 𝑒𝑖 102 − 90 82 − 80 16 − 30
𝜒0 = = + +
𝑒𝑖 90 80 30
𝑖=1
= 8.18
𝛼 = 0.05, 𝑘 = 3, 𝑚 = 0 (There are no unknown parameters to estimate)
The critical value:
2 2
𝜒𝑘−1−𝑚; 𝛼 = 𝜒2; 0.05
= 5.991
𝜒02 = 8.18
∴ Since 𝜒02 > 5.991, 𝐻0 is rejected at a 5% l.o.s.
Thus, there is sufficient evidence to conclude the market share
proportions have changed after advertising campaign.
Or, using the P-value approach… 𝜒02 = 8.18, 𝑑𝑓 = 𝑘 − 1 − 𝑚 = 2
The P-value:
= 𝑃(𝜒 2 > 𝜒02 )
= 𝑃(𝜒 2 > 8.18)
∴ 0.01 < P-value < 0.025
Thus, P-value < 0.05 7.378 < 8.18 < 9.210
∴ Since P-value < α = 0.05, 𝐻0 is rejected at a 5% level of significance.
Example 2:
To test whether a six-sided die is fair (balanced), it is tossed 30 times
and the frequency of the number facing up is recorded. The
observed frequencies are shown in the table on the next slide.
Solution:
1
Recall for a balanced six-sided die: 𝑃 𝑋 = 𝑥 = , 𝑥 = 1, 2, 3, 4, 5, 6
6
1 1 1
∴ 𝐻0: 𝑝1 = , 𝑝2 = , … , 𝑝6 =
6 6 6
Face-up Value Observed Freq. Expected Freq.
1 3 30 × 1/6 = 5 𝑒𝑖 = 𝑛𝑝𝑖
2 10 5
1
3 5 5 𝑝𝑖 = ∀𝑖
6
𝑘=6
4 2 5
5 6 5
𝑒𝑖 ≥ 5, ∀𝑖
6 4 5
Total 𝒏 = 30 30
𝑘
2 2 2 2
2
𝑜𝑖 − 𝑒𝑖 3−5 10 − 5 4−5
𝜒0 = = + + … +
𝑒𝑖 5 5 5
𝑖=1
=8
𝛼 = 0.05, 𝑘 = 6, 𝑚 = 0 (There are no unknown parameters to estimate)
𝜒02 = 8 𝑑𝑓 = 𝑘 − 1 − 𝑚 = 5
2 2
The critical value: 𝜒𝑘−1−𝑚; 𝛼 = 𝜒5; 0.05 = 11.07
∴ Since 𝜒02 < 11.07, 𝐻0 is NOT rejected at a 5% l.o.s.
Thus, there is insufficient evidence to conclude that the die is not
1
balanced (i.e. we cannot say 𝑝𝑖 ≠ ∀𝑖)
6
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 8) → 0.1 < P-value < 0.9
∴ Since P-value > α = 0.05, 𝐻0 is NOT Thus, P-value > 0.05
rejected at a 5% l.o.s. (same conclusion as using the critical value)
Chapter 2: Chi-Square Tests
Section 2.2
Goodness-of-Fit Test for Specific
Parametric Distributions
Section 2.2: Goodness-of-Fit Test for Specific Parametric
Distributions
o STAT130 Recap on Binomial, Poisson and Normal Distributions
o GoF tests for fitting a discrete (Poisson and Binomial) or
continuous (Normal) distribution
• So far we have considered a goodness-of-fit test for testing the
hypothesis that the expected proportions will follow set values.
• This can be extended to test if the data takes on a specific
parametric distribution.
• For example a test to see if the data follows a Poisson distribution,
binomial distribution, normal distribution etc…
𝐻0: The data follows a specific distribution
𝐻1: The data does not follow a specific distribution
• The expected frequencies can the be calculated using the
specified distribution under the null hypothesis.
1. Binomial Distribution discrete random variable
Definition: If the following conditions hold:
1) A Bernoulli trial is repeated a fixed 𝑛 times where each trial
results in two outcomes; a “success” or “failure”,
2) The outcomes of each Bernoulli trial are independent of each
other,
3) The probability of success 𝑃(success) = 𝑝 is constant for each
trial,
then 𝑋 = number of successes out of the 𝑛 trials follows a Binomial
distribution with parameters 𝑛 and 𝑝, i.e. 𝑋~Bin(𝑛, 𝑝), with the following
probability mass function (p.m.f.):
𝑛 𝑥
𝑓 𝑥 = 𝑝 1 − 𝑝 𝑛−𝑥 for 𝑥 = 0, 1, 2, … , 𝑛
𝑥
Cumulative Binomial Distribution Tables
• Recall from STAT130: Instead of using the p.m.f. 𝑓(𝑥) to solve the
problems concerning cumulative probability, e.g. 𝑃(𝑋 ≤ 𝑥), the c.d.f.
𝐹(𝑥) can be used.
• Values for the c.d.f. are found in the Cumulative Binomial Distribution
tables (Table A) – on Moodle.
• There are several tables – one for each different value of 𝑛. The first
column gives the value of 𝑛 while the second column gives the possible
values that the random variable 𝑋 can take on. The top row gives
common values of 𝑝.
Note: These tables give cumulative probabilities 𝑃(𝑋 ≤ 𝑥), so situations that
involve the “<”, “>”and “≥” signs must be adjusted so that they are in a form
that uses the “≤” sign i.e. a “less than or equal to” situation.
Examples:
1) Suppose X ~ Bin(12 , 0.6). Find the probability that X is less than or
equal to 5:
Here we want to find 𝐹(5) = 𝑃(𝑋 ≤ 5).
Step 1: Find the table that has 𝑛 = 12 in the first column.
Step 2: Choose the value 𝑥 = 5 in the second column.
Step 3: Find 𝑝 = 0.6 in the top row.
The value given at the intersection of the “𝑥 = 5” and the “𝑝 = 0.6” is
𝐹(5) = 𝑃(𝑋 ≤ 5) = 0.1582
0.1582
2. Poisson Distribution
Definition: If a random variable 𝑋 counts the number of events
(successes) that occur at random in an interval of time or space with
the average number of events that occur in the given time/space
interval denoted by 𝜆 , then 𝑋 follows a Poisson distribution with
parameter 𝜆, i.e. 𝑋~Po(𝜆), and the following p.m.f.:
𝑒 −𝜆 𝜆𝑥 for 𝑥 = 0, 1, 2, … ,
𝑓 𝑥 =
𝑥! 𝜆>0
Take note of the different notation from STAT130: 𝜇 = 𝜆
Examples
1) The number of bad cheques presented for daily payment at a bank.
2) The number of road deaths per month.
3) The number of bacteria in a given culture.
4) The number of defects per square meter on metal sheets being
manufactured.
5) The number of mistakes per typewritten page.
If 𝑋~Po(𝜆), then the mean and variance are given by:
𝐸 𝑋 =𝜆 and 𝑉𝑎𝑟 𝑋 = 𝜆
The value of 𝜆 for the Poisson distribution must correspond to the interval of
time/space for which the probability, mean or variance is being calculated.
Cumulative Poisson Distribution Tables
The Cumulative Poisson Distribution tables (Table B) can be found on
Moodle.
The top row gives some values for 𝜆 = 𝜇 and the first column gives
some values that Poisson random variable 𝑋 can take on.
The cumulative probabilities 𝐹(𝑥) = 𝑃(𝑋 ≤ 𝑥) can be found by lining up
the relevant row and column.
Reminder: As with the Cumulative Binomial Distribution tables, these tables give
cumulative probabilities 𝑃(𝑋 ≤ 𝑥) only!
Example:
1) Suppose 𝑋 ~ 𝑃𝑜(4). Find the probability that 𝑋 is less than or equal to 3:
Here we want to find 𝐹(3) = 𝑃(𝑋 ≤ 3).
Step 1: Find the table that has 𝜆 = 4.0 in the top row.
Step 2: Find the value 𝑥 = 3 in the first column.
Step 3: Line up the column and row to obtain 𝑃(𝑋 ≤ 3) = 0.4335
0.4335
3. The Normal Distribution
• Recall from STAT130: The normal distribution is the most frequently
used continuous probability distribution is statistics.
• If 𝑋 follows a normal distribution then it is defined by parameters 𝜇
(the mean) and 𝜎 2 (the variance), i.e. if 𝑋~𝑁(𝜇, 𝜎 2 ).
Recall, to find probability concerning any normal random variable, we
need to standardize the variable using the following formula in order
to use the tables:
𝑋−𝜇
𝑍=
𝜎
(FYI)
• The standard normal table (Table C1 and C2) gives the area under
the curve to the left of a z-value.
• Other areas can be found using the property that the total area
under the curve equals 1.
The mean µ = 0
The z-values to the The z-values to the
left of the mean right of the mean
are negative. are positive.
Calculating probabilities using the standard normal tables
The standard normal tables can be found in the statistical tables on
Moodle (Table C).
Recall: The areas shown in the table are those under the standard
normal curve to the left of the corresponding z-value.
i.e. 𝑃(𝑍 ≤ 𝑧) = 𝑃(𝑍 < 𝑧) As 𝑃 𝑍 = 𝑧 = 0 since 𝑍
is a continuous random
variable
e.g. 𝑃(𝑍 ≤ 1.25)
Recall: 𝑃 𝑎 < 𝑍 < 𝑏 =
This shaded 𝑃 𝑍 < 𝑏 − 𝑃(𝑍 < 𝑎)
region is what the
tables gives us.
1.25
How to use the standard normal tables to find
areas/probabilities:
There are two standard normal tables:
• Table C1 gives the areas to the left of all the negative z-values.
• Table C2 gives areas to the left of all the positive z-values.
All z-values in the tables are to 2 decimal places.
The first column represents the units position and first decimal place
of the z-value.
The top row represents the second decimal place of the z-value.
The values in the body of the table represent the areas.
Second decimal place
Units position
and first
Areas
0000
decimal place
Example 1:
𝑃(𝑍 < 1.35)
Units position and
first decimal place:
1.30
Locate this in the first
column.
Second decimal
place: 0.05
Locate this in the top
row.
Finding the value in
the body of the
table that
corresponds to this
column and row will
give the area to the
left of 1.35
∴ 𝑃 𝑍 < 1.35 0.9115
= 0.9115
Chi-Square Goodness-of-Fit Test
Example 1:
Let 𝑋 denote the repair times in the number of days required for a
certain component in an airplane. We wish to test whether a Poisson
model with a mean of three days appears to be a reasonable model
for this variable. The repair times of 40 components were recorded,
with the results shown in the table on the next slide. In some cases the
component could be repaired immediately on site, which is
interpreted as zero days. Test at 𝜶 = 𝟎. 𝟏
Solution: 𝐻0: 𝑋 ~ Poi(3) is an appropriate model
𝐻1: 𝑋 ~ Poi(3) is not an appropriate model
Repair Times (𝑿) Oi o For this example, we are not given
the values of 𝑝𝑖 in the null hypothesis.
0 1 o Recall 𝑝𝑖 is required to find the
1 3 expected frequencies, 𝑒𝑖 .
2 7 o However, we are testing to see if the
3 6 repair times in days follow a Poisson
4 10 distribution with 𝜆 = 3, thus we can
5 7 easily calculate the 𝑝𝑖 values.
6 6
≥7 0 𝑒 −3 3𝑥
Thus, 𝑝𝑖 = 𝑃 𝑋 = 𝑥 =
𝑥!
𝑒 −3 3𝑥
Repair Times (𝑿) Oi 𝒑𝒊 𝑝𝑖 = 𝑃 𝑋 = 𝑥 =
𝑥!
0 1 0.050 𝑒𝑒−3
−33 30165432
𝑝8∴ =
𝑝4765321𝑃(𝑋
== 𝑃(𝑋
𝑃(𝑋 = 1)1=
= 0)
≥ 7) 3)
2)
4)
5)
6)
= =− 𝑃(𝑋 ≤ 6)
1 3 0.149 0!
1!
2!
3!
4!
6!
5!
2 7 0.224 = 1 − (0.05 + 0.149
=+
= ⋯ + 0.05)
0.050
0.149
0.224
0.168
0.101
0.050
3 6 0.224 = 0.034
4 10 0.168
(or use the cumulative
5 7 0.101 Poisson tables)
6 6 0.050
∑𝑝𝑖 = 1 (the sum of the
≥7 0 0.034
probabilities must be 1)
Total 40 1
Repair Times 𝑒𝑖 = 𝑛𝑝𝑖
Oi 𝒑𝒊 𝒆𝒊 𝑛 = 40
(𝑿)
0 1 0.050 40 × 0.050 = 2
1 3 0.149 40 × 0.149 = 5.96 These expected
frequencies are
2 7 0.224 8.96
less than 5.
3 6 0.224 8.96
4 10 0.168 6.72 ∴ We must group
5 7 0.101 4.04 the adjacent
frequencies
6 6 0.050 2.00
together so that
≥7 0 0.034 1.36 𝑒𝑖 ≥ 5.
Total 40 1 40
Repair Times
Oi 𝒑𝒊 𝒆𝒊
(𝑿)
0 1 0.050 2
4 7.96
1 3 0.149 5.96
2 7 0.224 8.96 The observed
3 6 0.224 8.96 frequencies, 𝑂𝑖 , must
be grouped too.
4 10 0.168 6.72
5 7 0.101 4.04
6 6 13 0.050 2.00 7.40
≥7 0 0.034 1.36
Total 40 1 40
Repair Times Now, the number of
Oi 𝒑𝒊 𝒆𝒊
(𝑿) groups reduces to 5.
0 1 0.050 2
1 4 7.96
1 3 0.149 5.96
2 2 7 0.224 8.96
3 3 6 0.224 8.96 ∴𝑘=5
4 4 10 0.168 6.72
5 7 0.101 4.04
6 5 6 13 0.050 2.00 7.40
≥7 0 0.034 1.36
Total 40 1 40
𝑘
2
Oi 𝒆𝒊 2
𝑜𝑖 − 𝑒𝑖
𝜒0 =
𝑒𝑖
𝑖=1
1 2
4 7.96
3 5.96
7 8.96 4 − 7.96 2 7 − 8.96 2 13 − 7.40 2
= + + … +
6 8.96 7.96 8.96 7.40
10 6.72
= 9.22
7 4.04
6 13 2.00 7.40
0 1.36
𝛼 = 0.1, 𝑘 = 5, 𝑚 = 0 (There are no unknown parameters to estimate)
𝜒02 = 9.22 𝑑𝑓 = 𝑘 − 1 − 𝑚 = 4
2 2
The critical value: 𝜒𝑘−1−𝑚; 𝛼 = 𝜒4; 0.1 = 7.779
∴ Since 𝜒02 > 7.779, 𝐻0 is rejected at a 10% l.o.s.
Thus, there is sufficient evidence to conclude that the repair times DO
NOT follow a Poisson distribution with a mean of 3 days (𝐻1 ).
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 9.22) → 0.05 < P-value < 0.1
∴ Since P-value < α = 0.1, 𝐻0 is Thus, P-value < 0.1
rejected at a 10% l.o.s. (same conclusion as using the critical value)
Example 2:
Consider the previous example again. Suppose now we wish to test if
𝑋~𝑃𝑜𝑖(𝜆).
I.e. We wish to test the data follows a Poisson distribution with an
unspecified value of 𝜆.
Solution: 𝐻0: 𝑋 ~ Poi(𝜆) is an appropriate model
𝐻1: 𝑋 ~ Poi(𝜆) is not an appropriate model
In order to find the probabilities and hence the expected values, we
need to use the data to estimate 𝜆…
Recall for a Poisson distribution, 𝐸 𝑋 = 𝜆 (the mean/average of the
data). 𝑓𝑖
Therefore, we can find the mean of the
Repair Times (𝑿) O observations and use that to estimate 𝜆:
i
0 1 ∴𝜆 (the mean of a
1 𝑘
frequency distribution)
1 3 ≈ 𝑓𝑖 𝑥𝑖
𝑛 𝑖=1
2 7
3 6 0 1 +1 3 +2 7 + …+6 6
=
4 10 40
5 7 = 3.65
6 6
≥7 0
Now, we can recalculate the
Repair Times (𝑿) Oi 𝒑𝒊
probabilities on slide 21 using
0 1 0.026 𝜆 = 3.65 instead of 3:
1 3 0.095
2 7 0.173 𝑒 −3.65 3.65𝑥
𝑝𝑖 = 𝑃 𝑋 = 𝑥 =
3 6 0.211 𝑥!
4 10 0.192
5 7 0.140 From these updated
probabilities, we can calculate
6 6 0.085
the new expected values…
≥7 0 0.078
Total 40 1
Repair Times
Oi 𝒑𝒊 𝒆𝒊 𝑒𝑖 = 𝑛𝑝𝑖
(𝑿)
𝑛 = 40
0 1 0.026 40 × 0.026 = 1.04
1 3 0.095 40 × 0.095 = 3.80 These expected
frequencies are
2 7 0.173 6.92
less than 5.
3 6 0.211 8.44
4 10 0.192 7.68 ∴ We must group
5 7 0.140 5.60 the adjacent
frequencies
6 6 0.085 3.40
together so that
≥7 0 0.078 3.12 𝑒𝑖 ≥ 5.
Total 40 1 40
Repair Times The number of
Oi 𝒑𝒊 𝒆𝒊 groups reduces
(𝑿)
to 5.
0 1 0.026 40 × 0.026 = 1.04
1 3 11 0.095 40 × 0.095 = 3.80 11.76
2 7 0.173 6.92
3 6 0.211 8.44
∴𝑘=5
4 10 0.192 7.68
5 7 0.140 5.60
6 6 0.085 3.40
6 6.52
≥7 0 0.078 3.12
Total 40 1 40
𝑘
2
Oi 𝒆𝒊 2
𝑜𝑖 − 𝑒𝑖
𝜒0 =
𝑒𝑖
𝑖=1
1 1.04
3 11 3.80 11.76
7 6.92 11 − 11.76 2 6 − 8.44 2 6 − 6.52 2
= + + … +
6 8.44 11.76 8.44 6.52
10 7.68
= 1.85
7 5.60
6 3.40
6 6.52
0 3.12
𝛼 = 0.1, 𝑘 = 5, 𝒎 = 𝟏 (Since 𝝀 was estimated from the data)
𝜒02 = 1.85 𝑑𝑓 = 𝑘 − 1 − 𝑚 = 5 − 1 − 1 = 3
2 2
The critical value: 𝜒𝑘−1−𝑚; 𝛼 = 𝜒3; 0.1 = 6.251
∴ Since 𝜒02 < 6.251, 𝐻0 is NOT rejected at a 10% l.o.s.
Thus, we can conclude the data may follow a Poisson distribution.
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 1.85)
Since 0.584 < 𝜒02 = 1.85 < 6.251 → 0.1 < P-value < 0.9
∴ Since P-value > α = 0.1, 𝐻0 is not Thus, P-value > 0.1
rejected at a 10% l.o.s. (same conclusion as using the critical value)
Example 3:
Test the hypothesis at a 5% l.o.s. that the frequency distribution of
battery lives may be approximated by Normal distribution with mean
of 3.5 and standard deviation of 0.7.
Class boundaries Oi
Solution:
1.45-1.95 2
𝐻0 : 𝑋~𝑁 3.5; 0.72 is an appropriate 1.95-2.45 1
model 2.45-2.95 4
2.95-3.45 15
𝐻1 : 𝑋~𝑁 3.5; 0.72 is not an appropriate
3.45-3.95 10
model
3.95-4.45 5
4.45-4.95 3
First we need to adjust the lower limit of the first class and upper limit
of the last class so that the probabilities sum to 1:
𝑋 − 3.5
To find 𝑝𝑖 , we will use the standard normal tables where 𝑍 =
0.7
Class
Oi 𝒑𝒊
boundaries
−∞ 1.45-1.95 2 𝑃(𝑋 < 1.95) = 𝑃(𝑍 < −2.21) = 0.0136
1.95-2.45 1 𝑃(1.95 < 𝑋 < 2.45) = 𝑃(−2.21 < 𝑍 < −1.5) = 0.0532
2.45-2.95 4 𝑃(2.45 < 𝑋 < 2.95) = 𝑃(−1.5 < 𝑍 < −0.79) = 0.148
2.95-3.45 15 𝑃(2.95 < 𝑋 < 3.45) = 𝑃(−0.79 < 𝑍 < −0.07) = 0.257
3.45-3.95 10 𝑃(3.45 < 𝑋 < 3.95) = 𝑃(−0.07 < 𝑍 < 0.64) = 0.2668
3.95-4.45 5 𝑃(3.95 < 𝑋 < 4.45) = 𝑃(0.64 < 𝑍 < 1.36) = 0.1742
4.45-4.95 ∞ 3 1− (sum of probability of 6 previous classes)= 0.0872
𝑒𝑖 = 𝑛𝑝𝑖
Class
Oi 𝒑𝒊 𝒆𝒊 𝑛 = 40
boundaries
−∞ -1.95 2 0.0136 40 × 0.0136 = 0.544
1.95-2.45 7 1 0.0532 40 × 0.0532 = 2.128 8.592
2.45-2.95 4 0.1480 5.92
2.95-3.45 15 0.2570 10.28
3.45-3.95 10 0.2668 10.672
3.95-4.45 5 0.1742 6.968
8 10.456
4.45- ∞ 3 0.0872 3.488
40 1 40
These expected frequencies are less than 5, therefore group adjacent classes.
The number of groups reduces to 4. ∴𝑘=4
Oi 𝒆𝒊
𝑘
𝑜𝑖 − 𝑒𝑖 2
2
2 0.544 𝜒0 =
𝑒𝑖
7 1 2.128 8.592 𝑖=1
4 5.92 7 − 8.592 2
15 − 10.28 2
10 − 10.672 2
= + +
15 10.28 8.592 10.28 10.672
10 10.672 8 − 10.456 2
5 6.968 +
8 10.456 10.456
3 3.488
∴ 𝜒02 = 3.08
𝛼 = 0.05, 𝑘 = 4, 𝑚 = 0 (We did not use estimates for 𝜇 and 𝜎)
𝜒02 = 3.08 𝑑𝑓 = 𝑘 − 1 − 𝑚 = 4 − 1 − 0 = 3
2 2
The critical value: 𝜒𝑘−1−𝑚; 𝛼 = 𝜒3; 0.05 = 7.815
∴ Since 𝜒02 < 7.815, 𝐻0 is NOT rejected at a 5% l.o.s.
Thus, we can conclude that 𝑋~𝑁(3.5; 0.72 ) is appropriate for the data.
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 3.08)
Since 0.584 < 𝜒02 = 3.08 < 6.251 → 0.1 < P-value < 0.9
∴ Since P-value > α = 0.05, 𝐻0 is not Thus, P-value > 0.1
rejected at a 5% l.o.s. (same conclusion as using the critical value)
Example 4:
Consider the previous example again. Suppose now we wish to test if
𝑋~𝑁(𝜇, 𝜎 2 )
I.e. We wish to test the data follows a Normal distribution with an
unspecified value of 𝜇 and 𝜎 2 .
Solution: 𝐻0: 𝑋~𝑁(𝜇, 𝜎 2 ) is an appropriate model
𝐻1: 𝑋~𝑁(𝜇, 𝜎 2 ) is not an appropriate model
In order to find the probabilities and hence the expected values, we
need to use the data to estimate the mean 𝜇 and the variance 𝜎 2 …
We need to estimate the parameters 𝜇 and 𝜎 2
Recall for a frequency distribution:
𝑘 Class Midpoints 1 𝑘
1 𝜎 2≈ 𝑓𝑖 𝑥𝑖 2 − 𝑛𝑥ҧ 2
𝜇 ≈ 𝑓𝑖 𝑥𝑖 𝑛−1 𝑖=1
𝑛 𝑖=1
Degrees of Freedom = 𝒌 − 𝟏 − 𝒎 where 𝒎 = 𝟐 is the number of
parameters estimated (𝝁 and 𝝈𝟐 ).
Rework the example by setting up the table to determine if
𝑿~𝑵(𝝁; 𝝈𝟐 ) is a suitable model for our data.
Chapter 2: Chi-Squared Tests
Section 2.3
Test of Independence and Homogeneity
Section 2.3: Chi-Square Test of Independence and
Homogeneity
o Test of Independence
o Test of Homogeneity
Chi-Squared Test of Independence
The Chi-squared test of independence is used to:
Determine if there is a significant relationship/association
between two categorical (nominal) variables.
• The test uses a two-way table called a contingency table that
displays the observed counts/frequencies of each combination of
the categories of the two variables.
• The hypotheses for the test are:
𝐻0 : The two variables are independent (there is NO association/ relationship)
𝐻1 : The two variables are dependent (there is an association/ relationship)
If the null hypothesis is rejected, it can be concluded that there is a
significant relationship between the two variables.
The following in an example of a two-way contingency table
summarizing the total enrolment at institutions of higher education.
Type of Enrolment
Full-time Part-time
Male 3768 2615
Gender
Female 4658 3717
The Test Statistic
𝑘
𝑜𝑖 − 𝑒𝑖 2
(the same as that from 2 2 Degrees of freedom=
𝜒0 = ~𝜒(𝑟−1)(𝑐−1)
Goodness-of-Fit tests) 𝑒𝑖 (#rows-1)(#columns-1)
𝑖=1
• 𝑜𝑖 = the observed count/frequency of a cell in the table.
• 𝑘 = the total number of cells in the table (=#rows × #columns,
which equals the number of combinations of the categories of
the two variables).
• 𝑒𝑖 = the expected count of a cell if the null hypothesis was true
(𝑒𝑖 ≥ 10), which is calculated as….
Assuming the null hypothesis is true, the expected counts for each cell
can determined:
Row total × Column total
𝑒𝑖 =
Grand total
What if 𝒆𝒊 <10?
• The test statistic on the previous slide is only valid if 𝑒𝑖 ≥ 10.
𝑘
𝑜𝑖 − 𝑒𝑖 − 0.5 2
2
• If 5 ≤ 𝑒𝑖 < 10, apply Yates correction 𝜒0 = 𝑒𝑖
𝑖=1
• If 𝑒𝑖 < 5, we use Fisher Irwin Test (not done in STAT140)
• Chi-square test statistic on the previous slide is a measure of how
different the observed counts are from the expected counts.
• If the test statistic is very large, it suggests there are large
differences between the observed and expected counts, and thus
the null hypothesis of independence should be rejected.
our expected frequencies are calculated based under the assumption that the two variables are
independent. If it is in fact the case that the two variables are independent, then the oi and ei will
be very close.
So how large must 𝜒02 be for 𝐻0 to be rejected?
• Since the null hypothesis is rejected for large values of 𝜒02 , 𝐻0 is then
rejected if 𝜒02 > critical value, where
critical value = 𝜒 2𝑟−1 𝑐−1 ; 𝛼
• Or 𝐻0 is rejected if P-value = 𝑃 𝜒 2 > 𝜒02 < 𝛼 .
Example:
Determine whether the opinions of the voting residents of the state of
Illinois concerning a new tax reform are independent of their levels of
income. Use a 5% level of significance
Income Level
Low Medium High
For 182 213 203
Opinion
Against 154 138 110
Solution:
𝐻0 : Voters opinion concerning a new tax reform are independent of
their levels of income.
𝐻1 : Voters opinion concerning a new tax reform are not independent
of their levels of income.
To find 𝑒𝑖 , first determine
Income Level
the row, column and
Total:
grand totals: Low Medium High
For 182 213 203 598
Opinion
Against 154 138 110 402
Total: 336 351 313 1000
Let’s consider the Income Level
first cell to find 𝑒𝑖 Total:
Low Medium High
For 182 (200.9) 213 (209.9) 203 (187.2) 598
Opinion
Against 154 (135.1) 138 (141.1) 110 (125.8) 402
Total: 336 351 313 1000
Row 1 total × Column 1 total 598 × 336
𝑒1 = = = 200.9
Grand total 1000
The expected cell counts are represented in brackets next to the
observed counts.
The rest of the expected counts are found in the same way…
Income Level
Total:
Low Medium High
For 182 (200.9) 213 (209.9) 203 (187.2) 598
Opinion
Against 154 (135.1) 138 (141.1) 110 (125.8) 402
Total: 336 351 313 1000
The calculation of the expected cell counts is based on the fact that,
under the null hypothesis of independence, we would expect to see
the same proportion of voters ‘for’ the tax reform whether they were
in the low, medium or high income group…
200.9 209.9 187.2
e.g. For those ‘for’ the tax reform: = = = 0.598
336 351 313
Income Level
Total:
Low Medium High
For 182 (200.9) 213 (209.9) 203 (187.2) 598
Opinion
Against 154 (135.1) 138 (141.1) 110 (125.8) 402
Total: 336 351 313 1000
Before calculating the test statistic, take note 𝑒𝑖 ≥ 10.
𝑘 2 2 2
𝑜𝑖 − 𝑒𝑖 2 182 − 200.9 213 − 209.9 110 − 125.8
2
𝜒0 = = + …
+ +
𝑒𝑖 200.9 209.9 125.8
𝑖=1
= 7.85
The degrees of freedom = 𝑟 − 1 𝑐 − 1 = 2 − 1 3 − 1 = 2
𝛼 = 0.05, 𝑑𝑓 = 2 𝜒02 = 7.85
2
The critical value: (𝑟−1)(𝑐−1); 𝛼 = 𝜒2;
𝜒 2
0.05 = 5.991
∴ Since 𝜒02 > 5.991, 𝐻0 is rejected at a 5% l.o.s.
Therefore, there is sufficient evidence to conclude that the voters’
opinions about tax reform are dependent on their income levels
(i.e. there is an association between their opinion about tax reform
and their income level.)
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 7.85) ⇒ 7.378 < 𝜒02 = 7.85 < 9.210
∴ 0.010 < P-value < 0.025
Thus, P-value < 0.05 So 𝐻0 is rejected at a 5% l.o.s.
Chi-Squared Test of Homogeneity
• In the Test of Independence, the overall sample size was decided
on, and then the frequencies/counts for the cells were observed.
E.g. in the previous example, we looked at a total of 1000 voters
and then recorded the counts according to each voter
opinion-income level combination in the cells. The row and
column totals were then determined.
• However, for a Test of Homogeneity, the row or column totals are
predetermined and then the observed counts/responses are filled
in the cells for the given row or column totals.
• We then test the hypothesis that the population proportions within
1 of the two variables
each row or column are the same.
Example 1:
Suppose it is of interest to get the opinion of voters about affordable
health care (known as Obama Care) in the US. It is decided in
advance to select 200 Democrats, 150 Republicans, and 150
Independents from the voters of the state of North Carolina and
record whether they are for a affordable health care, against it or
undecided. The results are as follows:
Affordable Political affiliation
Health Care Democrat Republican Independent Total
For 82 70 62 214
Against 93 62 67 222
Undecided 25 18 21 64
Total 200 150 150 500
Test the hypothesis that the opinion concerning affordable health
care are the same within each political affiliation. Use 0.05 level of
significance.
Since the column totals (total number of voters selected within each
political affiliation) were predetermined, a test of homogeneity is
carried out.
𝐻𝑜 : For each opinion, the proportion of Democrats, Republicans and
Independents are the same.
𝐻1: For at least one opinion, the proportion of Democrats,
Republicans and Independents are not the same.
The test procedure remains exactly the same as that of independence.
Affordable Political affiliation
Health Care Democrat Republican Independent Total
For 82 (85.6) 70 (64.2) 62 (64.2) 214
Against 93 (88.8) 62 (66.6) 67 (66.6) 222
Undecided 25 (25.6) 18 (19.2) 21 (19.2) 64
Total 200 150 150 500
To find the expected cell counts, 𝑒𝑖 , we use:
Row total × Column total
𝑒𝑖 =
Grand total
Affordable Political affiliation
Health Care Democrat Republican Independent Total
For 82 (85.6) 70 (64.2) 62 (64.2) 214
Against 93 (88.8) 62 (66.6) 67 (66.6) 222
Undecided 25 (25.6) 18 (19.2) 21 (19.2) 64
Total 200 150 150 500
Before calculating the test statistic, make sure all 𝑒𝑖 ≥ 10.
𝑘 2 2 2
𝑜𝑖 − 𝑒𝑖 2 82 − 85.6 70 − 64.2 21 − 19.2
2
𝜒0 = = + + … +
𝑒𝑖 85.6 64.2 19.2
𝑖=1
= 1.53
The degrees of freedom = 𝑟 − 1 𝑐 − 1 = 3 − 1 3 − 1 = 4
𝛼 = 0.05, 𝑑𝑓 = 4 𝜒02 = 1.53
2
The critical value: (𝑟−1)(𝑐−1); 𝛼 = 𝜒4;
𝜒 2
0.05 = 9.488
∴ Since 𝜒02 < 9.488, 𝐻0 is NOT rejected at a 5% l.o.s.
Therefore, there is insufficient evidence to conclude that the
proportion of Democrats, Republicans and Independents are different
for each opinion of affordable health care.
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 1.53) ⇒ 1.064 < 𝜒02 = 1.53 < 7.779
∴ 0.1 < P-value < 0.9
Thus, P-value > 0.05 So 𝐻0 NOT is rejected at a 5% l.o.s.
Example 2:
Do male and female university students have the same distribution of
living conditions? Use a level of significance of 0.05. Suppose that 100
randomly selected male students and 150 randomly selected female
students were asked about their living conditions: Res, Apartment,
With Parents, Other. The results are shown in the table below:
Living Condition
Res Apartment With Parents Other Total
Male 45 30 20 5 100
Female 75 35 25 15 150
Total 120 65 45 20 250
Since the row totals (total number of male and female students) were
predetermined, a test of homogeneity is carried out.
𝐻𝑜 : The distribution of living conditions for male students is the same as
the distribution of living conditions for female students.
𝐻1: The distribution of living conditions for male students is the not the
same as the distribution of living conditions for female students.
Living Condition
Res Apartment With Parents Other Total
Male 45 (48) 30(26) 20 (18) 5 (8) 100
Female 75 (72) 35 (39) 25 (27) 15 (12) 150
Total 120 65 45 20 250
To find the expected cell counts, 𝑒𝑖 , we use:
Row total × Column total
𝑒𝑖 =
Grand total
Living Condition
Res Apartment With Parents Other Total
Male 45 (48) 30(26) 20 (18) 5 (8) 100
Female 75 (72) 35 (39) 25 (27) 15 (12) 150
Total 120 65 45 20 250
Notice now that one of the expected cell counts is between 5 and 10,
therefore Yates correction must be used…
𝑘
𝑜𝑖 − 𝑒𝑖 − 0.5 2
2
𝜒0 =
𝑒𝑖
𝑖=1
Living Condition
Res Apartment With Parents Other Total
Male 45 (48) 30(26) 20 (18) 5 (8) 100
Female 75 (72) 35 (39) 25 (27) 15 (12) 150
Total 120 65 45 20 250
𝑘 2 2
𝑜𝑖 − 𝑒𝑖 − 0.5 2 45 − 48 − 0.5 15 − 12 − 0.5
2
𝜒0 = = …
+ +
𝑒𝑖 48 12
𝑖=1
= 2.51
The degrees of freedom = 𝑟 − 1 𝑐 − 1 = 2 − 1 4 − 1 = 3
𝛼 = 0.05, 𝑑𝑓 = 3 𝜒02 = 2.51
2
The critical value: (𝑟−1)(𝑐−1); 𝛼 = 𝜒3;
𝜒 2
0.05 = 7.815
∴ Since 𝜒02 < 7.815, 𝐻0 is NOT rejected at a 5% l.o.s.
Therefore, there is insufficient evidence to conclude that the
distribution of living conditions is not the same for male and female
students.
The P-value: 𝑃(𝜒 2 > 𝜒02 ) = 𝑃(𝜒 2 > 2.51) ⇒ 0.584 < 𝜒02 = 2.51 < 6.251
∴ 0.10 < P-value < 0.90
Thus, P-value > 0.05 So 𝐻0 NOT is rejected at a 5% l.o.s.