You are on page 1of 15

Course Code: STA 342

Course Title: TESTING HYPOTHESIS

http://ecampus.mmust.ac.ke
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

Topic 6: THE CHI-SQUARE (  2 ) TEST

Introduction

In this topic, we will perform the Chi-Square (  2 ) test that is applied to both parametric and non-
parametric distributions.

Objectives

By the end of this topic, you should be able to:

1. State and test a hypothesis on population variance when mean is given and when mean is not
given (  2 test).

2. Perform a goodness of fit  2 test,

3. Perform a  2 test for independence of attributes,

Learning Activities

Activity 1:
 Students to take note of the exercises provided within the text and at the end of the topic

Topic Resources

Students to take note of the reference text books provided in the course outline

Page 2 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

INTRODUCTION

 So far, we have been testing hypotheses on population parameters, i.e. population mean  , population

variance  2 , and population proportion P , among others.

 These tests are referred to as Parametric tests as they are centered around population parameters.

 However, not all real life situations require parametric testing, since some populations do not have well
defined distributions (Distribution-free populations), hence non–parametric tests become useful.

 Some common non–parametric tests include; Mann – Whitney U - test, Kruskal – Wallis test, Wilcoxon
Signed rank test, Kolmogorov – Smirnov test, Chi – Square test, etc.

 In this topic, we shall limit ourselves to the Chi – Square test because it is unique, as it applies to both
parametric and non-parametric situations.

 The Chi – Square test is applicable in the following situations:

a) A test for population variance

b) A test for independence of attributes

c) A test for goodness of fit

d) A test for homogeneity

A. TEST ON NPOPULATION VARIANCE: SINGLE SAMPLE

Let X  X1 , X 2 ,..., X n be identically and independently distributed random variable from normal distribution
with mean  and variance  2 , i.e. X ~ N   ,  2  . To test on variance, we need to review the following.

Recall that:
a) Knowledge of population variability is important, e.g.
i) An educator will want to choose a teaching strategy/ method with low variability in the
students achievement level,
ii) Tyres with low variability in wear may be preferred to more durable tyres with greater
variability in useful lifetime, simply because it’s cheaper to replace an entire set of tyres
periodically for each car,
Page 3 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

iii) A lengthy waiting time is acceptable if variability is smaller, etc.

b) If population variance =  2 is unknown, we have to estimate it using sample data (unbiased


variance), i.e.
1  
n 2
1
S2  
n  1 i 1
 xi  x  
n 1 

 xi2  n x 2 

c) If population variance =  2 is unknown, Student’s t- distribution is used to make inference about the
population mean. Thus, a Chi-square distribution assigns a role to S 2 that is similar to the role
Student’s t- distribution assigns to x .

d) Before a sample is taken, S 2 must be viewed as a random variable (just like x )


e) If  is unknown:

1  n 2 
n 2
from 1
xi  n x 2  ,
S2  
n  1 i 1
 xi  x  
n 1 

 i 1 

 n 
n 2
we have  n  1 S 2    xi  x     xi2  n x 2 
i 1  i 1 

2
n
 n 2 2 
 x  x   xi  n x 
Dividing  on both sides, then:  n  1 S
2 2 i

  i 1  ~  2 ......... *
i 1
 n 1
2
 2 2

f) If  is known:

1 n 
2
from 1 n
s2    xi       xi2  n  2  ,
n i 1 n  i 1 

 n 
n 2
we have n s 2    xi       xi2  n  2 
i 1  i 1 

2
n
 n 2 2 
 x     xi  n  
Dividing  2 on both sides, then:
2 i

  i 1  ~  2 ......... **
ns i 1

2 2 2
 n

Note:

i) Take note of the use of capital letter S 2 and small letter s 2 (to bring the difference in the above two
equations * and **)

ii)  n2 or  n21 is our test statistic depending on whether  is known or unknown

iii) n or n  1 is the degrees of freedom


Activity 4.1:
 Define the phrase “degrees of freedom” as used in statistics
Page 4 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

Activity 4.2: Reading from the Chi-square tables

(Hint: from the diagram, v is the degrees of freedom, which can be v  n or v  n  1 )


For n  25 and   0.05 , find:

a) 2 ,n (for one tailed test): 2 , n  0.05,25


2
 ???

b) 2 , n 1 (for one tailed test): 2 , n1  0.05,25


2
1  0.05,24  ???
2

c)  2,n (for two tailed test):  2, n   0.05


2
,25
 0.025,25
2
 ???
2 2 2

d)  2, n 1 (for two tailed test):  2, n1   0.05


2
,251
 0.025,24
2
 ???
2 2 2

Activity 4.3:
Repeat Activity 4.2 for n  16 and   0.01 , find

Therefore, testing on the population variance:

a) To test H 0 :  2   02 versus H1 :  2   02 or
H 0 :  2   02 versus H1 :  2   02 or
H 0 :  2   02 versus H1 :  2   02 , where  02 is some specified variance.
b) Under H 0 , the test statistics is:
n s2
i) 2  ~  n2 , where 2 ,n establishes the critical value (if  is known)
 02

ii)  2 
 n  1 S 2 ~  2 , where  2 establishes the critical value (if  is unknown)
n 1  , n 1
0 2

Page 5 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

Case 1: Testing on population variance, when population mean is known.


If  02 is some specified number, to test
H 0 :  2   02 versus 

 critical value   , n (upper tailed test)
2
i)
H1 :    0
2 2

H 0 :  2   02 versus 

 critical value  1 , n (lower tailed test)
2
ii)
H1 :    0
2 2

H 0 :  2   02 versus 

 critical values : C1  1 2 , n and C2   2 , n (Two tailed test)
2 2
iii)
H1 :    0
2 2

Under H 0 , the test statistics is:


 2  ns which is compared to 2 , n or 12 , n (for one tailed test) or
2 2
2 , n and
0 2
2
1 , n (for two tailed test).
2

n n n
where; ns 2    xi    = x  2  xi  n 2 and 2 , n , 12 , n ,
2 2
i
2
, n and 2
1 , n are tabulated in the chi –
2 2
i 1 i 1 i 1

square tables (  2 tables).

N/B: The Decision rule is such that we reject H 0 iff the calculated  2 value is greater than the tabulated

 2 -critical value for an upper tail and iff the calculated  2 value is less than the tabulated  2 -critical value
for a lower tail.

Case 2: Testing on population variance, when population mean is unknown.


If  02 is some specified number, to test
H 0 :  2   02 versus 

 critical value   , n 1 (upper tailed test)
2
i)
H1 :    0
2 2

H 0 :  2   02 versus 

 critical value  1 , n1 (lower tailed test)
2
ii)
H1 :    0
2 2

H 0 :  2   02 versus 

 critical values : C1  1 2 , n 1 and C2   2 , n 1 (Two tailed test)
2 2
iii)
H1 :    0
2 2

Under H 0 , the test statistics is:


Page 6 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

2  
n 1 S 2
 02
which is compared to 2 , n 1 or 12 , n1 (for one tailed test) or 2
  , n1 and
2
2
1 , n1 (for two tailed test).
2

n n
where;  n  1 s 2    xi  x  = x  nx 2 and 2 , n 1 , 12 , n1 ,
2 2 2 2
i   , n1 and 1 , n1 are tabulated in the chi–
2 2
i 1 i 1

square(  2 ) tables.

N/B: The Decision rule is as stated above.

Example 6.1:
The weight of a new package of juice is known to have a mean of 40 grams. A sample of n  7 packages
yielded the weights 37, 38, 38, 39, 40, 41 and 42 grams respectively. Assuming the weights come from a
normal population, test the hypothesis H0 :   4 against H1 :   4 where  is the standard deviation

at   0.05 level of significance.

Solution:

We wish to test H0 :   4 against H1 :   4 or equivalently

H0 :  2  16 against H1 :  2  16 .

n n
Data summary: n  7 ;   40 ;  xi  275 ;
i 1
x
i 1
2
i  10823 ; x  275
7  39.28571429 ;

49  1.665986256  ,  n 1  21  1.799470822  ;   5%  0.05 and 2  2.5%  0.025


 n2  136 2 68 2  2

n n n
ns 2    xi    =  xi2  2  xi  n 2 = 10823  2  40  275  7  40  = 23
2 2

i 1 i 1 i 1

Under H 0 , the test statistics is:  2  ns 2


 02
, since population mean,  is given.

Therefore,  2  ns 2
 02
= 23
16 = 1.4375

At   5%  0.05 and n  7 , (one tailed test to the left), we have 2


1 , n = 2
 0.95, 7 = 2.17

Therefore, at   5%  0.05 , since  2  1.4375 is less than 2


 0.95, 7  2.17 , we reject H 0 .

Page 7 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

The Decision: Variance of the package of juice is 16. (Not significant)

Example 6.2:
A particular postmaster has determined that the current procedure of separate lines yields a standard
deviation in waiting times on December mornings of  02  10 minutes per customer. She wishes to
implement the single line policy on a trial basis to see if a reduction in waiting time variability is achieved.
A sample of 30 customers was monitored and their waiting times were determined which gave a sample
standard deviation s  5 minutes. Test at   1%  0.01level.
Solution:

We wish to test H 0 :  2   02 versus H1 :  2   02 , i.e. H 0 :  2  100 versus H1 :  2  100

Under H 0 , the test statistic is  


2  n  1 S 2
~  n21 (since  is unknown)
2
0

 2 
 n  1 S 2   30  1 52  7.25
 02 102

Hence, at   1%  0.01level, and n 1  30 1  29 , a one tailed test to the left is

21 , n1  210.01,301  0.99,29


2
14.256

At   1%  0.01  2  7.25 belongs to the rejection region, thus we reject H 0

Decision: The postmaster has to adopt the new single–line system.

Exercise 6.1:
Repeat Example 6.1 while assuming that the population mean   40 was unknown.

We wish to test H0 :   4 against H1 :   4 or equivalently

H0 :  2  16 against H1 :  2  16 .

Under H 0 , the test statistics is:  2  


n 1 S 2
 02
, since population mean,  is unknown

2  
n 1 S 2
 02
 ???

At   5%  0.05 and n  7 , (one tailed test to the left), we have 2 2 2


1 , n1   0.95, 71   0.95, 6  ????

Page 8 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

Therefore, at   5%  0.05 , since  2  ???? is less/greater than 2


 0.95, 6  ?? , we reject or fail to reject H 0 .

The Decision: ????


Exercise 6.2:

 Repeat Example 6.1 and test H0 :  2  16 against H1 :  2  16 at   0.01

Exercise 6.3:

 Repeat Example 6.2 and test H 0 :  2  100 versus H1 :  2  100 at   0.05

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: Alternatively; we can use the p  value approach.

Exercise 6.4:

a) Refer to Example 6.1 and use the p  value approach to test H0 :  2  16 against H1 :  2  16 at
  0.05 , where mean  is known

 
Hint: p  value  P  2  21 , n 
b) Refer to Example 6.1 and use the p  value approach to test H0 :  2  16 against H1 :  2  16 at
  0.01 , where mean  is unknown

 
Hint: p  value  P  2  21 , n1 
c) Refer to Example 6.2 and use the p  value approach to test H 0 :  2  100 verses H1 :  2  100 at
  1%  0.01, where mean  is unknown

 
Hint: p  value  P  2  21 , n1 
Exercise 6.5:

Refer to Example 6.2 and use it to test H 0 :  2  100 versus H1 :  2  100 . (i.e. a two tailed test)

Use both traditional approach and the p  value approach

Exercise 6.6:
A manufacturer of car batteries guarantees that his batteries will last, on the average, 3 years with a standard
deviation of 1 year. If 5 of these batteries have lifetimes of 1.9, 2.4, 3.0, 3.5 and 4.2 years, is the
manufacturer still convinced of his standard deviation of 1 year? Test at (i)   0.01 and (ii)   0.05

Page 9 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

REMARK 1:

1. To test H 0 :  2   02 versus H1 :  2   02 , we compare calculated  2 with 2


1 , n  2
or 1 , n1 
2. To test H 0 :  2   02 verses H1 :  2   02 we compare calculated  2 with 2 , n or or 2 , n1  
3. To test H 0 :    verses H1 :   
2 2
0
2 2
0 we compare calculated  with
2 2
, n and 2
1 , n
2 2

or  2 2
  , n1 and 1 , n1
2 2

REMARK 2:

 
A Chi-square distribution 2 ,v table gives values up to n  30 . For n -large, (i.e. n  30 ), we use the
normal approximation to Chi-square distribution, with:

Mean = E  2 , v   v The deg rees of freedom  , and

Variance = Var  2 , v   2v Twice the deg rees of freedom 

 2  v    n  1
2

Hence, the normal variate becomes: Z   ; where v   n  1


2v 2  n  1

Exercise 6.7:
For each of the following hypotheses testing situations, state whether we reject or fail to reject H 0

a) H 0 :  2  16 versus H1 :  2  16 ; where n  25   0.05 S 2  19

b) H 0 :  2  16 versus H1 :  2  16 ; where n  25   0.05 S 2  19

c) H 0 :  2  100 versus H1 :  2  100 ; where n  10 ,   0.01 , S 2  105

d) H 0 :  2  100 versus H1 :  2  100 ; where n  10 ,   0.01 , S 2  105

e) H 0 :  2  0.64 versus H1 :  2  0.64 ; where n  19 ,   0.10 , S 2  0.59

f) H 0 :  2  0.64 versus H1 :  2  0.64 ; where n  19 ,   0.10 , S 2  0.59

g) H 0 :  2  6.1 versus H1 :  2  6.1 ; where n  17 ,   0.05 , S 2  10.1

h) H 0 :  2  6.1 versus H1 :  2  6.1; where n  17 ,   0.05 , S 2  10.1

Exercise 6.8:
For each of the following hypotheses testing situations, state whether we reject or fail to reject H 0
Page 10 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

a) H 0 :  2  100 versus H1 :  2  100 ; where n  40 ,   0.01 , S 2  105

b) H 0 :  2  100 versus H1 :  2  100 ; where n  40 ,   0.01 , S 2  105

 Hint: use normal approximation

B. TEST ON INDEPENDENCE ATTRIBUTES


It is widely applied to:
a) Data where observed frequencies occupy a single row i.e. 1 row by k columns ( 1 k contingency
table), also referred to as one – way classification or
b) Data where observed frequencies occupy h rows and k columns, i.e. h  k contingency table.

Example 6.3
A study was carried out to investigate whether there is a relationship between students’ performance in an
end of stage examination and the category of school attended. The data collected is summarized in the table
below:
GRADES TOTAL
SCHOOL CATEGORY A B C
X 18 12 20
Y 26 12 32
TOTAL

Is there any difference between the two schools’ sets of results?

Solution:
Note that this is a 2  3 contingency table, i.e. 2 rows and 3 columns.
We wish to test
H0 : grades are independent of schools versus H1 : grades are NOT independent of school

Steps:
1. Find the columns totals, row totals and overall total.

GRADES TOTAL
SCHOOL CATEGORY A B C
X 18 12 20 50
Y 26 12 32 70
TOTAL 44 24 52 120
Row total Column total
2. Find the expected frequencies (Eij) by taking: Overall total e.g.
Row1 total Column1 total
i. the expected frequency for observation 18 is E11  Overall total  50120
44
 18.33333
Row1 total Column 2 total
ii. the expected frequency for observation 12 is E12  Overall total  50120
24
 10

Page 11 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

Row1 total Column 3 total


iii. the expected frequency for observation 20 is E13  Overall total  50120
52
 21.6666
Row 2 total Column1 total
iv. the expected frequency for observation 26 is E21  Overall total  50120
52
 25.6666
Row 2 total Column 2 total
v. the expected frequency for observation 12 is E22  Overall total  50120
52
 14
Row 2total Column 3 total
vi. the expected frequency for observation 32 is E23  Overall total  50120
52
 30.3333
3. under H 0 , the test statiscs is:
n
2   
Oi  Ei 
2

Ei
, where Oi is the observed frequency / experimental values and Ei is expected
i 1
frequency / theoretical values.

Oi Ei  Oi  Ei 2
Ei

X 18 18.33333 0.006060606
12 10 0.4
20 21.6666 0.1282051282
Y 26 25.6666 0.004329004329
12 14 0.2857142857
32 30.3333 0.09157509158
TOTAL 0.9158841158

4. Find the test statistic:


n
2   
Oi  Ei 
2

Ei  0.9158841158
i 1
5. Find the number of degrees of freedom, i.e. (total number of rows minus one)  (total number of
columns minus one).
This implies that  h  1   k  1 =  2  1   3  1 = 1 2 = 2
6. Find the tabulated chi – square value.
2 , v = 0.05,
2
2  5.99

7. Take the decision:

At   5%  0.05 and v  2 , X calculated


2
 0.9158841158 is less than 2 , v = 0.05,
2
2  5.99 , hence we

fail to reject H 0 .

The Decision: There is NO statistical evidence to suggest a connection between the school and the
grades
Or
Performance and school are independent.

Page 12 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

Exercise 6.9

A sample of 200 people with a particular disease was selected. Out of these, 100 were given a drug and the
others were not given any drug. The results are as follows:

Number of people
STATUS Drug No Drug
Cured 65 55
Not cured 35 45

Test at   5% whether the drug is effective or not.

Exercise 6.10

A certain drug is said to be effective in curing cold. In an experiment on 500 people, half were given the
drug and half were cheated with sugar pills. The patients’ reactions to drugs are recorded in the table below

NUMBER OF PEOPLE TOTAL


STATUS Cured Harmed No effect
Drug 150 30 70
Sugar pills 130 40 80
TOTAL

On the basis of this information, can it be concluded that there is a significant difference in the effect of the
drug and the sugar pills? Test at   5% .

C. TEST ON GOODNESS OF FIT

Here we will consider the goodness of fit test for a normal distribution.

Example 6.4
The height in cm gained by a plant in its first year of planting is denoted by a random variable X. The value
of X is measured for a random sample of 86 plants and the results obtained are summarized in the table
below:

X <35 35-45 45-55 55-65 >65


Frequency 10 18 28 18 12

Page 13 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

a) Assuming X is modelled by a N (50,152 ) calculate the expected frequencies for each of the five

classes.

b) Carry out a goodness of fit test at   5% to test the hypothesis that X can be modelled as in (a)
above.

Solution:

a) To compute the expected frequencies, we proceed as follows:

Probabilities E  Pr obability  86

35  50 13.7
p( X  35)  p( Z  )  p(Z  1)  1  0.8413  0.1587
15
p(35  X  45)  p(1  Z  0.333)  0.8413  0.6304  0.2109 18.1

p(45  X  55)  p(0.333  Z  0.333)  2  0.6304 1  0.2608 22.4

p(55  X  65)  0.2109 (by symmetry) 18.1

p( X  65)  0.1587(by symmetry) 13.7

 E  86
b) We wish to test

H0 : X N (50,152 ) versus
H1 : X is not distributed this way

Page 14 of 15
TOPIC 6: < THE CHI-SQUARE (  2 ) TEST >

The above table now becomes

Observed freq (O) Expected freq (E) (O  E ) 2


E

10 13.7 0.999…

18 18.1 0.0005…

28 22.4 1.4….

18 18.1 0.0005…

12 13.7 0.210…

(O  E ) 2
 E =2.611

(4)
2
 9.488

Now since computed


2
 (4)
2
, we fail to reject H 0 and conclude that the model N (50,152 ) is a suitable model.

Exercise 6.11
A weaving mill sells lengths of cloth with a nominal length of 70m. A customer measured 100 lengths and
obtained the following frequency distribution.

Length (m) 61-67 67-69 69-71 71-73 73-75 75-81


Frequency 1 16 26 19 20 18

Use a  2 test at   5% to show that a normal distribution is not an adequate model for this data.

Page 15 of 15

You might also like