Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test...

26
1 1 Lecture 23 ! Test of Goodness of Fit ! Contingency Tables

Transcript of Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test...

Page 1: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

11

Lecture 23

! Test of Goodness of Fit

! Contingency Tables

Page 2: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

2

• In some problems, we have one specificdistribution in mind for the data we will observe.If that one distribution is not appropriate, we donot necessarily have a parametric family ofalternative distributions in mind.

• In these cases, and others, we can still test the nullhypothesis that the data come from the onespecific distribution against the alternativehypothesis that the data do not come from thedistribution.

Page 3: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

3

Test of Goodness-of-fit! Test of Goodness-of-fit

The goodness of fit measures the extent towhich the distribution expected under the nullhypothesis how well it fits a set ofobservations. Measures of goodness of fittypically summarize the discrepancy betweenobserved values and the values expectedunder the model in question.

Page 4: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

4

Testing goodness of fit : the Chi-square statistic (C2)

! Used for frequency (categorical) data, i.e. the nnumber of observations/results in each of k categoriescompared to the number expected under the nullhypothesis.

2

1

( )ki i

i i

Observed ExpectedExpectedQ

=

-=å

! If the match between observed and expected is poor, then we should reject the null hypothesis.

Page 5: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

5

Example: Scott Marketing Research firm

Over the past year market shares have stabilized, with 30% for company A, 50% for company B, 20%for company C.

Recently company C has developed a “new and improved” product that will replace its current entry in the market. Managers of company C have asked Scott firm to determine whether the new product will cause a shift in the market shares of the three competitors.

Page 6: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

6

! Scott firm conducted a survey with 200 responses. The results are:• A 48• B 98• C 54

! Is there any change in market shares?

Page 7: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

7

Goodness-of-fit Test

! H0: The population consists 3 different types,with PA=0.30 PB=0.50 PC=0.20;H1: The population does not have PA=0.30PB=0.50 PC=0.20.

! Basic idea:if H0 is true, the difference between the

observed frequencies and expectedfrequencies should not be large.

Page 8: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

8

Sampling Distribution under H0

210

10

20

~,when,Under

)(

-

=

¥®

-=å

k

k

i i

ii

QnHnpnpNQ

c

k : the number of categories.n : the sample size.

iN : the observed counts for category i.

00

01

: , 1, ,: , for at least one value of .

i i

i i

H p p i kH p p i

= =

¹

!

Page 9: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

9

Rule of five! The test statistic used to perform the test is

only approximately Chi-squared distributed.

! For the approximation to apply, the expected cell frequency has to be at least 5.

! If the expected frequency in a cell is less than 5, combine it with other cells.

Page 10: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

10

Calculations: Scott Marketing Research firmAssumed Observed ExpectedProportion Frequency Frequency

Company A 0.3 48 60 Company B 0.5 98 100 Company C 0.2 54 40 Total 200 200

! Using a= 0.05,rejection region is

99.5205.0,2

2,1 ==> - cc akQ

5.99

05.0=a

2c

34.740

)4054(100

)10098(60

)6048( 222

=-

+-

+-

=Q

Any change in market shares?Yes!

Page 11: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

11

Genetics Problem! Each individual in a given population must have one

of three possible genotypes, and it is assumed that the probabilities p1, p2 and p3 of the three genotypes can be represented in the following form:

! A random sample is taken from the population, and the statistician must test the following hypotheses:H0: There exists a value of q in (0,1) such that pi=pi(q)

for i=1,…,3,H1: The hypothesis H0 is not true.

233

22

211

)1()()1(2)(

)(

qqpqqqp

qqp

-=º

-=º=º

ppp

Page 12: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

12

! Under null hypothesis, let denote the M.L.E. of the parameter based on the observed numbers N1,…,N3, i.e.

[ ] [ ] [ ]

[ ] [ ]

[ ]nNN

NNNNNL

NNNNNNNN

NL

L

iii

NNN

22

)(22)(logmaxargˆ

2log)1log()2(log)2()1(log)1(2log)log(

)(log)(log

)()()()(

21

321

21

22321

232

21

3

1

321321

+=

+++

==

+-+++=-+-+=

=

=

å=

qq

qqqqqq

qpq

qpqpqpq

q

Page 13: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

13

! The statistic Q can be found by:

! R. A. Fisher (1924) showed that if the null hypothesis is true and certain regularity conditions are satisfied, then the d.f. of Q converges to the d.f. of as the sample size where s is the number of parameters estimated (s=1 in the genetic example).

[ ]å=

-=

3

1

2

)ˆ()ˆ(

i i

ii

nnNQqpqp

21 sk --c

¥®n

Page 14: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

14

Page 15: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

15

Page 16: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

16

Contingency Tables

! Alber’s Brewery manufactures and distributes threetypes of beer: light, regular, and dark. In an analysisof the market segments for the three beers, the firm’smarket research group has raised the question ofwhether the preferences for the three beers differamong male and female beer drinkers. If thepreference depends on the gender of the beerdrinker, the firm will tailor its promotions todifferent target markets.

Page 17: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

17

! H0: Beer preference is independent of the gender of the beer drinker.

! H1: Beer preference is not independent of the gender of the beer drinker.

! Sample results:Beer Preference

Light Regular Dark TotalSex Male

Female20 40 2030 30 10

8070

Total 50 70 30 150

Page 18: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

18

什么叫做独立?

! 情景1:

! 情景2:

! 情景3:

A B C男性 10 20 20

女性 10 20 20

A B C男性 1 6 32 3 2

女性 4 8 8

A B C男性 10 30 10

女性 10 10 30

Page 19: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

19

案例中

n 两变量独立是指产品选择与性别无关。不管是男是女,选择产品A的比例(概率)是相同的,选择产品B的比例是相同的,选择产品C的比例是相同的。

Page 20: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

20

检验统计量及分布

如果原假设成立,在样本大(每个单元格的预期频数不少于5)的时候,

( )2 2( 1) ( 1)

1 1~

L Mlm lm

L Ml m lm

o ee

c - ´ -= =

-åå

Page 21: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

21

卡方独立性检验

( )2

1 1

2( 1) ( 1)

L Mlm lm

l m lm

lm

lm

L M

L M

o eT

eo l mo l m

c

= =

- ´ -

-=åå

设列联表有 行 列。

检验统计量:

—位于第行、第 列的单元的观测频数

—原假设下位于第行、第 列的单元的期望频数

在原假设下,检验统计量的分布近似为

( )

2,( 1) ( 1)

2( 1) ( 1)P

L M

L M

T

p Tac

c- ´ -

- ´ -

Þ

Þ

>

>

检验统计量的值越大

观测频数与期望频数相差越大

原假设越可能不正确

拒绝域:

值: 观测到的 值

Page 22: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

22

! R rows and C columns.! pij: the probability that an individual selected at

random from a given population will be classified in the ith row and the jth column of the table.

! pi.: the marginal probability that the individual will be classified in the ith row of the table.

! p.j: the marginal probability that the individual will be classified in the jth column of the table.

å ==

C

j iji pp1.

å ==

R

i ijj pp1.

11 .1 .1 1

=== ååå å === =

C

j jR

i iR

i

C

j ij ppp

ijp

Page 23: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

23

The Beer Example! Expected Frequency:

Beer PreferenceLight Regular Dark Total

Sex MaleFemale

80*50/150=26.67 80*70/150=37.33 80*30/150=16.0070*50/150=23.33 70*70/150=32.67 70*30/150=14.00

8070

Total 50 70 30 150

13.6ˆ

)ˆ(2

1

3

1

2

=-

=å å= =i jij

ijij

pnpnN

Q

Page 24: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

24

! When a = 0.05, the rejection region is

! So we reject the null hypothesis and conclude beerpreferences is not independent of the sex of the beerdrinker.

99.5205.0,2

205.0),13)(12( ==> -- ccQ

Page 25: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

25

案例:意见反馈情况

某公司的负责人就公司拓展某项业务的计划征求

了员工的意见。反馈意见的详细分类显示在下表。是否有证据可以推断,三个不同组的员工的反馈意见是不同的?

意见 蓝领工人 白领工人 管理者

支持 67 32 11

反对 63 18 9

Page 26: Lecture 23 - PKUmwfy.gsm.pku.edu.cn/miao_files/ProbStat/lecture23.pdf · 9 Rule of five!The test statistic used to perform the test is only approximately Chi-squared distributed.

26

案例:衬衫的质量

某生产衬衫的公司的运营经理想确定不同班次生产出来的衬衫的做工质量是不是存在差异。他随机选取了600件衬衫并且对它们进行了仔细的检查。每件衬衫都被归为好或中或差,并且记录下了每件衬衫相应的生产班次。

这些数据是否提供了足够的证据来推断三个班次的工人生产的衬衫的质量有差异?

班次

衬衫质量 1 2 3好 240 191 139差 10 9 11