goodness of fit test and test for independence...Øchi-square!distribution Øgoodness!of!fit...

13
Goodness of Fit Test and Test for Independence Chi-Square Distribution Chi-Square Distribution: Note : Because there are many different shapes, software needs to be used to calculate probabilities in the tails, much like the t-distribution. Chi-Square Table

Upload: others

Post on 06-Sep-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Ø Chi-Square!Distribution

ØGoodness!of!Fit

Ø Examining!Standardized!Residuals

ØTest!for!Independence

ØDifference!of!Two!Proportions

Goodness of Fit Test and Test for Independence

Lecture!15

Section!14.1�14.3,!14.5�14.6

Chi-Square Distribution

• Chi-Square Distribution: continuous!probability!distribution!with!the!following!properties:• Unimodal,!right-skewed,!and!always!non-negative

• Values!get!larger!as!degrees!of!freedom!increase

• Denoted!by!!"# where!$ is!the!number!of!degrees!of!freedom• Degrees!of!freedom!dependent!upon!number!of!categories!in!variable(s)

Note: Because there are many

different shapes, software needs to be

used to calculate probabilities in the

tails, much like the t-distribution.

Chi-Square Table

• Because!the!chi-square!distribution!is!not!symmetric,!the!table!only!gives!statistics!for!areas!in!the!upper!tail.• As!degrees!of!freedom!increase,!chi-square!values!increase!to!get!the!same!area!in!the!upper!tail

• To!reject!the!null!hypothesis,!larger!test!statistics!are!needed!for!tests!that!have!more!degrees!of!freedom.

• Note:!All!chi-square!tests!in!this!course!are!upper!one-sided.

Table!Continues

Page 2: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Motivation: Goodness of Fit Test

• Scenario: CEO!is!interested!in!the!days!of!the!week!that!his!employees!are!most!likely!to!take!off.!!Take!a!random!sample!of!500!employees!and!look!at!the!day!of!the!week!they!last!took!off.

• Question: Do!workers!call!off!work!equally!across!all!five!days?

• Problem: Variable!has!more!than!______________!so!___________________!____________!does!not!apply

• Solution: Compare!________________!against!___________________________!__________________________________________________________________

Day Monday Tuesday Wednesday Thursday Friday

Times Called Off 107 82 68 90 153

Goodness of Fit Test: Hypotheses and Expected Counts

•Hypotheses: Must!be!customized!to!fit!the!problem,!but!the!general!idea!is:• %&:!The!specified!probability!distribution!fits!the!data!well• %':!The!specified!probability!distribution!does!not!fit!the!data!well

• Expected Counts: the!number!of!observations!from!the!sample!that!would!be!expected!to!fall!into!each!category!if!the!distribution!specified!in!the!null!hypothesis!is!true• Hypothesized Proportion: ()• Total Sample Size: *• Expected Count: *()

Example: Goodness of Fit

• Question: Do!workers!call!off!work!equally!across!all!five!days?

•Hypotheses:• _______________________________________________________________________________

• _______________________________________________________________________________!______________________

Day Monday Tuesday Wednesday Thursday Friday

Times Called Off 107 82 68 90 153

Expected Count 100 100 100 100 100

Page 3: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Goodness of Fit: Conditions

• Conditions:• Count Data: Data!must!be!counts!for!categories!of!a!categorical!variable

• Independence: Counts!in!the!cells!should!be!independent

• Randomization: Individuals!in!table!should!comprise!a!random!sample!from!the!population

• Expected Cell Frequency Count: Expected!number!of!observations!in!each!cell!at!least!5;!that!is,!*() + 5 for!each!assigned!proportion

Example: Goodness of Fit

• Question: Do!workers!call!off!work!equally!across!all!five!days?

• Setup:• Count Data: Each!observation!falls!into!__________________________

• Independence: One!employee�s!off-day!likely!_____________________________!__________________________________________________________

• Randomization: Employees!come!from!_________________!and!were!likely!__________________________

• Expected Cell Frequency Count: All!expected!counts!are!________________

Day Monday Tuesday Wednesday Thursday Friday

Times Called Off 107 82 68 90 153

Expected Count 100 100 100 100 100

Goodness of Fit: Test Statistic

• To!test!the!hypotheses!in!a!goodness!of!fit!test,!the!test!statistic!is:

,-./# =0)1/

- Observed 2 Expected #

Expectedwhere!3 is!the!number!of!categories!in!the!variable

• Idea: Compare!observed!and!expected!counts!in!each!category• The!_______!the!difference!between!the!observed!and!expected!counts,!the!larger!the!________________

• Larger!test!statistic!means!observed!and!expected!counts!are!_____________

• Reject!null!hypothesis!for!________!test!statistics!à __________________________

Note: Degrees of freedom based on the number of categories; not sample size!

Page 4: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Goodness of Fit

• Question: Do!workers!call!off!work!equally!across!all!five!days?

•Mechanics:• Test Statistic:

,# = ___________________________________________________________________________= _____________________________________= __________

• Degrees of Freedom: _____________________

• P-Value: ________________!(Using!software)

Day Monday Tuesday Wednesday Thursday Friday

Times Called Off 107 82 68 90 153

Expected Count 100 100 100 100 100

________

________

Example: Goodness of Fit

• Question: Do!workers!call!off!work!equally!across!all!five!days?

• Conclusion: With!a!p-value!of!_______________,!we!____________________!______________!and!conclude!that!the!proportion!of!times!employees!called!off!________________________________________________________________.!!Thus,!____________________________________________________________________.

Day Monday Tuesday Wednesday Thursday Friday

Times Called Off 107 82 68 90 153

Expected Count 100 100 100 100 100

Standardized Residuals

• Standardized Residual: a!measure!of!how!many!standard!deviations!an!observed!count!is!from!its!corresponding!expected!count!for!a!particular!category

4 = Observed 2 ExpectedExpected

• If!the!null!hypothesis!is!rejected,!standardized!residuals!give!us!an!idea!of!the!categories!that!likely!differed!from!their!hypothesized!proportions.

Page 5: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Standardized Residuals

• Question: What!are!the!standardized!residuals!for!each!day?

• Answer:

Day Observed Expected Standardized Residual

Monday 107 100

Tuesday 82 100

Wednesday 68 100

Thursday 90 100

Friday 153 100

Example: Standardized Residuals

• Question: What!do!the!standardized!residuals!tell!us!about!when!employees!take!off?

• Answer: Compared!to!what!we!would!expect!if!all!days!were!taken!off!equally:!• Monday:!__________________:!_____________________!days!off!than!expected

• Tuesday:!_______________________:!__________days!off!than!expected

• Wednesday:!_______________________:!_________________days!off!than!expected

• Thursday:!__________________:!_____________________!days!off!than!expected

• Friday:!______________________________:!______________!days!off!than!expected

Day Monday Tuesday Wednesday Thursday Friday

Standardized Res. .70 -1.80 -3.20 -1.00 5.30

Example: Standardized Residuals

• Question: What!do!the!standardized!residuals!tell!us!about!how!the!proportion!of!days!taken!off!relate!to!.20?

• Answer: Proportion!of!days!taken!off!on�• Wednesday!and!Friday!_________________________________!from!.20• __________!residuals

• Tuesday!_______________________________________!from!.20• ______________!residual

• Monday!and!Thursday!likely!______________________________!from!.20• __________!residuals

Day Monday Tuesday Wednesday Thursday Friday

Standardized Res. .70 -1.80 -3.20 -1.00 5.30

Page 6: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Using Excel

• Scenario:Mars!Company!claims!that!plain!M&M�s!have!the!following!distribution!of!colors:

• Question: Does!Mars�!claim!appear!to!be!accurate?

• Setup:• Hypotheses:

• ______________________________________________________________________________

• ______________________________________________________________________________!___________________________________

Color Blue Orange Green Yellow Brown Red

Hypothesized Proportion .24 .20 .16 .14 .13 .13

Example: Using Excel

• Scenario: After!opening!a!large!bag!of!plain!M&M�s,!you!find!the!following!counts:

• Question: Does!Mars�!claim!appear!to!be!accurate?

• Setup:• Count Data Condition: Each!observation!falls!into!________________________

• Independence: Color!of!one!M&M!has!___________!on!the!color!of!another

• Randomization: Bags!were!__________________________________________________

• Expected Cell Frequency Count: All!expected!counts!are!________________• Verification!on!next!slide

Color Blue Orange Green Yellow Brown Red

Actual Counts 128 92 83 56 61 49

Example: Using Excel

Note: Both CHISQ.TEST and CHISQ.DIST.RT will calculate the p-value.

They take the following arguments:

• CHISQ.DIST.RT([Test statistic], [Degrees of freedom])

• CHISQ.TEST([Range of observed counts], [Range of expected counts])

B

Page 7: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Using Excel

• Question: Does!Mars�!claim!appear!to!be!accurate?

•Mechanics:• Test Statistic: _______________

• Degrees of Freedom: ___________________

• P-Value: __________

• Conclusion: With!a!p-value!of!_________,!we!fail!to!___________________!_______________!and!conclude!that!the!distribution!of!colors!for!plain!M&M�s!_____________________________________________________.!!Therefore,!Mars!Company�s!claim!___________________________________.

Example: Standardized Residuals

• Question: What!do!you!notice!about!the!standardized!residuals?

• Answer: All!are!______________________• Most!of!the!____________!counts!were!close!to!their!____________!counts

• None!are!_____________________________!to!suggest!any!____________!counts

• Question: Why!should!this!have!been!expected?

• Answer: The!p-value!was!_________,!giving!the!indication!that!the!__________________________________________________________.

• Takeaway: Standardized!residuals!are!more!important!to!analyze!__________________________________________________.

Color Blue Orange Green Yellow Brown Red

Standardized Residual 1.455 -0.186 0.919 -1.192 0.004 -1.533

Review: Independence

• Scenario: All!employees!at!a!company!are!asked!if!they!would!be!interested!in!attending!a!professional!development!training

• Question: Are!being!a!full!time!employee!and!interest!in!professional!development!independent?

• Answer: ______

• Product of Marginals: ________________________________________________________

• Joint Probability: ______________________________________

Interested Not Interested Total

Full Time 240 60 300

Part Time 160 40 200

Total 400 100 500

Page 8: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Independence: Probability vs. Inference

• In!probability,!two!events!were!deemed!to!be!independent!if!6 7 and 8 = 697: × 698:.• In!inference,!because!we!deal!with!samples!that!are!much!smaller!than!the!population,!it!is!not!practical!to!check!for!exact!equality!between!the!marginal!and!joint!probabilities.

• Instead,!compare!the!observed!counts!against!the!expected!counts!under!the!assumption!the!events!are!independent!to!see!if!they!are!close.

Motivation: Test for Independence

• Scenario: Randomly!sample!400!people!and!record!their!gender!and!handedness

• Question: Are!gender!and!handedness!independent!or!is!one!gender!more!likely!to!be!left!or!right!handed?

• Strategy:• Assume!gender!and!handedness!are!___________________

• Compare!number!of!______________________________________________!against!the!number!we!would!expect!in!the!sample!_____________________________________

Left-Handed Right-Handed Total

Male 20 140 160

Female 20 220 240

Total 40 360 400

Test for Independence: Hypotheses and Expected Counts

•Hypotheses: Inserting!the!variable!names,!the!general!idea!is:• %&:!The!variables!are!independent• %'; The!variables!are!not!independent

• Expected Counts: the!number!of!observations!from!the!sample!that!would!be!expected!to!fall!into!each!cell!in!the!table!if!the!variables!are!actually!independent

<)> =9Row ? sum:9Column @ sum:

Total sample size

Page 9: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Test for Independence

• Question: Are!gender!and!handedness!independent?

•Hypotheses:• __________________________________________________________________

• __________________________________________________________________

Left-Handed Right-Handed Total

Male 20 140 160

Female 20 220 240

Total 40 360 400

Test for Independence: Conditions

• Conditions:• Count Data: Data!must!be!counts!for!categories!of!a!categorical!variable

• Independence: Counts!in!the!cells!should!be!independent

• Randomization: Individuals!in!table!should!comprise!a!random!sample!from!the!population

• Expected Cell Frequency Count: Expected!number!of!observations!in!each!cell!at!least!5

Example: Test for Independence

• Question: Are!gender!and!handedness!independent?

• Conditions:• Count Data: Each!observation!falls!into!__________________________________

• Independence: One!person�s!handedness!__________________________________

• Randomization: Subjects!were!randomly!selected!from!__________________!_______________________________________

• Expected Cell Frequency Count: All!expected!counts!are!________________

Expected Left Right Total

Male 160

Female 240

Total 40 360 400

Page 10: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Test for Independence: Test Statistic

• To!test!hypotheses!in!a!test!for!independence,!the!test!statistic!is:

,9A./:9B./:# =0)1/

- Observed 2 Expected #

Expectedwhere!D is!the!number!of!categories!in!the!row!variable!and!F is!the!number!of!categories!in!the!column!variable

• Idea: Same!as!goodness!of!fit!� compare!observed!and!expected!counts!in!each!category• Larger!test!statistic!means!observed!and!expected!counts!are!far!away• Reject!null!hypothesis!for!large!test!statistics!à Upper!one-sided!test

Example: Test for Independence

• Question: Are!gender!and!handedness!independent?

•Mechanics:• Test Statistic:

,# = _______________________________________________________= ________________________________= __________

• Degrees of Freedom: _________________________________

• P-Value: __________!(Using!software)

Obs. Left Right Total

Male 20 140 160

Female 20 220 240

Total 40 360 400

Exp. Left Right Total

Male 16 144 160

Female 24 216 240

Total 40 360 400

______

________

Example: Test for Independence

• Question: Are!gender!and!handedness!independent?

• Conclusion: With!a!p-value!of!________,!we!___________________________!__________________!and!conclude!gender!and!handedness!_____________!_____________________.!!Thus,!knowing!a!person�s!gender!yields!_______!__________________________________________________.

Obs. Left Right Total

Male 20 140 160

Female 20 220 240

Total 40 360 400

Exp. Left Right Total

Male 16 144 160

Female 24 216 240

Total 40 360 400

Page 11: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Standardized Residuals

• Scenario: Gender!and!handedness!were!found!to!be!independent.

• Question: What!are!the!standardized!residuals?

Gender Handedness Observed Expected Standardized Residual

Male Left 20 16

Male Right 140 144

Female Left 20 24

Female Right 220 216

Example: Standardized Residuals

• Scenario: Gender!and!handedness!were!found!to!be!independent.

• Question: What!do!the!standardized!residuals!tell!us?

• Answer: __________________________________________________• Most!of!the!observed!counts!were!______________!their!expected!counts

• None!are!_________________________________!to!suggest!any!_____________!counts

Std. Res. Left Right

Male 1.00 -0.333

Female -0.816 0.272

Example: Test for Independence

• Scenario: Doctors!are!interested!in!patients�!opinions!of!pain!relief!from!three!pain!killers!taken!after!surgery

• Question: Is!the!amount!of!pain!relief!independent!of!pain!killer?

•Hypotheses:• ___________________________________________________________________

• ___________________________________________________________________

Observed Ibuprofen Acetaminophen Codeine Total

Significant Relief 85 80 92 257

Slight Relief 70 83 54 207

Total 155 163 146 464

Page 12: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Using Excel

Note: Both CHISQ.TEST and CHISQ.DIST.RT will calculate the p-value.

• CHISQ.DIST.RT([Test statistic], [Degrees of freedom])

• CHISQ.TEST([Range of observed counts], [Range of expected counts])

Example: Test for Independence

• Question: Is!the!amount!of!pain!relief!independent!of!pain!killer?

• Conditions:• Count Data: Each!observation!falls!into!______________________________

• Independence: One!person�s!pain!__________________________________________

• Randomization: Subjects!likely!all!came!from!________________________,!but!comprise!a!________________________________________

• Expected Cell Frequency Count: All!expected!counts!are!________________

Observed Ibuprofen Acetaminophen Codeine Total

Significant Relief 85 80 92 257

Slight Relief 70 83 54 207

Total 155 163 146 464

Example: Test for Independence

• Question: Is!the!amount!of!pain!relief!independent!of!pain!killer?

•Mechanics:• Test Statistic: _______________

• Degrees of Freedom: ______________________________

• P-Value: __________

Observed Ibuprofen Acetaminophen Codeine Total

Significant Relief 85 80 92 257

Slight Relief 70 83 54 207

Total 155 163 146 464

Page 13: Goodness of Fit Test and Test for Independence...ØChi-Square!Distribution ØGoodness!of!Fit ØExamining!Standardized!Residuals ØTest!for!Independence ØDifference!of!Two!Proportions

Example: Test for Independence

• Question: Is!the!amount!of!pain!relief!independent!of!pain!killer?

• Conclusion: With!a!p-value!of!_______,!we!____________________________!and!conclude!the!type!of!pain!killer!and!the!amount!of!pain!relief!a!person!feels!post-surgery!are!_____________________________.

• Question: How!can!we!determine!what!the!relationship!is?

• Answer: Calculate!a!____________________________________________________!_____________________________________

Observed Ibuprofen Acetaminophen Codeine Total

Significant Relief 85 80 92 257

Slight Relief 70 83 54 207

Total 155 163 146 464

Difference of Two Proportions

• To!estimate!the!difference!in!the!proportion!of!successes!between!two!categorical!variables:

G(/ 2 G(# ± H G(/ GI/*/ J G(# GI#

*#

where!H is!the!standard!normal!multiplier!for!confidence!intervals,! G(/ and! G(# are!the!sample!proportions!and!*/ and!*# are!the!respective!sample!sizes

• Note:!The!conditions!are!the!same!as!the!test!for!independence

Example: Difference of Two Proportions

• Scenario: Confidence!intervals!for!every!pair!of!pain!killers!displaying!the!difference!in!the!proportions!is!shown!below

• Question: What!recommendations!would!you!make!to!the!doctor?

• Answer: __________!is!_________________________!at!providing!significant!pain!relief!than!_____________________.!!____________!worked!better!than!_______________,!but!the!difference!was!___________________.!______________!worked!better!than!____________________,!but!this!difference!was!_____!_______________________________

First Medication Second Medication Confidence Interval

Ibuprofen Acetaminophen (-0.052, 0.167)

Codeine Ibuprofen (-0.029, 0.193)

Codeine Acetaminophen (0.030, 0.249)