Lecture 43 - Test of Goodness of Fit
Download
Report
Transcript Lecture 43 - Test of Goodness of Fit
Test of Goodness of
Fit
Lecture 43
Section 14.1 – 14.3
Mon, Apr 17, 2006
Count Data
Count data – Data that counts the number of
observations that fall into each of several
categories.
The data may be univariate or bivariate.
Univariate example – Observe a student’s final
grade: A – F.
Bivariate example – Observe a student’s final
grade and year in college: A – F and freshman –
senior.
Univariate Example
Observe students’ final grades in statistics: A, B,
C, D, or F.
A
5
B
12
C
8
D
3
F
2
Bivariate Example
Observe students’ final grade in statistics and
year in college.
A
B
C
D
F
Fresh
3
6
3
2
1
Soph
1
4
4
1
0
Junior
1
2
0
0
1
Senior
0
1
1
0
0
Observed and Expected Counts
Observed counts – The counts that were
actually observed in the sample.
Expected counts – The counts that would be
expected if the null hypothesis were true.
Tests of Goodness of Fit
The goodness-of-fit test applies only to
univariate data.
The null hypothesis specifies a discrete
distribution for the population.
We want to determine whether a sample from
that population supports this hypothesis.
The Chi-Square Statistic
Denote the observed counts by O and the
expected counts by E.
Define the chi-square (2) statistic to be
2
(
O
E
)
2
E
Clearly, if the observed counts are close to the
expected counts, then 2 will be small.
But if even a few observed counts are far from
the expected counts, then 2 will be large.
Think About It
Think About It, p. 923.
Chi-Square Degrees of Freedom
The chi-square distribution has an associated
degrees of freedom, just like the t distribution.
Each chi-square distribution has a slightly
different shape, depending on the number of
degrees of freedom.
Chi-Square Degrees of Freedom
0.5
0.4
2(2)
0.3
2(5)
0.2
2(10)
0.1
5
10
15
20
Properties of 2
The chi-square distribution with df degrees of
freedom has the following properties.
2 0.
It is unimodal.
It is skewed right (not symmetric!)
2 = df.
2 = (2df).
If df is large, then 2(df) is approximately N(df, (2df)).
Chi-Square vs. Normal
0.05
0.04
N(30,60)
N(32, 8)
2(30)2
(32)
0.03
0.02
0.01
10
20
30
40
50
Chi-Square vs. Normal
0.025
0.02
N(128, 16)
2(128)
0.015
0.01
0.005
100
120
140
160
The Chi-Square Table
See page A-11.
The left column is degrees of freedom: 1, 2, 3,
…, 15, 16, 18, 20, 24, 30, 40, 60, 120.
The column headings represent areas of lower
tails:
0.005, 0.01, 0.025, 0.05, 0.10,
0.90, 0.95, 0.975, 0.99, 0.995.
Of course, the lower tails 0.90, 0.95, 0.975, 0.99,
0.995 are the same as the upper tails 0.10, 0.05,
0.025, 0.01, 0.005.
Example
If df = 10, what value of 2 cuts off an lower
tail of 0.05?
If df = 10, what value of 2 cuts off a upper tail
of 0.05?
TI-83 – Chi-Square Probabilities
To find a chi-square probability (p-value) on the
TI-83,
Press DISTR.
Select 2cdf (item #7).
Press ENTER.
Enter the lower endpoint, the upper endpoint, and
the degrees of freedom.
Press ENTER.
The probability appears.
Example
If df = 8, what is the probability that 2 will fall
between 4 and 12?
If df = 32, what is the probability that 2 will fall
between 24 and 40?
Compute 2cdf(4, 12, 8).
Compute 2cdf(24, 40, 32).
If df = 128, what is the probability that 2 will
fall between 96 and 160?
Compute 2cdf(96, 160, 128).
Tests of Goodness of Fit
The goodness-of-fit test applies only to
univariate data.
The null hypothesis specifies a discrete
distribution for the population.
We want to determine whether a sample from
that population supports this hypothesis.
Examples
If we rolled a die 60 times, we expect 10 of each
number.
If we got frequencies 8, 10, 14, 12, 9, 7, does that
indicate that the die is not fair?
If we toss a fair coin, we should get two heads
¼ of the time, two tails ¼ of the time, and one
of each ½ of the time.
Suppose we toss a coin 100 times and get two heads
16 times, two tails 36 times, and one of each 48
times. Is the coin fair?
Examples
If we selected 20 people from a group that was
60% male and 40% female, we would expect to
get 12 males and 8 females.
If we got 15 males and 5 females, would that
indicate that our selection procedure was not
random (i.e., discriminatory)?
Null Hypothesis
The null hypothesis specifies the probability (or
proportion) for each category.
Each probability is the probability that a random
observation would fall into that category.
Null Hypothesis
To test a die for fairness, the null hypothesis
would be
H0: p1 = 1/6, p2 = 1/6, …, p6 = 1/6.
The alternative hypothesis will always be a
simple negation of H0:
H1: At least one of the probabilities is not 1/6.
or more simply,
H1: H0 is false.
Expected Counts
To find the expected counts, we apply the
hypothetical (H0) probabilities to the sample
size.
For example, if the hypothetical probabilities are
1/6 and the sample size is 60, then the expected
counts are
(1/6) 60 = 10.
Example
We will use the sample data given for 60 rolls of
a die to calculate the 2 statistic.
Make a chart showing both the observed and
expected counts (in parentheses).
1
8
(10)
2
10
(10)
3
14
(10)
4
12
(10)
5
9
(10)
6
7
(10)
Example
Now calculate 2.
2
2
2
2
2
2
(
8
10
)
(
10
10
)
(
14
10
)
(
12
10
)
(
9
10
)
(
7
10
)
2
10
10
10
10
10
10
0.4 0.0 1.6 0.4 0.1 0.9
3.4
Computing the p-value
The number of degrees of freedom is 1 less
than the number of categories in the table.
In this example, df = 5.
To find the p-value, use the TI-83 to calculate
the probability that 2(5) would be at least as
large as 3.4.
p-value = 2cdf(3.4, E99, 5) = 0.6386.
Therefore, p-value = 0.6386 (accept H0).
The Effect of the Sample Size
What if the previous sample distribution
persisted in a much larger sample, say n = 6000?
Would it be significant?
1
800
(1000)
2
1000
(1000)
3
1400
(1000)
4
1200
(1000)
5
900
(1000)
6
700
(1000)
TI-83 – Goodness of Fit Test
The TI-83 will not automatically do a goodnessof-fit test.
The following procedure will compute 2.
Enter the observed counts into list L1.
Enter the expected counts into list L2.
Evaluate the expression (L1 – L2)2/L2.
Select LIST > MATH > sum and apply the sum
function to the previous result, i.e., sum(Ans).
The result is the value of 2.
The List of Expected Counts
To get the list of expected counts, you may
Store the list of hypothetical probabilities in L3.
Multiply L3 by the sample size and store in L2.
For example, if the probabilities for 4 categories
are p1 = 0.25, p2 = 0.15, p3 = 0.40, and p4 = 0.20,
and the sample size is n = 225, then
Store {0.25,0.25,0.40,0.20} in L3.
Compute L3*225 and store in L2.
Example
To test whether the coin is fair, the null
hypothesis would be
H0: pHH = 1/4, pTT = 1/4, pHT = 1/2.
The alternative hypothesis would be
H1: H0 is false.
Let = 0.05.
Expected Counts
To find the expected counts, we apply the
hypothetical probabilities to the sample size.
Expected HH = (1/4) 100 = 25.
Expected TT = (1/4) 100 = 25.
Expected HT = (1/2) 100 = 50.
Example
We will use the sample data given for 60 rolls of
a die to calculate the 2 statistic.
Make a chart showing both the observed and
expected counts (in parentheses).
HH
16
(25)
TT
36
(25)
HT
48
(50)
Example
Now calculate 2.
2
2
2
(
16
25
)
(
36
25
)
(
48
50
)
2
25
25
50
3.24 4.84 0.08
8.16
Compute the p-value
In this example, df = 2.
To find the p-value, use the TI-83 to calculate
the probability that 2(2) would be at least as
large as 8.16.
2cdf(8.16, E99, 2) = 0.0169.
Therefore, p-value = 0.0169 (reject H0).
The coin appears to be unfair.
Example
Suppose we select 20 people from a group that
is 60% male and 40% female and we get 15
males and 5 females.
Is it reasonable to believe that we selected the 20
people at random?
The Hypotheses
To test that the process was random, the null
hypothesis would be
H0: pM = 0.60, pF = 0.40.
The alternative hypothesis would be
H1: H0 is false.
Let = 0.05.
Calculate the Expected Counts
To find the expected counts, multiply the
hypothetical probabilities to the sample size.
Expected no. of males = 0.60 20 = 12.
Expected no. of females = 0.40 20 = 8.
Make the Chart
Make a chart showing both the observed and
expected counts (in parentheses).
M
15
(12)
F
5
(8)
Compute 2
Now calculate 2.
2
2
(
15
12
)
(
5
8
)
2
12
8
0.75 1.125
1.875.
Compute the p-value
In this example, df = 1.
To find the p-value, use the TI-83 to calculate
the probability that 2(1) would be at least as
large as 1.875.
2cdf(1.875, E99, 1) = 0.1709.
Therefore, p-value = 0.1709 (accept H0).
There is no evidence that the people were not
selected at random.