Ch14

advertisement

14

Goodness-of-Fit Tests and Categorical Data

Analysis

14.1-14.2 Goodness-of-Fit Tests

Testing for goodness of fit

We use the chi-square test as the tool to compare two or more distributions all based on sample data.

We consider a slight variation on this scenario where only one of the distributions is known (our sample data observations) and we want to compare it with a hypothesized distribution.

 Data for n observations on a categorical variable with k possible outcomes are summarized as observed counts, n

1

, n

2

, . . . , n k

.

The null hypothesis specifies probabilities p

1

, p

2

, . . . , p k for the possible outcomes.

Car accidents and day of the week

A study of 667 drivers who were using a cell phone when they were involved in a collision on a weekday examined the relationship between these accidents and the day of the week.

Are the accidents equally likely to occur on any day of the working week?

H

0 specifies that all 5 days are equally likely for car accidents  each p i

= 1 / 5.

The chi-square goodness of fit test

Data for n observations on a categorical variable with k possible outcomes are summarized as observed counts, n

1

, n

2

, . . . , n k in k cells.

H

0 specifies probabilities p

1

, p

2

, . . . , p k for the possible outcomes.

For each cell, multiply the total number of observations n by the specified probability p i

: expected count = np i

The chi-square statistic follows the chi-square distribution with k − 1 degrees of freedom :

X

2 

 (

observed

 exp

ected

) 2 exp

ected



Chi-squared distribution

If H

0 is true, the chi-square test has approximately a χ

2 distribution with degrees of freedom .

The c

2 distributions are a family of distributions that can take only positive values, are skewed to the right, and are described by a specific degrees of freedom.

Finding the p-value with Table A.7.

The P-value for the chisquare test is the area to the right of c

2 under the c

2 distribution with df

P(χ 2 ≥ X 2 ).

Table A.7 gives upper critical values for many c

2 distributions.

Table A.7.

Ex: 7 possible outcomes (k=7)

Then, df = (k −1)=6

If X 2 = 16.1, the p-value is between

0.01

−0.02.

31.79

32.91

34.03

35.14

36.25

47.27

58.16

68.97

90.41

111.70

20.47

21.61

22.76

23.90

25.04

26.17

27.30

28.43

29.55

30.68

0.2

1.64

3.22

4.64

5.99

7.29

8.56

9.80

11.03

12.24

13.44

14.63

15.81

16.98

18.15

19.31

12

13

14

15

8

9

10

11

6

7

4

5 df

1

2

3

20

21

22

23

24

25

16

17

18

19

26

27

28

29

30.43

31.53

32.62

33.71

30

40

50

60

34.80

45.62

56.33

66.98

80 88.13

100 109.10

19.37

20.49

21.60

22.72

23.83

24.93

26.04

27.14

28.24

29.34

0.25

1.32

2.77

4.11

5.39

6.63

7.84

9.04

10.22

11.39

12.55

13.70

14.85

15.98

17.12

18.25

35.56

36.74

37.92

39.09

40.26

51.81

63.17

74.40

96.58

118.50

23.54

24.77

25.99

27.20

28.41

29.62

30.81

32.01

33.20

34.38

0.1

2.71

4.61

6.25

7.78

9.24

10.64

12.02

13.36

14.68

15.99

17.28

18.55

19.81

21.06

22.31

33.43

34.57

35.71

36.85

37.99

49.24

60.35

71.34

93.11

114.70

21.79

22.98

24.16

25.33

26.50

27.66

28.82

29.98

31.13

32.28

0.15

2.07

3.79

5.32

6.74

8.12

9.45

10.75

12.03

13.29

14.53

15.77

16.99

18.20

19.41

20.60

42.86

44.14

45.42

46.69

47.96

60.44

72.61

84.58

108.10

131.10

29.63

31.00

32.35

33.69

35.02

36.34

37.66

38.97

40.27

41.57

0.02

5.41

7.82

9.84

11.67

13.39

15.03

16.62

18.17

19.68

21.16

22.62

24.05

25.47

26.87

28.26

21.03

22.36

23.68

25.00

26.30

27.59

28.87

30.14

31.41

32.67

33.92

35.17

36.42

37.65

38.89

40.11

41.34

42.56

p

0.05

0.025

3.84

5.99

5.02

7.38

7.81

9.49

11.07

12.59

9.35

11.14

12.83

14.45

14.07

15.51

16.92

18.31

19.68

16.01

17.53

19.02

20.48

21.92

43.77

55.76

67.50

79.08

101.90

124.30

46.98

59.34

71.42

83.30

106.60

129.60

23.34

24.74

26.12

27.49

28.85

30.19

31.53

32.85

34.17

35.48

36.78

38.08

39.36

40.65

41.92

43.19

44.46

45.72

45.64

46.96

48.28

49.59

50.89

63.69

76.15

88.38

112.30

135.80

32.00

33.41

34.81

36.19

37.57

38.93

40.29

41.64

42.98

44.31

0.01

0.005

0.0025

0.001

0.0005

6.63

7.88

9.14

10.83

12.12

9.21

11.34

10.60

12.84

11.98

14.32

13.82

16.27

15.20

17.73

13.28

15.09

16.81

18.48

14.86

16.75

18.55

20.28

16.42

18.39

20.25

22.04

18.47

20.51

22.46

24.32

20.00

22.11

24.10

26.02

20.09

21.67

23.21

24.72

26.22

27.69

29.14

30.58

21.95

23.59

25.19

26.76

28.30

29.82

31.32

32.80

23.77

25.46

27.11

28.73

30.32

31.88

33.43

34.95

26.12

27.88

29.59

31.26

32.91

34.53

36.12

37.70

27.87

29.67

31.42

33.14

34.82

36.48

38.11

39.72

34.27

35.72

37.16

38.58

40.00

41.40

42.80

44.18

45.56

46.93

48.29

49.64

50.99

52.34

53.67

66.77

79.49

91.95

116.30

140.20

36.46

37.95

39.42

40.88

42.34

43.78

45.20

46.62

48.03

49.44

50.83

52.22

53.59

54.97

56.33

69.70

82.66

95.34

120.10

144.30

39.25

40.79

42.31

43.82

45.31

46.80

48.27

49.73

51.18

52.62

54.05

55.48

56.89

58.30

59.70

73.40

86.66

99.61

124.80

149.40

41.31

42.88

44.43

45.97

47.50

49.01

50.51

52.00

53.48

54.95

56.41

57.86

59.30

60.73

62.16

76.09

89.56

102.70

128.30

153.20

Car accidents and day of the week

H

0 specifies that all days are equally likely for car accidents  each p i

= 1 / 5.



The expected count for each of the five days is np i

= 667 ( 1 / 5 ) = 133 .

4.

X 2 

 ( observed  exp ected ) 2 exp ected

 ( count day

 133.4) 2

133.4

 8.49

Following the chisquare distribution with 5 − 1 = 4 degrees of freedom.

3

4 df

1

2

0.25

1.32

2.77

4.11

5.39

0.2

1.64

3.22

4.64

5.99

0.15

2.07

3.79

5.32

6.74

0.1

2.71

4.61

6.25

7.78

p

0.05

0.025

3.84

5.99

5.02

7.38

7.81

9.49

9.35

11.14

0.02

5.41

7.82

9.84

11.67

0.01

0.005

0.0025

0.001

0.0005

6.63

9.21

7.88

10.60

9.14

11.98

10.83

13.82

12.12

15.20

11.34

13.28

12.84

14.86

14.32

16.42

16.27

18.47

17.73

20.00

5 6.63

7.29

8.12

9.24

11.07

12.83

13.39

15.09

16.75

18.39

20.51

22.11

6 7.84

9.04

8.56

9.80

9.45

10.75

10.64

12.02

12.59

14.07

14.45

16.01

15.03

16.62

16.81

18.48

18.55

20.28

20.25

22.04

α

22.46

5%.

24.10

26.02

8

9

10.22

11.39

11.03

12.24

12.03

13.29

13.36

14.68

15.51

16.92

17.53

19.02

18.17

19.68

20.09

21.67

21.95

23.59

23.77

25.46

26.12

27.88

27.87

29.67

10 12.55

13.44

14.53

15.99

18.31

20.48

21.16

23.21

25.19

27.11

29.59

31.42

26.76

28.73

31.26

33.14

weekdays when the driver was using a cell phone.

24.72

12 14.85

15.81

16.99

18.55

21.03

23.34

24.05

26.22

13 15.98

16.98

18.20

19.81

22.36

24.74

25.47

27.69

28.30

29.82

30.32

31.88

32.91

34.53

34.82

36.48

21

22

23

24

25

26

27

14

15

16

17

18

19

20

17.12

18.25

19.37

20.49

21.60

22.72

23.83

24.93

26.04

27.14

28.24

29.34

30.43

31.53

28

29

30

40

32.62

33.71

34.80

45.62

50

60

56.33

66.98

80 88.13

100 109.10

18.15

19.31

20.47

21.61

22.76

23.90

25.04

26.17

27.30

28.43

29.55

30.68

31.79

32.91

34.03

35.14

36.25

47.27

58.16

68.97

90.41

111.70

19.41

20.60

21.79

22.98

24.16

25.33

26.50

27.66

28.82

29.98

31.13

32.28

33.43

34.57

35.71

36.85

37.99

49.24

60.35

71.34

93.11

114.70

21.06

22.31

23.54

24.77

25.99

27.20

28.41

29.62

30.81

32.01

33.20

34.38

35.56

36.74

37.92

39.09

40.26

51.81

63.17

74.40

96.58

118.50

23.68

25.00

26.30

27.59

28.87

30.14

31.41

32.67

33.92

35.17

36.42

37.65

38.89

40.11

41.34

42.56

43.77

55.76

67.50

79.08

101.90

124.30

26.12

27.49

28.85

30.19

31.53

32.85

34.17

35.48

36.78

38.08

39.36

40.65

41.92

43.19

44.46

45.72

46.98

59.34

71.42

83.30

106.60

129.60

26.87

28.26

29.63

31.00

32.35

33.69

35.02

36.34

37.66

38.97

40.27

41.57

42.86

44.14

45.42

46.69

47.96

60.44

72.61

84.58

108.10

131.10

29.14

30.58

32.00

33.41

34.81

36.19

37.57

38.93

40.29

41.64

42.98

44.31

45.64

46.96

48.28

49.59

50.89

63.69

76.15

88.38

112.30

135.80

31.32

32.80

34.27

35.72

37.16

38.58

40.00

41.40

42.80

44.18

45.56

46.93

48.29

49.64

50.99

52.34

53.67

66.77

79.49

91.95

116.30

140.20

33.43

34.95

36.46

37.95

39.42

40.88

42.34

43.78

45.20

46.62

48.03

49.44

50.83

52.22

53.59

54.97

56.33

69.70

82.66

95.34

120.10

144.30

36.12

37.70

39.25

40.79

42.31

43.82

45.31

46.80

48.27

49.73

51.18

52.62

54.05

55.48

56.89

58.30

59.70

73.40

86.66

99.61

124.80

149.40

38.11

39.72

41.31

42.88

44.43

45.97

47.50

49.01

50.51

52.00

53.48

54.95

56.41

57.86

59.30

60.73

62.16

76.09

89.56

102.70

128.30

153.20

14.3

Two-Way Contingency Tables

Hypothesis: no association

Again, we want to know if the differences in sample proportions are likely to have occurred just by chance due to random sampling.

We use the chi-square ( c 2

) test to assess the null hypothesis of no relationship between the two categorical variables of a two-way table.

Expected cell counts

Two-way tables sort the data according to two categorical variables.

We want to test the hypothesis that there is no relationship between these two categorical variables ( H

0

).

To test this hypothesis, we compare actual counts from the sample data with expected counts , given the null hypothesis of no relationship.

The expected count in any cell of a two-way table when H

0 is true is:

Cocaine addiction

Observed

Expected

35% 35% 35%

Desipramine

Lithium

Placebo

Expected relapse counts

No Yes

(25)(26)/74 ≈

8.78

25 x 0.35

16.22

25 x 0.65

9.14

26 x 0.35

8.08

23 x 0.35

16.86

26 x 0.65

14.92

23 x 0.65

Successful firms

Franchise businesses are sometimes given an exclusive territory by contract.

This means that the new outlet will not have to compete with other outlets of the same chain within its own territory. How does the presence of an exclusive-territory clause in the contract relate to the survival of the business?

A simple random sample of 170 new franchises recorded two categorical variables for each firm: (1) whether the firm was successful or not (based on economic criteria) and (2) whether or not the firm had an exclusive-territory contract.

This is a 2x2 table (two levels for success, yes/no; two levels for exclusive territory, yes/no).

 df = (2 − 1)(2 − 1) = 1

Successful firms

Specifically, we will test:

H

0

: No relationship between exclusive clause and success

H a

: There is some relationship between the two variables

The p-value is significant at

α = 5% ( p = 1.5%).

Thus, we reject the null hypothesis.

We have found a significant relationship between an exclusive territory and the success of a franchised firm.

Computations for two-way tables

When analyzing relationships between two categorical variables, follow this procedure:

1.

Calculate descriptive statistics that convey the important information in the table —usually column or row percents.

2.

Find the expected counts and use them to compute the X 2 statistic.

3.

Compare your X 2 statistic to the chi-square critical values to find the approximate P -value for your test.

4.

Draw a conclusion about the association between the row and column variables.

Computing expected counts

When testing the null hypothesis that there is no relationship between both categorical variables of a two-way table, we compare actual counts from the sample data with expected counts given H

0

.

The expected count in any cell of a two-way table when H

0 is true is:

Although in real life counts must be whole numbers, an expected count need not be. The expected count is the mean over many repetitions of the study, assuming no relationship.

Music and wine purchase decision

The null hypothesis is that there is no relationship between music and wine sales. The alternative is that these two variables are related.

What is the expected count in the upper-left cell of the two-way table, under H

0

?

Column total 84: Number of bottles sold without music

Row total 99: Number of bottles of French wine sold

Table total 243: all bottles sold during the study

This expected cell count is thus

(84)(99) / 243 = 34 .

222

Nine similar calculations produce the table of expected counts:

Computing the chi-square statistic

The chi-square statistic ( c

2 ) is a measure of how much the observed cell counts in a two-way table diverge from the expected cell counts.

The formula for the c

2 statistic is:

(summed over all r x c cells in the table) c 2 

observed count - expected count expected count

2

 c

2 components, (observed-expected) 2 /expected, for each cell of the table, and then sum them up to arrive at the c

2 statistic.

Music and wine purchase decision

H

0

: No relationship between music and wine H a

: Music and wine are related

Observed counts Expected counts

We calculate nine X 2 components and sum them to produce the X 2 statistic:

X 2 

 ( observed  exp ected ) 2 exp ected

(30  34.222) 2 (39  30.556) 2 (30  34.222) 2

34.222

34.222

34.222

(11  10.716) 2 (1  9.568) 2 (19  10.716) 2

10.716

9.568

10.716

(43  39.062) 2

(35  34.877) 2

(35  39.062)

39.062

34.877

39.062

 0.5209

 2.3337

 0.5209

 0.0075

 7.6724

2

 6.4038

 0.3971

 0.0004

 0.4223

 18.28



Table A.7.

df = (r −1)(c−1)

Ex: In a

4x3 table, df = 3*2 = 6

If X 2 = 16.1, the p-value is between

0.01

−0.02.

31.79

32.91

34.03

35.14

36.25

47.27

58.16

68.97

90.41

111.70

20.47

21.61

22.76

23.90

25.04

26.17

27.30

28.43

29.55

30.68

0.2

1.64

3.22

4.64

5.99

7.29

8.56

9.80

11.03

12.24

13.44

14.63

15.81

16.98

18.15

19.31

12

13

14

15

8

9

10

11

6

7

4

5 df

1

2

3

20

21

22

23

24

25

16

17

18

19

26

27

28

29

30.43

31.53

32.62

33.71

30

40

50

60

34.80

45.62

56.33

66.98

80 88.13

100 109.10

19.37

20.49

21.60

22.72

23.83

24.93

26.04

27.14

28.24

29.34

0.25

1.32

2.77

4.11

5.39

6.63

7.84

9.04

10.22

11.39

12.55

13.70

14.85

15.98

17.12

18.25

35.56

36.74

37.92

39.09

40.26

51.81

63.17

74.40

96.58

118.50

23.54

24.77

25.99

27.20

28.41

29.62

30.81

32.01

33.20

34.38

0.1

2.71

4.61

6.25

7.78

9.24

10.64

12.02

13.36

14.68

15.99

17.28

18.55

19.81

21.06

22.31

33.43

34.57

35.71

36.85

37.99

49.24

60.35

71.34

93.11

114.70

21.79

22.98

24.16

25.33

26.50

27.66

28.82

29.98

31.13

32.28

0.15

2.07

3.79

5.32

6.74

8.12

9.45

10.75

12.03

13.29

14.53

15.77

16.99

18.20

19.41

20.60

42.86

44.14

45.42

46.69

47.96

60.44

72.61

84.58

108.10

131.10

29.63

31.00

32.35

33.69

35.02

36.34

37.66

38.97

40.27

41.57

0.02

5.41

7.82

9.84

11.67

13.39

15.03

16.62

18.17

19.68

21.16

22.62

24.05

25.47

26.87

28.26

21.03

22.36

23.68

25.00

26.30

27.59

28.87

30.14

31.41

32.67

33.92

35.17

36.42

37.65

38.89

40.11

41.34

42.56

p

0.05

0.025

3.84

5.99

5.02

7.38

7.81

9.49

11.07

12.59

9.35

11.14

12.83

14.45

14.07

15.51

16.92

18.31

19.68

16.01

17.53

19.02

20.48

21.92

43.77

55.76

67.50

79.08

101.90

124.30

46.98

59.34

71.42

83.30

106.60

129.60

23.34

24.74

26.12

27.49

28.85

30.19

31.53

32.85

34.17

35.48

36.78

38.08

39.36

40.65

41.92

43.19

44.46

45.72

45.64

46.96

48.28

49.59

50.89

63.69

76.15

88.38

112.30

135.80

32.00

33.41

34.81

36.19

37.57

38.93

40.29

41.64

42.98

44.31

0.01

0.005

0.0025

0.001

0.0005

6.63

7.88

9.14

10.83

12.12

9.21

11.34

10.60

12.84

11.98

14.32

13.82

16.27

15.20

17.73

13.28

15.09

16.81

18.48

14.86

16.75

18.55

20.28

16.42

18.39

20.25

22.04

18.47

20.51

22.46

24.32

20.00

22.11

24.10

26.02

20.09

21.67

23.21

24.72

26.22

27.69

29.14

30.58

21.95

23.59

25.19

26.76

28.30

29.82

31.32

32.80

23.77

25.46

27.11

28.73

30.32

31.88

33.43

34.95

26.12

27.88

29.59

31.26

32.91

34.53

36.12

37.70

27.87

29.67

31.42

33.14

34.82

36.48

38.11

39.72

34.27

35.72

37.16

38.58

40.00

41.40

42.80

44.18

45.56

46.93

48.29

49.64

50.99

52.34

53.67

66.77

79.49

91.95

116.30

140.20

36.46

37.95

39.42

40.88

42.34

43.78

45.20

46.62

48.03

49.44

50.83

52.22

53.59

54.97

56.33

69.70

82.66

95.34

120.10

144.30

39.25

40.79

42.31

43.82

45.31

46.80

48.27

49.73

51.18

52.62

54.05

55.48

56.89

58.30

59.70

73.40

86.66

99.61

124.80

149.40

41.31

42.88

44.43

45.97

47.50

49.01

50.51

52.00

53.48

54.95

56.41

57.86

59.30

60.73

62.16

76.09

89.56

102.70

128.30

153.20

Music and wine purchase decision

H

0

: No relationship between music and wine H a

: Music and wine are related

We found that the c

2 statistic under H

0 is 18.28.

The two-way table has a 3x3 design (3 levels of music and 3 levels of wine). Thus, the degrees of freedom for the c

2 distribution for this test is:

(r – 1)(c – 1) = (3 – 1)(3 – 1) = 4

22

23

24

25

26

27

26.04

27.14

28.24

29.34

30.43

31.53

28

29

30

40

50

60

32.62

33.71

34.80

45.62

56.33

66.98

80 88.13

100 109.10

12.55

13.70

14.85

15.98

17.12

18.25

19.37

20.49

21.60

22.72

23.83

24.93

0.25

1.32

2.77

4.11

5.39

6.63

7.84

9.04

10.22

11.39

16

17

18

19

20

21

10

11

12

13

14

15

7

8

9

4

5

6 df

1

2

3

20.47

21.61

22.76

23.90

25.04

26.17

27.30

28.43

29.55

30.68

31.79

32.91

34.03

35.14

36.25

47.27

58.16

68.97

90.41

111.70

0.2

1.64

3.22

4.64

0.15

2.07

3.79

5.32

0.1

2.71

4.61

6.25

p

0.05

0.025

3.84

5.99

7.81

5.02

7.38

9.35

0.02

5.41

7.82

9.84

0.01

0.005

0.0025

0.001

0.0005

6.63

9.21

11.34

7.88

10.60

12.84

9.14

11.98

14.32

10.83

13.82

16.27

12.12

15.20

17.73

5.99

7.29

8.56

9.80

11.03

12.24

6.74

7.78

9.49

11.14

11.67

13.28

14.86

16.42

8.12

9.24

11.07

12.83

13.39

16.42 < X 2 = 18.28 < 18.47

10.75

12.02

14.07

16.01

16.62

15.09

16.81

16.75

18.55

18.39

20.25

18.48

20.28

22.04

0.0025 > p-value > 0.001  very significant 23.77

13.29

14.68

16.92

19.02

19.68

21.67

23.59

25.46

18.47

20.51

22.46

24.32

26.12

27.88

20.00

22.11

24.10

26.02

27.87

29.67

13.44

14.63

14.53

15.77

15.99

17.28

18.31

19.68

20.48

21.92

21.16

22.62

23.21

24.72

25.19

26.76

27.11

28.73

29.59

31.26

31.42

33.14

15.81

16.98

16.99

18.20

18.55

19.81

21.03

22.36

23.34

24.74

24.05

25.47

18.15

19.31

19.41

20.60

21.06

22.31

23.68

25.00

26.12

27.49

26.87

28.26

26.22

27.69

29.14

30.58

28.30

29.82

31.32

32.80

30.32

31.88

33.43

34.95

32.91

34.53

36.12

37.70

34.82

36.48

38.11

39.72

21.79

22.98

24.16

25.33

26.50

27.66

28.82

29.98

31.13

32.28

33.43

34.57

35.71

36.85

37.99

49.24

60.35

71.34

93.11

114.70

23.54

24.77

25.99

27.20

28.41

29.62

30.81

32.01

33.20

34.38

35.56

36.74

37.92

39.09

40.26

51.81

63.17

74.40

96.58

118.50

26.30

27.59

28.87

30.14

31.41

32.67

33.92

35.17

36.42

37.65

38.89

40.11

41.34

42.56

43.77

55.76

67.50

79.08

101.90

124.30

28.85

30.19

31.53

32.85

34.17

35.48

36.78

38.08

39.36

40.65

41.92

43.19

44.46

45.72

46.98

59.34

71.42

83.30

106.60

129.60

29.63

31.00

32.35

33.69

35.02

36.34

37.66

38.97

40.27

41.57

42.86

44.14

45.42

46.69

47.96

60.44

72.61

84.58

108.10

131.10

32.00

33.41

34.81

36.19

37.57

38.93

40.29

41.64

42.98

44.31

45.64

46.96

48.28

49.59

50.89

63.69

76.15

88.38

112.30

135.80

34.27

35.72

37.16

38.58

40.00

41.40

42.80

44.18

45.56

46.93

48.29

49.64

50.99

52.34

53.67

66.77

79.49

91.95

116.30

140.20

36.46

37.95

39.42

40.88

42.34

43.78

45.20

46.62

48.03

49.44

50.83

52.22

53.59

54.97

56.33

69.70

82.66

95.34

120.10

144.30

39.25

40.79

42.31

43.82

45.31

46.80

48.27

49.73

51.18

52.62

54.05

55.48

56.89

58.30

59.70

73.40

86.66

99.61

124.80

149.40

41.31

42.88

44.43

45.97

47.50

49.01

50.51

52.00

53.48

54.95

56.41

57.86

59.30

60.73

62.16

76.09

89.56

102.70

128.30

153.20

Download