Statistics Parametric and Z square tests due in 48 hours
Chi Square/2013_BSTAT-Topic-7-Chi-Squared_Test-v6.docx
Business Statistics Topic 7 Chi-Squared
Business Statistics
7. Chi-Squared Goodness of Fit Tests
7.1 Introduction
The data set for a Chi-squared test is always a set of frequencies or counts. These are the observed frequencies denoted by o. The null hypothesis is a statement which, if it were true, would lead to a different set of frequencies, the expected frequencies denoted by e. The test statistic used in the chi-squared test is based on the differences between the corresponding o & e values. If the hypothesis is good all the differences will be small.
The test statistic is:
Each difference is squared and expressed as a proportion of e. If all the observed values are close to the expected values the test statistic will be small. If the hypothesis is poor (at least one large difference) the test statistic will be large. Hence for our purposes this is always a one-tailed test.
Example 1 (Worked)
The number of defective items found each day in production over a one week period, were as follows:
|
Day: |
Mon |
Tues |
Wed |
Thurs |
Fri |
|
Defectives: |
15 |
8 |
5 |
5 |
12 |
Test at the 5% level of significance the null hypothesis that the differences in the number of defectives on different days are due to chance.
H0: There IS NO significant difference in the number of defectives on each day.
H1: There is a significant difference in the number of defectives on each day.
Total number of defectives in week = 45, therefore 9 defectives expected each day.
|
Day: |
Mon |
Tues |
Wed |
Thurs |
Fri |
|
Observed, o |
15 |
8 |
5 |
5 |
12 |
|
Expected, e |
9 |
9 |
9 |
9 |
9 |
|
o – e |
6 |
-1 |
-4 |
-4 |
3 |
|
(o – e)2 |
36 |
1 |
16 |
16 |
9 |
|
(o – e)2/e |
4 |
0.1111 |
1.7778 |
1.7778 |
1 |
= 8.6667
Degrees of Freedom -> the number of independent expected values.
Degrees of Freedom, = number of e values – number of constraints on the e values.
Here (and in many examples) the only constraint is that the expected values must add up to 45 and if 4 are known then the 5th can be found by subtracting the sum of the other 4 from 45. So Degrees of Freedom, = 4.
Critical value (from χ2 table using 0.05 column) with 4 degrees of freedom =
Test Statistic = 8.6667 < Critical Value = 9.488
So: Do NOT Reject H0 at 5% level.
SPSS
You will need to put the number of Defectives in one column, Day in another using 1=Monday etc.
Use D ata- W eight Cases, weight cases by Defectives then
Use A nalyse – N onparametric tests – L egacy Dialogs- C hi square
Enter Day into Test Variable List the click OK.
Excel
The CHITEST function takes the Observed and Expected values as arguments and returns a p-value. The Expected values must first be calculated using appropriate formulae.
Alternatively the test statistic can be calculated as in the table above.
The Critical Value can be obtained using =CHISQ.INV.RT(α, ).
In the above example α,=0.05 and = 4.
The p-value can be obtained using =CHISQ.DIST.RT(Test Statistic, ).
Note: CHIINV and CHIDIST also work as above.
Example 2
A die is thrown 300 times.
H0: The die is fair
H1: The die is biased
|
Score |
1 |
2 |
3 |
4 |
5 |
6 |
|
o |
40 |
63 |
48 |
53 |
38 |
58 |
|
e |
50 |
50 |
50 |
50 |
50 |
50 |
|
o – e |
-10 |
13 |
-2 |
3 |
-12 |
8 |
|
(o – e)2 |
100 |
169 |
4 |
9 |
144 |
64 |
|
(o – e)2/e |
2 |
3.38 |
0.08 |
0.18 |
2.88 |
1.28 |
= 9.8
Degrees of freedom, = 6 – 1 = 5
Critical value = 11.070
so H0.
i.e. it is
7.2 Tests for Distributions
Example 3 (Worked)
The numbers of serious accidents each day on a section of motorway were recorded over a 250 day period:
|
No. serious accidents |
0 |
1 |
2 |
3 |
4 |
5 |
|
No. days |
100 |
70 |
45 |
20 |
10 |
5 |
Test at the 1% significance level the null hypothesis that the number of serious accidents follows a Poisson distribution.
The Poisson distribution has the following equation:
Where
k is the number of events occurring in the unit of time under consideration, in this case number of road accidents in one day. (k is a whole number)
λ is the mean value of k.
e is the constant 2.7182818….
H0: The number of serious accidents follows a Poisson distribution.
H1: The number of serious accidents does NOT follow a Poisson distribution.
Mean number of serious accidents per day, M, is (70+90+60+40+25)/250=285/250=1.14
We use M as our estimate for λ = 1.14
Using Poisson Distribution with mean 1.14:
P(0) = = 0.319819
P(1) = = 0.364594
P(2) = = 0.207818
P(3) = = 0.078971
P(4) = = 0.022507
P(5 or more) = 1-[P(0)+P(1)+ P(2)+P(3)+ P(4)]=0.00629117
Expected values are given by P(k) times number of days (250):
|
No. serious accidents |
0 |
1 |
2 |
3 |
4 |
5 or more |
|
No. days |
79.955 |
91.148 |
51.955 |
19.743 |
5.627 |
1.573 |
But:
The assumptions underlying the Chi-squared test are violated if any of the expected values are substantially less than 5.
So, the “5 or more” class must be merged with the “4” class:
|
No. serious accidents |
0 |
1 |
2 |
3 |
4 or more |
|
No. days, o |
100 |
70 |
45 |
20 |
15 |
|
Expected, e |
79.955 |
91.148 |
51.955 |
19.743 |
7.199 |
|
o – e |
20.045 |
-21.148 |
-6.955 |
0.257 |
7.801 |
|
(o – e)2 |
401.8118 |
447.2557 |
48.3665 |
0.0662 |
60.8482 |
|
(o – e)2/e |
5.02549 |
4.90689 |
0.93094 |
0.00335 |
8.45175 |
Two constraints:
1. Must add up to 250 (days)
2. Mean = 1.14
So degrees of freedom, = 5 – 2 = 3
Critical value is from table.
Test statistic = 19.318 > 11.345 = Critical value
Reject H0 at 1% level. Also we reject at levels down to 0.1%
There is strong evidence to suggest the number of serious accidents does NOT follow a Poisson distribution.
Example 4
A random sample of 100 managers were asked to rate the success of an advertising campaign on a scale from 0 to 100.
|
Score |
Number of managers (f) |
mid-point (m) |
fm |
fm2 |
|
0 < 40 |
8 |
20 |
160 |
3200 |
|
40 < 50 |
16 |
45 |
720 |
32400 |
|
50 < 60 |
13 |
55 |
715 |
39325 |
|
60 < 70 |
23 |
65 |
1495 |
97175 |
|
70 < 80 |
15 |
75 |
1125 |
84375 |
|
80 < 90 |
16 |
85 |
1360 |
115600 |
|
90 – 100 |
9 |
95 |
855 |
81225 |
|
Totals |
100 |
|
6430 |
453300 |
Mean = 64.3
Standard deviation = 20.063
Test at 5% level of significance the hypothesis that the scores are normally distributed.
H0: Scores are normally distributed
H1: Scores are NOT normally distributed
1. Calculate by how many standard deviations each class boundary differs from the mean (this gives us z values for the class boundaries).
2. For each class use the z table to determine the probability of an observation being in that class. Unlike the Poisson distribution there is no convenient formula.
3. From the probabilities calculate expected values for each class.
4. Using observed and expected values, calculate chi-squared.
Note: all expected values > 5 so proceed to table:
|
Score |
< 40 |
40 < 50 |
50 < 60 |
60 < 70 |
70 < 80 |
80 < 90 |
90+ |
|
o |
8 |
16 |
13 |
23 |
15 |
16 |
9 |
|
e |
|
|
|
|
|
|
|
|
o – e |
|
|
|
|
|
|
|
|
(o – e)2 |
|
|
|
|
|
|
|
|
(o – e)2/e |
|
|
|
|
|
|
|
=
Three constraints:
1. Expected values must add up to 100
2. The mean must be 64.3
3. The standard deviation must be 20.063
So there are 7 – 3 = 4 degrees of freedom (= ).
Critical value is
so H0. It is
7.3 Contingency Tables
A contingency table is a particular kind of chi-squared test where data items are classified according to two criteria, and the null hypothesis is that the two criteria are independent of each other.
Example 5
The following table shows the absence records of 100 employees in a company for one year classified according to method of payment.
|
|
|
Days Absent |
|
||
|
|
|
0 |
1 to 3 |
4 or more |
TOTAL |
|
Method of payment |
Hourly |
6 |
12 |
22 |
|
|
|
Weekly |
10 |
11 |
9 |
|
|
|
Monthly |
15 |
8 |
7 |
|
|
|
TOTAL |
|
|
|
|
Use a 5% level significance test to decide whether there is evidence to indicate a relationship between absences and method of payment.
Expected Value = Column Total X Row Total
Grand Total
|
Expected Values |
|
Days Absent |
|
||
|
|
|
0 |
1 to 3 |
4 or more |
TOTAL |
|
Method of payment |
Hourly |
|
|
|
|
|
|
Weekly |
|
|
|
|
|
|
Monthly |
|
|
|
|
|
|
TOTAL |
|
|
|
|
|
o |
e |
o – e |
(o – e)2 |
(o – e)2/e |
|
6 |
|
|
|
|
|
10 |
|
|
|
|
|
15 |
|
|
|
|
|
12 |
|
|
|
|
|
11 |
|
|
|
|
|
8 |
|
|
|
|
|
22 |
|
|
|
|
|
9 |
|
|
|
|
|
7 |
|
|
|
|
|
|
|
|
Total: |
|
For contingency tables, degrees of freedom = (r – 1) X (c – 1)
Where: r = number of rows and c = number of columns.
SPSS
You will need to put the Frequencies (number of employees) in one column, Method of payment in another column and category of Days absent in another.
Use D ata- W eight Cases, weight cases by Frequency then
Use A nalyse - D e scriptive Statistics – C rosstabs.
Enter the appropriate fields into Row(s), Column(s) and ‘Layer 1’.
Click Statistics
Tick the box for C h i-square
Click Continue
Click OK
Example 6
In a survey designed to test the preferences for different daily tabloid newspapers 200 men and 150 women who said they read a daily tabloid newspaper regularly gave their first preferences as follows:
|
|
Men |
Women |
TOTAL |
|
Daily Star |
46 |
37 |
|
|
Daily Mail |
30 |
26 |
|
|
Sun |
55 |
44 |
|
|
Daily Mirror |
51 |
37 |
|
|
Daily Express |
18 |
6 |
|
|
TOTAL |
|
|
|
Test at the 5% level the null hypothesis that the newspaper read is independent of gender.
|
Expected Values |
Men |
Women |
TOTAL |
|
Daily Star |
|
|
|
|
Daily Mail |
|
|
|
|
Sun |
|
|
|
|
Daily Mirror |
|
|
|
|
Daily Express |
|
|
|
|
TOTAL |
|
|
|
|
o |
e |
o – e |
(o – e)2 |
(o – e)2/e |
|
46 |
|
|
|
|
|
30 |
|
|
|
|
|
55 |
|
|
|
|
|
51 |
|
|
|
|
|
18 |
|
|
|
|
|
37 |
|
|
|
|
|
26 |
|
|
|
|
|
44 |
|
|
|
|
|
37 |
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
Total: |
|
Example 7
The table below shows the incidence of attack by cholera on 400 inoculated people and on 300 who had not been inoculated. Use a 5% significance level test to decide whether inoculation affects proneness to attack.
|
|
Inoculated |
Not inoculated |
TOTAL |
|
Attacked |
5 |
12 |
|
|
Not attacked |
395 |
288 |
|
|
TOTAL |
|
|
|
Note: As this is a 2 X 2 contingency table, use Yates’ correction:
The test statistic is now
|
Expected Values |
Inoculated |
Not inoculated |
TOTAL |
|
Attacked |
|
|
|
|
Not attacked |
|
|
|
|
TOTAL |
|
|
|
|
o |
e |
|o – e| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Total: |
|
Example 8
In an auditing exercise 150 invoices were examined for errors. 90 of the invoices were for amounts of £50 or less and the remainder for amounts greater than £50.
|
|
No errors |
At least 1 error |
TOTAL |
|
£50 or less |
70 |
20 |
|
|
Greater than £50 |
38 |
22 |
|
|
TOTAL |
|
|
|
Carry out a chi-squared test at the 5% level of significance to decide whether the presence of errors is related to invoice value.
|
Expected Values |
No errors |
At least 1 error |
TOTAL |
|
£50 or less |
|
|
|
|
Greater than £50 |
|
|
|
|
TOTAL |
|
|
|
|
o |
e |
|o – e| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Total: |
|
Exercises
1. Four different makes of machine tool were tried over a period and the breakages were 24, 18, 19, 19 respectively. Is this result consistent, at the 5% level, with the hypothesis that there is no real difference between the different makes of tool?
2. An advertiser receives 60, 112 and 68 responses respectively to the same advertisement in three different papers. Is one paper significantly better than the others as an advertising medium?
3. An engineering research laboratory buys one packet of 12 bolts from each of 100 different manufacturers. Each bolt is tested to destruction and the following distribution of failures found.
Number of failures: 0 1 2 3 4 5
Frequency: 80 12 3 3 1 1
Calculate the mean number of defectives per packet and show that if all the bolts are assumed equally likely to fail the test then the probability of failure is 0.03. After suitable regrouping of the data, test at the 5% level whether the observations agree with the appropriate binomial distribution. Comment on the result.
Equation for binomial distribution is:
Where
and
4. As part of an investigation during World War II south-east London was divided up into 576 squares of side 1 km and the number of bombs falling in each such area during a certain specified time counted. It was required to test the hypothesis that bombs were being dropped randomly (i.e according to a Poisson distribution).
|
Bombs: |
0 |
1 |
2 |
3 |
4 |
5 or more |
|
Frequency: |
229 |
211 |
93 |
35 |
8 |
0 |
Use a chi-squared test to decide whether the hypothesis of random bombing can be rejected at the 5% level of significance.
5. It is required to test whether there is an association between the income of salespersons of hotel supplies and their educational background. A random sample of 400 salespersons is chosen and the following results obtained:
|
|
No university education |
University but no degree |
Graduate |
|
< £10,000 |
63 |
78 |
29 |
|
£10,000 < £25,000 |
48 |
82 |
45 |
|
> £25,000 |
9 |
20 |
26 |
Test the hypothesis of no association at the 5% level.
6. Five 24-can boxes of tinned salmon were inspected for quality. The following results were obtained:
|
|
Brand 1 |
Brand 2 |
Brand 3 |
Brand 4 |
Brand 5 |
|
Below specification |
4 |
10 |
6 |
2 |
8 |
|
Adequate |
20 |
14 |
18 |
22 |
16 |
Use a Chi-squared contingency table to test at the 5% level of significance whether the brands can be believed to be of comparable quality.
7. A large department store operating several branches wants to determine whether there is an association between an employee’s length of service and his/her opinion of the store’s annual “back to school” sale. The table below shows the judgement of a random sample of 440 employees:
|
|
2 years or less |
3 – 5 years |
6 – 10 years |
11 or more years |
|
Sale very good |
48 |
51 |
43 |
35 |
|
Sale satisfactory |
22 |
42 |
59 |
57 |
|
Sale poor |
15 |
22 |
33 |
13 |
Test the hypothesis of no association at the 5% significance level.
8. In a ‘flu epidemic, 927 children contracted the virus. 408 of them received no treatment and of these 104 suffered after-effects. Of the remainder who did receive treatment, 166 suffered after-effects. Test at the 5% significance level the hypothesis that the after-effects are unrelated to whether treatment was received and comment on the result.
9. 300 components of a particular kind were sampled at random and the dimension, X, was measured in each case:
|
Measurement, X mm |
Number of components |
|
0 < 2 |
7 |
|
2 < 4 |
25 |
|
4 < 6 |
54 |
|
6 < 8 |
80 |
|
8 < 10 |
70 |
|
10 < 12 |
50 |
|
12 < 14 |
10 |
|
14 < 16 |
4 |
a) Show that the components have mean dimension of 7.6 mm with standard deviation 2.865 mm.
b) If the dimensions were normally distributed with mean 7.6 mm and standard deviation 2.865 mm, find how many of the 300 components could be expected to have measurements in each of the 8 classes specified above.
c) Carry out a chi-squared goodness of fit test on the null hypothesis that the measurements can be believed to come from a population of normally distributed measurements.
10. A British newspaper claimed that a person’s prospects of becoming very wealthy could be influenced by the time of year they were born.
To support this claim a breakdown was published of the dates of birth of the 1,000 richest people in England. These were shown in twelve categories ‘signs of the zodiac’ used in astrology.
Investigate the validity of the newspaper’s claim.
|
From |
To |
Number Born |
|
21 Mar |
20 Apr |
94 |
|
21 Apr |
21 May |
89 |
|
22 May |
21 Jun |
99 |
|
22 Jun |
22 Jul |
80 |
|
23 Jul |
22 Aug |
86 |
|
23 Aug |
23 Sep |
75 |
|
24 Sep |
23 Oct |
78 |
|
24 Oct |
22 Nov |
65 |
|
23 Nov |
21 Dec |
82 |
|
22 Dec |
20 Jan |
96 |
|
21 Jan |
19 Feb |
77 |
|
20 Feb |
20 Mar |
79 |
|
TOTAL: |
|
1000 |
SOURCE: Daily Mail, 8th April 2009. Available on-line at:
http://www.dailymail.co.uk/news/article-2305535/Sir-Paul-McCartney-Jamie-Oliver-Richest-people-England-study-reveals-high-concentration-Geminis.html
9
r!
r)!
(n
n!
C
r
n
-
=
r
n
r
r
n
q
p
C
P(r)
-
=
Chi Square/Exercises-Topic-7-Chi-Squared-v2.doc
Business Statistics Topic 7
Topic 7 Exercises – Chi-Squared Tests
Where datasets from Anderson (2010) Chapter 12 are mentioned these will be available on Moodle.
Use Excel or SPSS as appropriate
11. The file Lotto gives data on draws in the National Lottery for a 14 year period.
Column A shows draw number
Columns B-E shows the day of week and date
Columns F-K shows the six numbers drawn in order
Column L shows the machine used
Column M shows the set of balls.
Using appropriate Hypothesis Tests:
Assess whether there is evidence that some numbers are more or less likely to be drawn than others. Consider the 1st number drawn, the 2nd, the 3rd, the 4th, the 5th and 6th number drawn as well as all numbers irrespective of order.
Assess whether there is evidence of any dependence between numbers drawn and day of the week.
Assess whether there is evidence of any dependence between numbers drawn and machine used.
Assess whether there is evidence of any dependence between numbers drawn and the set of balls used.
12. The file Webpages gives the results of a survey to assess students’ views about a University’s web site.
Column A shows gender of respondent
Columns B shows level of study (Undergraduate or Postgraduate)
Columns C-F shows whether they Agree or Disagree with the statements:
“Website is attractive to potential students”
“Website is easy to navigate”
“Website is up to date”
“I would refer the website to prospective students”
Using appropriate Hypothesis Tests:
For each of the four items C-F, test for the independence of the response and gender.
For each of the four items C-F, test for the independence of the response and level of study.
State an overall conclusion about the consistency of response for students of both genders and both levels of study.
13. The file Pharmaco shows employee aptitude scores for 50 randomly chosen job applicants. Using an appropriate chi-squared test (see example 4 in the notes) test the hypothesis that the population has a normal distribution.
Compare the result obtained with an alternative test for normality (the Shapiro-Wilk test) in SPSS:
Use A nalyze-D e scriptive Statistics- E xplore
Move Score to Dependent List
Click Plots
Tick Normality tests with plots
Click Continue, Click OK.
The p-value is shown in the Tests or Normality output table under Shapiro-Wilk as Sig.
Note: Initially it may be useful to create a histogram of the data.
In SPSS use G raphs- C hart Builder and select histogram from the gallery tab.
In Excel explore the Histogram option in Data Analysis.
14. The SPSS file RealAle shows the results of a survey of beer drinkers categorized by the person’s gender and their favourite beer out of a choice of three.
(a) Using SPSS test the hypothesis that beer preference is independent of gender.
(b) Compare your result with the worked example in the Excel file Independence.
(c) Consider anything unusual about the data in the table of observed values, and investigate how it might influence the conclusion.
15. A survey of one thousand households with children is carried out. It includes questions on the number of children and whether at least one adult is working. The following results are obtained:
|
|
Number of Children |
||||
|
Work Status |
1 |
2 |
3 |
4 |
5 or more |
|
Non-working |
68 |
42 |
19 |
7 |
4 |
|
Working |
403 |
330 |
96 |
23 |
8 |
(a) Carry out a chi-squared test at an appropriate level of significance to determine whether the number of children in a family is independent of the family’s work status.
(b) Critically discuss the validity of the above test.
(c) Carry out an alternative parametric test on the null hypothesis that the mean number of children is the same for working and non-working households. Compare the result with that obtained in part (a) and discuss any differences. State any assumptions you make.
16. A survey of voters is carried out on the peace process in the two regions of a divided country. The results are shown on the table below.
|
|
Region |
|
|
|
North |
South |
|
Approve |
16 |
45 |
|
Disapprove |
10 |
9 |
(a) Carry out a chi-squared test at the 5% level of significance to determine whether voter’s region is independent of their attitude to the peace process. Carry out the test twice: (i) with and (ii) without Yates’ Correction.
(b) Carry out an alternative parametric test on the null hypothesis that the proportion of voters approving the peace process is the same in the two regions.
(c) Carry out an alternative parametric test on the null hypothesis that the proportion of voters in the North is the same regardless of their attitude to the peace process.
(d) Critically compare your conclusions for (a), (b) and (c).
(e) Using the above example and your own investigations, discuss the appropriate use of Yates’ Correction and the problem of using a Chi-squared test with small tables and small sample sizes.
Reference
Anderson D R, Sweeney D J, Williams T A, Freeman J & Shoesmith E, Statistics for Business and Economics, 2nd Edition, Cengage Learning EMEA 2010
1