Chi STST Chi STST Chi-Square Tests Square Tests Chi

Chapte
er
15
Chi--Square
Chi
S
Tests
T
Chi-Square
ChiS
T
Testt for
f Independence
I d
d
Chi--Square Tests for Goodness
Chi
Goodness--of
of--Fit
Uniform Goodness
Goodness--of
of--Fit Test
Poisson Goodness
Goodness--of
of--Fit Test
Normal ChiChi-Square Goodness
Goodness--of
of--Fit Test
ECDF Tests (Optional)
Chi--Square Test for Independence
Chi
” Contingency Tables
•
•
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
” Contingency Tables
A contingency table is a cross
cross--tabulation of n
paired observations into categories
categories.
Each cell shows the count of observations that
fall into the
category
defined by its
row (r
(r) and
column (c
(c)
h di
heading.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
McGraw-Hill/Irwin
For example:
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Chi
Chi--Square Test
•
•
•
•
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
” Chi
Chi--Square Distribution
In a test of independence for an r x c contingency
table the hypotheses are
table,
H0: Variable A is independent of variable B
H1: Variable A is not independent
p
of variable B
Use the chi
chi--square test for independence to test
these hypotheses.
This non
non--parametric test is based on frequencies
frequencies..
The n data pairs are classified into c columns
and r rows and then the observed frequency fjk is
compared with the expected frequency ejk.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
•
•
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
” Chi
Chi--Square Distribution
•
McGraw-Hill/Irwin
The critical value comes from the chi
chi--square
probability distribution with ν degrees of freedom
freedom.
ν = degrees of freedom = (r
(r – 1)(c
)(c – 1)
where r = number of rows in the table
c = number of columns in the table
Appendix
pp
E contains critical values for rightright
g -tail
areas of the chi
chi--square distribution.
The mean of a chi
chi--square distribution is ν with
variance 2ν.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Expected Frequencies
Consider the shape of the chi
chi--square distribution:
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
McGraw-Hill/Irwin
Assuming that H0 is true, the expected frequency
of row j and column k is:
ejk = RjCk/n
where Rj = total for row j (j = 1, 2, …, r)
Ck = total for column k (k = 1, 2, …, c)
n = sample
p size
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Expected Frequencies
•
” Steps in Testing the Hypotheses
The table of expected frequencies is:
•
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
•
Step 1: State the Hypotheses
H0: Variable A is independent of variable B
H1: Variable A is not independent of variable B
•
Step 2: State the Decision Rule
)(c
c – 1)
Calculate ν = ((rr – 1)(
For a given α, look up the right
right--tail critical value
(χ2R) from Appendix E or by using Excel.
Reject H0 if χ2R > test statistic.
The ejk always sum to the same row and column
frequencies as the observed frequencies.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
” Steps in Testing the Hypotheses
•
McGraw-Hill/Irwin
For example, for ν = 6 and α = .05
.05,, χ2.05 = 12
12..59
59..
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Steps in Testing the Hypotheses
•
McGraw-Hill/Irwin
Here is the rejection region.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Steps in Testing the Hypotheses
•
Chi--Square Test for Independence
Chi
” Steps in Testing the Hypotheses
Step 3: Calculate the Expected Frequencies
ejk = RjCk/n
For example,
•
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
•
•
•
McGraw-Hill/Irwin
The chi
chi--square test is unreliable if the expected
frequencies are too small.
Rules of thumb:
• Cochran’s Rule requires that ejk > 5 for all cells.
• Up to 20
20%
% of the cells ma
may ha
have
e ejk < 5
Most agree that a chi
chi--square test is infeasible if
ejk < 1 in any cell.
cell
If this happens, try combining adjacent rows or
columns to enlarge the expected frequencies.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Step 4: Calculate the Test Statistic
q
test statistic is
The chi
chi--square
•
Step 5: Make the Decision
Reject H0 if χ2R > test statistic or if the
p-value < α.
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
” Small Expected Frequencies
•
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Small Expected Frequencies
•
For example,
here are
some test
t t
results from
MegaStat
g
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” Test of Two Proportions
•
” Cross
Cross--Tabulating Raw Data
For a 2 x 2 contingency table, the chi
chi--square test
is equivalent to a twotwo-tailed z test for two
proportions,
ti
if th
the samples
l are llarge enough
h tto
ensure normality.
The hypotheses are:
H0: π1 = π2
H1: π1 ≠ π2
The z test statistic is:
•
•
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Independence
Chi
” 3-Way Tables and Higher
•
•
•
•
McGraw-Hill/Irwin
Chi--Square Test for Independence
Chi
•
Chi-square tests for independence can also be
Chiused to analyze quantitative variables by coding
th
them
into
i t categories.
t
i
For example, the
variables
ariables Infant
Deaths per 1,000
and Doctors per
100,,000 can each
100
h
be coded into
various categories:
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
” Purpose of the Test
More than two variables can be compared using
contingency tables.
However, it is difficult to visualize a higher order
table.
For example,
example you could visualize a cube as a
stack of tiled 2-way contingency tables.
Major computer packages permit 3-way tables.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
•
McGraw-Hill/Irwin
The goodness
goodness--of
of--fit (GOF
GOF)) test helps you decide
whether your sample resembles a particular kind
of population.
The chichi-square test will be used because it is
versatile and easy to understand.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
” Test Statistic and Degrees of Freedom for GOF
” Hypotheses for GOF
•
•
McGraw-Hill/Irwin
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
The hypotheses are:
H0: The population follows a _____ distribution
H1: The population does not follow a ______
distribution
The blank may contain the name of any
theoretical distribution ((e.g.,
g , uniform,, Poisson,,
normal).
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
Assuming n observations, the observations are
grouped into c classes and then the chi
chi--square
test statistic is found using:
where
McGraw-Hill/Irwin
fj = the observed frequency of
observations in class j
ej = the expected frequency in class j if
H0 were true
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
” Test Statistic and Degrees of Freedom for GOF
” Test Statistic and Degrees of Freedom for GOF
•
•
McGraw-Hill/Irwin
If the proposed distribution gives a good fit to the
sample the test statistic will be near zero
sample,
zero.
The test statistic follows the chichi-square
distribution with degrees of freedom
ν=c–m–1
where
c is the no. of classes used in the test
m is the no. of parameters estimated
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
” Data
Data--Generating Situations
•
” Eyeball Tests
Instead of “fishing” for a goodgood-fitting model,
visualize a priori the characteristics of the
underlying data
data--generating process.
process.
” Mixtures:
Mi t
A Problem
P bl
•
•
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
” Multinomial Distribution
•
McGraw-Hill/Irwin
Goodness-of
Goodnessof--fit tests may lack power in small
samples. As a guideline, a chichi-square goodness
goodness-of--fit test should be avoided if n < 25
of
25..
McGraw-Hill/Irwin
Uniform Goodness
Goodness--of
of--Fit Test
•
A simple “eyeball” inspection of the histogram or
dot plot may suffice to rule out a hypothesized
population.
” Small
S ll Expected
E
t d Frequencies
F
i
Mixtures occur when more than one datadatagenerating process is superimposed on top of
one another.
McGraw-Hill/Irwin
Chi--Square Test for Goodness
Chi
Goodness--of
of--Fit
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Uniform Goodness
Goodness--of
of--Fit Test
” Multinomial Distribution
A multinomial distribution is defined by any k
probabilities π1, π2, …,, πk that sum to unity.
p
y
For example, consider the following “official”
proportions of M&M colors.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
The hypotheses are
H0: π1 = ..30
30, π2 = ..20
30,
20, π3 = ..10
20,
10, π4 = ..10
10,
10, π5 = ..10
10,
10, π6 = ..20
10,
20
H1: At least one of the πj differs from the hypothesized
value
•
McGraw-Hill/Irwin
No parameters are estimated (m
(m = 0) and there
are c = 6 classes, so the degrees of freedom are
ν=c–m–1=6–0-1
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Uniform Goodness
Goodness--of
of--Fit Test
” Uniform Distribution
•
•
•
” Uniform GOF Test: Grouped Data
The uniform goodness
goodness--of
of--fit test is a special case
of the multinomial in which every
y value has the
same chance of occurrence.
The chi
chi--square test for a uniform distribution
compares all c groups simultaneously.
The hypotheses are:
H0: π1 = π2 = …, πc = 1/c
H1: Not all πj are equal
McGraw-Hill/Irwin
Uniform Goodness
Goodness--of
of--Fit Test
•
•
•
•
•
•
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
McGraw-Hill/Irwin
Uniform Goodness
Goodness--of
of--Fit Test
” Uniform GOF Test: Raw Data
•
•
•
•
•
•
McGraw-Hill/Irwin
First form c bins of equal width and create a
frequency
q
y distribution.
Calculate the observed frequency fj for each bin.
Define
e e ej = n/c.
/c
Perform the chi
chi--square calculations.
The degrees of freedom are ν = c – 1 since there
are no parameters for the uniform distribution.
Obtain the critical value from Appendix
pp
E for a
given significance level α and make the decision.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
The test can be performed on data that are
y tabulated into groups.
g p
already
Calculate the expected frequency eij for each cell.
The
e deg
degrees
ees o
of freedom
eedo a
are
eν=c–1s
since
ce there
ee
are no parameters for the uniform distribution.
pp
E for
Obtain the critical value χ2α from Appendix
the desired level of significance α.
The p-value can be obtained from Excel.
Reject H0 if p-value < α.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Uniform Goodness
Goodness--of
of--Fit Test
” Uniform GOF Test: Raw Data
•
Maximize the test’s power by defining bin width
as
•
As a result, the expected frequencies will be as
large
g as p
possible.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Uniform Goodness
Goodness--of
of--Fit Test
” Uniform GOF Test: Raw Data
•
•
•
McGraw-Hill/Irwin
Calculate the mean and standard deviation of the
uniform distribution as:
μ = (a + b)/2
b)/2
σ=
[(b – a + 1)2 – 1)/12
)/12
If the
e da
data
aa
are
e not
o sskewed
e ed a
and
d the
e sa
sample
p e ssize
e is
s
large (n
(n > 30
30),
), then the mean is approximately
normally distributed.
So, test the hypothesized uniform mean using
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Poisson Goodness
Goodness--of
of--Fit Test
” Poisson Data
Data--Generating Situations
•
•
•
•
McGraw-Hill/Irwin
Poisson Goodness
Goodness--of
of--Fit Test
” Poisson Goodness
Goodness--of
of--Fit Test
•
•
McGraw-Hill/Irwin
The mean λ is the only parameter.
Assuming that λ is unknown and must be
estimated from the sample, the steps are:
Step
p 1: Tally
y the observed frequency
q
y fj of each
X-value.
Step
p 2: Estimate the mean λ from the sample.
p
Step 3: Use the estimated λ to find the Poisson
probability P(X) for each value of X.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
In a Poisson distribution model, X represents the
per unit of time or space.
p
number of events p
X is a discrete nonnegative integer (X
(X = 0, 1,
2, …)
Event arrivals must be independent of each
other.
Sometimes called a model of rare events
because X typically has a small mean.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Poisson Goodness
Goodness--of
of--Fit Test
” Poisson Goodness
Goodness--of
of--Fit Test
Step 4: Multiply P(X) by the sample size n to get
expected
p
Poisson frequencies
q
ej.
Step 5: Perform the chi
chi--square calculations.
Step
S
ep 6: Make
a e the
e dec
decision.
so
•
McGraw-Hill/Irwin
You may need to combine classes until expected
frequencies become large enough for the test (at
least until ej > 2).
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Poisson Goodness
Goodness--of
of--Fit Test
” Poisson GOF Test: Tabulated Data
•
Calculate the sample mean as:
Poisson Goodness
Goodness--of
of--Fit Test
” Poisson GOF Test: Tabulated Data
•
c
^λ =
•
McGraw-Hill/Irwin
Σ xj fj
j =1
n
•
Using this estimate mean, calculate the Poisson
probabilities either by using the Poisson formula
P(x) = (λ
(λxe-λ)/
)/xx! or Excel.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
McGraw-Hill/Irwin
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Normal Data Generating Situations
•
•
•
McGraw-Hill/Irwin
Two parameters, μ and σ, fully describe the
normal distribution.
Unless μ and σ are know a priori
priori,, they must be
estimated from a sample by using x and s.
Using these statistics, the chi
chi--square goodnessgoodnessof--fit test can be used.
of
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
For c classes with m = 1 parameter estimated,
g
of freedom are
the degrees
ν=c–m–1
Obtain the critical value for a given α from
Appendix E.
Make the decision.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 1: Standardizing the Data
•
Transform the sample observations x1, x2, …, xn
into standardized values
values.
•
Count the sample observations fj within intervals
of the form x + ks and compare them with the
known frequencies ej based on the normal
distribution.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 1: Standardizing the Data
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 2: Equal Bin Widths
•
Advantage is a
standardized
t d di d scale.
l
Disadvantage is
that data are no
longer
g in the
original units.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
McGraw-Hill/Irwin
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 2: Equal Bin Widths
•
McGraw-Hill/Irwin
Step 3: Find the normal area within each bin
assuming a normal distribution.
distribution
Step 4: Find expected frequencies ej by
multiplying each normal area by the
sample size n.
Classes may need to be collapsed from the ends
inward to enlarge expected frequencies.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
To obtain equal
equal--width bins, divide the exact data
range into c groups of equal width.
width
Step 1: Count the sample observations in each
bin to get observed frequencies fj.
Step 2: Convert the bin limits into standardized
z-values by using the formula.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 3: Equal Expected Frequencies
•
•
•
•
McGraw-Hill/Irwin
Define histogram bins in such a way that an
equal number of observations would be expected
within each bin under the null hypothesis.
Define bin limits so that ej = n/c
A normal area of 1/c in each of the c bins is
desired.
The first and last classes must be openopen-ended for
a normal distribution,, so to define c bins,, we
need c – 1 cutpoints.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 3: Equal Expected Frequencies
•
•
•
The upper limit of bin j can be found directly by
using Excel
Excel.
Alternatively, find zj for bin j using Excel and then
calculate the upper limit for bin j as x + zjs
Once the bins are defined, count the
observations fj within each bin and compare them
with the expected frequencies ej = n/c.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Method 3: Equal Expected Frequencies
•
McGraw-Hill/Irwin
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Histograms
•
•
•
McGraw-Hill/Irwin
Standard normal cutpoints for equal area bins.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Normal ChiChi-Square
G d
GoodnessGoodness
-of
off-Fit
Fi T
Test
” Critical Values for Normal GOF Test
The fitted normal histogram gives visual clues as
to the likely outcome of the GOF test.
Histograms reveal any outliers or other nonnonnormality issues.
F th tests
Further
t t are needed
d d since
i
hi
histograms
t
vary.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
•
Since two parameters, m and s, are estimated
from the sample, the degrees of freedom are
ν=c–m–1
•
At least 4 bins are needed to ensure 1 df.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
ECDF Tests
ECDF Tests
” Kolmogorov
Kolmogorov--Smirnov and Lilliefors Tests
•
•
•
There are many alternatives to the chi
chi--square
test based on the Empirical Cumulative
Distribution Function (ECDF
ECDF).
).
The Kolmogorov
Kolmogorov--Smirnov (K
(K--S) test statistic D is
th largest
the
l
t absolute
b l t difference
diff
b
between
t
th
the
actual and expected cumulative relative
frequency of the n data values:
D = Max |F
|Fa – Fe|
The K
K--S test is not recommended for g
grouped
p
data.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
” Kolmogorov
Kolmogorov--Smirnov and Lilliefors Tests
•
•
•
•
•
Fa is the actual cumulative frequency at
observation i.
Fe is the expected cumulative frequency at
observation i under the assumption that the data
came from
f
the
th hypothesized
h
th i d di
distribution.
t ib ti
The K
K--S test assumes that no parameters are
estimated.
estimated
If parameters are estimated, use a Lilliefors test.
test.
Both of these tests are done by
y computer.
p
McGraw-Hill/Irwin
ECDF Tests
ECDF Tests
” Kolmogorov
Kolmogorov--Smirnov and Lilliefors Tests
” Kolmogorov
Kolmogorov--Smirnov and Lilliefors Tests
K-S test for
normality.
K-S test for
uniformity.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
ECDF Tests
ECDF Tests
” Anderson
Anderson--Darling Tests
•
•
•
•
McGraw-Hill/Irwin
” Anderson
Anderson--Darling Tests with MINITAB
The Anderson
Anderson--Darling (A
(A--D) test is widely used
for nonnon-normality because of its power.
The A
A--D test is based on a probability plot.
plot.
When the data fit the hypothesized distribution
closely,
l
l th
the probability
b bilit plot
l t will
ill b
be close
l
tto a
straight line.
The AA-D test statistic measures the overall
distance between the actual and the
hypothesized
yp
distributions, using
g a weighted
g
squared distance.
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.
Applied Statistics in
Business and Economics
End of Chapter 15
McGraw-Hill/Irwin
© 2007 The McGraw-Hill Companies, Inc. All rights reserved.