Chapter12

50
1 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc. Chapter 12 The Analysis of Categorical Data and Goodness-of-Fit Tests

description

 

Transcript of Chapter12

Page 1: Chapter12

1 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Chapter 12

The Analysis of Categorical Data and

Goodness-of-Fit Tests

Page 2: Chapter12

2 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Univariate Categorical Data

Univariate categorical data is best summarized in a one-way frequency table. For example, consider the following observations of sample of faculty status for faculty in a large university system.

Full Professor

Associate Professor

Assistant Professor Instructor

Adjunct/Part time

Frequency 22 31 25 35 41

Category

Page 3: Chapter12

3 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Univariate Categorical Data

A local newsperson might be interested in testing hypotheses about the proportion of the population that fall in each of the categories.

For example, the newsperson might want to test to see if the five categories occur with equal frequency throughout the whole university system.

To deal with this type of question we need to establish some notation.

Page 4: Chapter12

4 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Notation

k = number of categories of a categorical variable

1 = true proportion for category 1

2 = true proportion for category 2

k = true proportion for category k

(note: 1 + 2 + + k = 1)

Page 5: Chapter12

5 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Hypotheses

H0: 1 = hypothesized proportion for category 1

2 = hypothesized proportion for category 2

k = hypothesized proportion for category k

Ha: H0 is not true, so at least one of the true category proportions differs from the corresponding hypothesized value.

Page 6: Chapter12

6 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Expected Counts

For each category, the expected count for that category is the product of the total number of observations with the hypothesized proportion for that category.

Page 7: Chapter12

7 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Expected Counts - Example

Consider the sample of faculty from a large university system and recall that the newsperson wanted to test to see if each of the groups occurred with equal frequency.

Full Professor

Associate Professor

Assistant Professor

InstructorAdjunct/Part time Total

Frequency 22 31 25 35 41 154Hypothesized

Proportion0.2 0.2 0.2 0.2 0.2 1

Expected Count

30.8 30.8 30.8 30.8 30.8 154

Category

Page 8: Chapter12

8 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Goodness-of-fit statistic, 2

The value of the 2 statistic is the sum of these terms.

The goodness-of-fit statistic, 2, results from first computing the quantity

for each cell.

2(observed cell count - expected cell count)expected cell count

22 (observed cell count - expected cell count)expected cell count

Page 9: Chapter12

9 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Chi-square distributions

Chi-square Distributions

0 5 10 15 20 25x

df = 1

df = 2

df = 3

df = 4

df = 5

df = 8

df = 10

df = 15

Page 10: Chapter12

10 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Upper-tail Areas for Chi-square Distributions

Right-tail area df = 1 df = 2 df = 3 df = 4 df = 5 > .100 < 2.70 < 4.60 < 6.25 < 7.77 < 9.230.100 2.70 4.60 6.25 7.77 9.230.095 2.78 4.70 6.36 7.90 9.370.090 2.87 4.81 6.49 8.04 9.520.085 2.96 4.93 6.62 8.18 9.670.080 3.06 5.05 6.75 8.33 9.830.075 3.17 5.18 6.90 8.49 10.000.070 3.28 5.31 7.06 8.66 10.190.065 3.40 5.46 7.22 8.84 10.380.060 3.53 5.62 7.40 9.04 10.590.055 3.68 5.80 7.60 9.25 10.820.050 3.84 5.99 7.81 9.48 11.070.045 4.01 6.20 8.04 9.74 11.340.040 4.21 6.43 8.31 10.02 11.640.035 4.44 6.70 8.60 10.34 11.980.030 4.70 7.01 8.94 10.71 12.370.025 5.02 7.37 9.34 11.14 12.830.020 5.41 7.82 9.83 11.66 13.380.015 5.91 8.39 10.46 12.33 14.090.010 6.63 9.21 11.34 13.27 15.080.005 7.87 10.59 12.83 14.86 16.740.001 10.82 13.81 16.26 18.46 20.51

< .001 > 10.82 > 13.81 > 16.26 > 18.46 > 20.51

Right-tail area df = 6 df = 7 df = 8 df = 9 df = 10 > .100 < 10.64 < 12.01 < 13.36 < 14.68 < 15.980.100 10.64 12.01 13.36 14.68 15.980.095 10.79 12.17 13.52 14.85 16.160.090 10.94 12.33 13.69 15.03 16.350.085 11.11 12.50 13.87 15.22 16.540.080 11.28 12.69 14.06 15.42 16.750.075 11.46 12.88 14.26 15.63 16.970.070 11.65 13.08 14.48 15.85 17.200.065 11.86 13.30 14.71 16.09 17.440.060 12.08 13.53 14.95 16.34 17.710.055 12.32 13.79 15.22 16.62 17.990.050 12.59 14.06 15.50 16.91 18.300.045 12.87 14.36 15.82 17.24 18.640.040 13.19 14.70 16.17 17.60 19.020.035 13.55 15.07 16.56 18.01 19.440.030 13.96 15.50 17.01 18.47 19.920.025 14.44 16.01 17.53 19.02 20.480.020 15.03 16.62 18.16 19.67 21.160.015 15.77 17.39 18.97 20.51 22.020.010 16.81 18.47 20.09 21.66 23.200.005 18.54 20.27 21.95 23.58 25.180.001 22.45 24.32 26.12 27.87 29.58

< .001 > 22.45 > 24.32 > 26.12 > 27.87 > 29.58

Page 11: Chapter12

11 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Goodness-of-Fit Test Procedure

Hypotheses:

H0: 1 = hypothesized proportion for category 1

2 = hypothesized proportion for category 2

k = hypothesized proportion for category k

Ha: H0 is not true

Test statistic:22 (observed cell count - expected cell count)

expected cell count

Page 12: Chapter12

12 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Goodness-of-Fit Test Procedure

P-values: When H0 is true and all expected counts are at least 5, 2 has approximately a chi-square distribution with df = k-1.

Therefore, the P-value associated with the computed test statistic value is the area to the right of 2 under the df = k-1 chi-square curve.

Page 13: Chapter12

13 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Goodness-of-Fit Test Procedure

Assumptions:

1. Observed cell counts are based on a random sample.

2. The sample size is large. The sample size is large enough for the chi-squared test to be appropriate as long as every expected count is at least 5.

Page 14: Chapter12

14 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Consider the newsperson’s desire to determine if the faculty of a large university system were equally distributed. Let us test this hypothesis at a significance level of 0.05.

Let 1, 2, 3, 4, and 5 denote the proportions of all faculty in this university system that are full professors, associate professors, assistant professors, instructors and adjunct/part time respectively.

H0: 1 = 0.2, 2 = 0.2, 3 = 0.2, 4= 0.2, 5 = 0.2

Ha: H0 is not true

Page 15: Chapter12

15 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

ExampleSignificance level: = 0.05

Assumptions: As we saw in an earlier slide, the expected counts were all 30.8 which is greater than 5. Although we do not know for sure how the sample was obtained for the purposes of this example, we shall assume selection procedure generated a random sample.

Test statistic:22 (observed cell count - expected cell count)

expected cell count

Page 16: Chapter12

16 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Full Professor

Associate Professor

Assistant Professor

InstructorAdjunct/Part time Total

Frequency 22 31 25 35 41 154Hypothesized

Proportion0.2 0.2 0.2 0.2 0.2 1

Expected Count

30.8 30.8 30.8 30.8 30.8 154

Category

Calculation:recall

2 2 2 2 2

2 22 30.8 31 30.8 25 30.8 35 30.8 41 30.8

30.8 30.8 30.8 30.8 30.82.514 0.001 1.092 0.573 3.378

7.56

Page 17: Chapter12

17 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

ExampleP-value:

The P-value is based on a chi-squared distribution with df = 5 - 1 = 4. The computed value of 2, 7.56 is smaller than 7.77, the lowest value of 2 in the table for df = 4, so that the P-value is greater than 0.100.

Conclusion:

Since the P-value > 0.05 = , H0 cannot be rejected. There is insufficient evidence to refute the claim that the proportion of faculty in each of the different categories is the same.

Page 18: Chapter12

18 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Tests for Homogeneity and Independence in a Two-Way Table

Data resulting from observations made on two different categorical variables can be summarized using a tabular format. For example, consider the student data set giving information on 79 student dataset that was obtained from a sample of 79 students taking elementary statistics. The table is on the next slide.

Page 19: Chapter12

19 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Tests for Homogeneity and Independence in a Two-Way Table

Contacts Glasses NoneFemale 5 9 11Male 5 22 27

This is an example of a two-way frequency table, or contingency table.

The numbers in the 6 cells with clear backgrounds are the observed cell counts.

Page 20: Chapter12

20 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Tests for Homogeneity and Independence in a Two-Way Table

Contacts Glasses NoneRow Marginal

Total

Female 5 9 11 25Male 5 22 27 54

Column Marginal Total

10 31 38 79

Marginal totals are obtained by adding the observed cell counts in each row and also in each column.

The sum of the column marginal total (or the row marginal totals) is called the grand total.

Page 21: Chapter12

21 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Tests for Homogeneity in a Two-Way Table

Typically, with a two-way table used to test homogeneity, the rows indicate different populations and the columns indicate different categories or vice versa.

For a test of homogeneity, the central question is whether the category proportions are the same for all of the populations

Page 22: Chapter12

22 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Tests for Homogeneity in a Two-Way Table

When the row indicates the population, the expected count for a cell is simply the overall proportion (over all populations) that have the category times the number in the population. To illustrate: Contacts Glasses None

Row Marginal Total

Female 5 9 11 25Male 5 22 27 54

Column Marginal Total

10 31 38 79

54 = total number of male students

= overall proportion of students using contacts10

79

= expected number of males that use contacts as primary vision correction

1054 6.83

79

Page 23: Chapter12

23 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Tests for Homogeneity in a Two-Way Table

The expected values for each cell represent what would be expected if there is no difference between the groups under study can be found easily by using the following formula.

(Row total)(Column total)Expected cell count =

Grand total

Page 24: Chapter12

24 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Contacts Glasses None

Row Marginal

Total

5 9 11

5 22 27

Column Marginal

Total10 31 38 79

Female

Male

25

54

25 10

79

25 31

79

25 38

79

54 10

79

54 31

79

54 38

79

Tests for Homogeneity in a Two-Way Table

Page 25: Chapter12

25 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Contacts Glasses None

Row Marginal

Total

5 9 11(3.16) (9.81) (12.03)

5 22 27(6.84) (21.19) (25.97)

Column Marginal

Total10 31 38 79

Female25

Male54

Tests for Homogeneity in a Two-Way Table

Expected counts are in parentheses.

Page 26: Chapter12

26 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Comparing Two or More Populations Using the 2 Statistic

Hypotheses:

H0: The true category proportions are the same for all of the populations (homogeneity of populations).

Ha: The true category proportions are not all the same for all of the populations.

Page 27: Chapter12

27 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Comparing Two or More Populations Using the 2 Statistic

The expected cell counts are estimated from the sample data (assuming that H0 is true) using the formula

(Row total)(Column total)Expected cell count =

Grand total

Test statistic:22 (observed cell count - expected cell count)

expected cell count

Page 28: Chapter12

28 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Comparing Two or More Populations Using the 2 Statistic

P-value:When H0 is true, 2 has approximately a chi-square distribution with

The P-value associated with the computed test statistic value is the area to the right of 2 under the chi-square curve with the appropriate df.

df = (number of rows - 1)(number of columns - 1)

Page 29: Chapter12

29 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Comparing Two or More Populations Using the 2 Statistic

Assumptions:

1. The data consists of independently chosen random samples.

2. The sample size is large: all expected counts are at least 5. If some expected counts are less than 5, rows or columns of the table may be combined to achieve a table with satisfactory expected counts.

Page 30: Chapter12

30 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

The following data come from a clinical trial of a drug regime used in treating a type of cancer, lymphocytic lymphomas.* Patients (273) were randomly divided into two groups, with one group of patients receiving cytoxan plus prednisone (CP) and the other receiving BCNU plus prednisone (BP). The responses to treatment were graded on a qualitative scale. The two-way table summary of the results is on the following slide.

* Ezdinli, E., S., Berard, C. W., et al. (1976) Comparison of intensive versus moderate chemotherapy of lympocytic lymphomas: a progress report. Cancer, 38, 1060-1068.

Page 31: Chapter12

31 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Set up and perform an appropriate hypothesis test at the 0.05 level of significance.

Complete Response

Partial Response

No Change Progression

Row Marginal

Total

26 51 21 4031 59 11 34

Column Marginal

Total57 110 32 74 273

BPCP

138135

Page 32: Chapter12

32 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Hypotheses:

H0: The true response to treatment proportions are the same for both treatments (homogeneity of populations).

Ha: The true response to treatment proportions are not all the same for both treatments.

Example

Significance level: = 0.05

Test statistic:22 (observed cell count - expected cell count)

expected cell count

Page 33: Chapter12

33 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Assumptions:

All expected cell counts are at least 5, and samples were chosen independently so the 2 test is appropriate.

Complete Response

Partial Response

No Change Progression

Row Marginal

Total

26 51 21 40(28.81) (55.60) (16.18) (37.41)

31 59 11 34(28.19) (54.40) (15.82) (36.59)

Column Marginal

Total57 110 32 74 273

Female138

Male135

Page 34: Chapter12

34 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

ExampleCalculations:

The two-way table for this example has 2 rows and 4 columns, so the appropriate df is (2-1)(4-1) = 3. Since 4.60 < 6.25, the P-value > 0.10 > = 0.05 so H0 is not rejected. There is insufficient evidence to conclude that the responses are different for the two treatments.

2 2 2

2

2 2

2 2 2

26 28.81 51 55.60 21 16.18

28.81 55.60 16.18

40 37.41 31 28.19

37.41 28.19

59 54.40 11 15.82 34 36.59

54.40 15.82 36.59

0.275+0.381+1.439+0.180+0.281+0.390+1.471+0.184 4.60

Page 35: Chapter12

35 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Comparing Two or More Populations Using the 2 Statistic

P-value: When H0 is true, 2 has approximately a chi-square distribution with

df = (number of rows - 1)(number of columns - 1)

The P-value associated with the computed test statistic value is the area to the right of 2 under the chi-square curve with the appropriate df.

(Row total)(Column total)Expected cell count =

Grand total

Page 36: Chapter12

36 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

A student decided to study the shoppers in Wegman’s, a local supermarket to see if males and females exhibited the same behavior patterns with regard to the device use to carry items.

He observed 57 shoppers (presumably randomly) and obtained the results that are summarized in the table on the next slide.

Page 37: Chapter12

37 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Determine if the carrying device proportions are the same for both genders using a 0.05 level of significance.

Device

Gender Cart Basket Nothing

Row Marginal

Total

Male 9 21 5 35Female 7 7 8 22

Column Marginal

Total 16 28 13 57

Page 38: Chapter12

38 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Hypotheses:

H0: The true proportions of the device used are the same for both genders.

Ha: The true proportions of the device used are the same for both genders.

Example

Significance level: = 0.05

Test statistic:22 (observed cell count - expected cell count)

expected cell count

Page 39: Chapter12

39 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Using Minitab, we get the following output:

Example

Chi-Square Test: Basket, Cart, Nothing

Expected counts are printed below observed counts

Basket Cart Nothing Total 1 9 21 5 35 9.82 17.19 7.98

2 7 7 8 22 6.18 10.81 5.02

Total 16 28 13 57

Chi-Sq = 0.069 + 0.843 + 1.114 + 0.110 + 1.341 + 1.773 = 5.251DF = 2, P-Value = 0.072

Page 40: Chapter12

40 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

We draw the following conclusion.

Example

With a P-value of 0.072, there is insufficient evidence at the 0.05 significance level to support a claim that males and females are not the same in terms of proportionate use of carrying devices at Wegman’s supermarket.

Page 41: Chapter12

41 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Hypotheses:

H0: The two variables are independent.

Ha: The two variables are not independent.

2 Test for Independence

The 2 test statistic and procedures can also be used to investigate the association between tow categorical variable in a single population.

Page 42: Chapter12

42 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

The expected cell counts are estimated from the sample data (assuming that H0 is true) using the formula

2 Test for Independence

Test statistic:

22 (observed cell count - expected cell count)expected cell count

(Row total)(Column total)Expected cell count =

Grand total

Page 43: Chapter12

43 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

2 Test for Independence

The P-value associated with the computed test statistic value is the area to the right of 2 under the chi-square curve with the appropriate df.

(Row total)(Column total)Expected cell count =

Grand total

P-value:When H0 is true, 2 has approximately a chi-square distribution with

df = (number of rows - 1)(number of columns - 1)

Page 44: Chapter12

44 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Assumptions:

1. The observed counts are from a random sample.

2. The sample size is large: all expected counts are at least 5. If some expected counts are less than 5, rows or columns of the table may be combined to achieve a table with satisfactory expected counts.

2 Test for Independence

Page 45: Chapter12

45 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Consider the two categorical variables, gender and principle form of vision correction for the sample of students used earlier in this presentation.

We shall now test to see if the gender and the principle form of vision correction are independent.

Contacts Glasses NoneRow Marginal

Total

Female 5 9 11 25Male 5 22 27 54

Column Marginal Total

10 31 38 79

Page 46: Chapter12

46 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

ExampleHypotheses:

H0: Gender and principle method of vision correction are independent.

Ha: Gender and principle method of vision correction are not independent.

Significance level: We have not chosen one, so we shall look at the practical significance level.

Test statistic:22 (observed cell count - expected cell count)

expected cell count

Page 47: Chapter12

47 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

ExampleAssumptions:

We are assuming that the sample of students was randomly chosen.

All expected cell counts are at least 5, and samples were chosen independently so the 2 test is appropriate.

Contacts Glasses None

Row Marginal

Total

5 9 11(3.16) (9.81) (12.03)

5 22 27(6.84) (21.19) (25.97)

Column Marginal

Total10 31 38 79

Female25

Male54

Page 48: Chapter12

48 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Assumptions:Notice that the expected count is less than 5 in the cell corresponding to Female and Contacts. So that we should combine the columns for Contacts and Glasses to get

Contacts or Glasses None

Row Marginal

Total

14 11(12.97) (12.03)

27 27(28.03) (25.97)

Column Marginal

Total41 38 79

Female 25

Male 54

Contacts or Glasses None

Row Marginal

Total

14 11

27 27

Column Marginal

Total41 38 79

Female25

Male54

41 25

79

38 25

79

41 54

79

38 54

79

Page 49: Chapter12

49 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

The contingency table for this example has 2 rows and 2 columns, so the appropriate df is (2-1)(2-1) = 1. Since 0.246 < 2.70, the P-value is substantially greater than 0.10. H0 would not be rejected for any reasonable significance level. There is not sufficient evidence to conclude that the gender and vision correction are related.

(I.e., For all practical purposes, one would find it reasonable to assume that gender and need for vision correction are independent.

Calculations: 2 2 2 2

2 14 12.97 11 12.03 27 28.03 27 25.97

12.97 12.03 28.03 25.970.081+0.087+0.038+0.040

0.246

Page 50: Chapter12

50 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc.

Example

Minitab would provide the following output if the frequency table was input as shown.

Chi-Square Test: Contacts or Glasses, None

Expected counts are printed below observed counts

Contacts None Total 1 14 11 25 12.97 12.03

2 27 27 54 28.03 25.97

Total 41 38 79

Chi-Sq = 0.081 + 0.087 + 0.038 + 0.040 = 0.246DF = 1, P-Value = 0.620