© department of statistics 2012 stats 330 lecture 28: slide 1 stats 330: lecture 28

39
© Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

Upload: roberta-stone

Post on 11-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 1

Stats 330: Lecture 28

Page 2: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 2

Plan of the dayIn today’s lecture we apply Poisson regression to the analysis of contingency tables having 3 or 4 dimensions.Topics

– Types of independence– Connection between independence and interactions for

3 and 4 dimensional tables– Hierarchical models– Graphical models– Examples

Reference: Coursebook, sections 5.3, 5.3.1

Page 3: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 3

Example: the Florida murder data

• 326 convicted murderers in Florida, 1976-1977

• Classified by– Death penalty (n/y)– Victims race (black/white)– Defendants race (black/white)

Page 4: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 4

Contingency table

Victim's race

Black White

Defendant's Death Penalty Death Penalty

Race Yes No Yes No

Black 13 195 23 105

White 1 19 39 265

Page 5: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 5

Getting the data into Rmurder.df<-data.frame(expand.grid( defendant=c("b","w"),dp = c("y","n"),victim=c("b","w")),counts=c(13,1,195,19,23,39,105,265))

Note use of function expand.gridexpand.grid(defendant=c("b","w"),dp = c("y","n"),victim=c("b","w")) defendant dp victim1 b y b2 w y b3 b n b4 w n b5 b y w6 w y w7 b n w8 w n w

Page 6: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 6

The data frame

defendant dp victim counts1 b y b 132 w y b 13 b n b 1954 w n b 195 b y w 236 w y w 397 b n w 1058 w n w 265

Page 7: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 7

Questions

• Is death penalty independent of race?

• What is the role of victim’s race?

• What does “independent” mean when we have 3 factors?

Page 8: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 8

Types of independence

• Suppose we have 3 criteria (factors) A, B and C

• In a multinomial sampling context, let

ijk = Pr(A=i, B=j, C=k)

• Various forms of independence may be of interest. These can be expressed in terms of the probabilities ijk

Page 9: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 9

Marginal probabilities

ij

kijk

k

k

kCjBiAPjBiAP

kCjBiAjBiA

),,(),(

},,{},{

Page 10: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 10

Marginal probabilities (ii)

i

j kijk

j k

kj

kCjBiAPiAP

kCjBiAiA

),,()(

},,{}{,

Page 11: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 11

All three factors independent

• This can be expressed as

kji

ijk

k)(Cj)(Bi)(A

kCjBiA

PrPrPr

),,Pr(

Page 12: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 12

One factor independent of the other two

• This can be expressed as

jki

ijk

k)Cj(Bi)(A

kCjBiA

,PrPr

),,Pr(

Page 13: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 13

Two factors conditionally independent, given a third

This can be expressed as

k

jkkiijk

kCjBkCiA

kCjBiA

toEquivalent

)|Pr()|Pr(

)|,Pr(

Page 14: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 14

Parameterising tables of Poisson means with main effects and

interactions• Recall (see Slides 22 and 23 of lecture 19) that in

ordinary 3-way ANOVA we split up the table of means into main effects and interactions:

mijkijkijjkik

ijk

• We can do exactly the same thing with the logs of the Poission means in a 3-way table:

Log(mjk

ijkijjkik ijk

Page 15: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 15

Parameterising tables of probabilities with main effects and

interactions

• Corresponding multinomial probabilities are given by the model

Log(jk /

ijkijjkik

ijk

Page 16: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 16

Parameterising tables with main effects and

interactions (cont)• The interactions are related to the different forms of

independence: – if all the interactions are zero, then the 3 factors are

mutually independent – If the ABC and AB interactions are zero, then A and B are

independent, given C– If the ABC, AB and AC interactions are zero, then A is

independent of B and C• Using the connection between multinomial and

Poisson sampling, we can test for the various types of independence by fitting a Poisson regression with A, B and C as explanatory variables, and testing for interactions.

Page 17: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 17

Summary of independence models

• All 3 factors independent in multinomial model– Equivalent to all interactions zero in

Poisson model– Poisson Model is count ~ A + B + C

• A independent of B and C– Equivalent to all interactions between A

and the others zero– Poisson Model is count ~ A + B + C + B:C

or count ~ A + B*C

Page 18: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 18

Summary of independence models (cont)

• Factors A and B conditionally independent given C – Equivalent to all interactions containing both A

and B zero– Poisson Model is

count ~ A + B + C + A:C + B:C– Equivalent to count ~ A*C + B*C

Page 19: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 19

Analysis strategy: Florida data

• We will fit some models to this data and investigate the pattern of independence/ dependence between the factors.

• We fit a maximal model, and then investigate suitable submodels.

Page 20: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 20

The analysis> maximal.glm<-glm(counts~victim*defendent*dp, family=poisson, data=murder.df)> anova(maximal.glm, test="Chisq") Df Deviance Resid. Df Resid. Dev P(>|Chi|)NULL 7 774.73 victim 1 64.10 6 710.63 1.183e-15defendent 1 0.22 5 710.42 0.64dp 1 443.51 4 266.90 1.861e-98victim:defendent 1 254.15 3 12.75 3.230e-57victim:dp 1 10.83 2 1.92 9.999e-04defendent:dp 1 1.90 1 0.02 0.17victim:defendent:dp 1 0.02 0 -2.442e-15 0.89>

No interactions between defendants race and death penalty - Seems that model victim*dp + victim*defendant is appropriate “given the victim’s race, defendants race and death penalty are independent” ie the conditional independence model. Model also selected by stepwise, other anovas.

Page 21: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 21

Testing if the model is adequate

> submodel.glm<-glm(counts~victim*defendant + victim*dp, family=poisson, data=murder.df)

> summary(submodel.glm)Deviance Residuals: 1 2 3 4 5 6 7

8 0.0636 -0.2127 -0.0163 0.0525 1.0389 -0.7138 -0.4453

0.2860 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 2.5472 0.2680 9.503 < 2e-16 ***victimw 0.3635 0.3057 1.189 0.23449 defendantw -2.3418 0.2341 -10.003 < 2e-16 ***dpn 2.7269 0.2759 9.885 < 2e-16 ***victimw:defendantw 3.2068 0.2567 12.491 < 2e-16 ***victimw:dpn -0.9406 0.3081 -3.053 0.00227 ** • ---

Page 22: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 22

Testing if the model is adequate

Null deviance: 774.7325 on 7 degrees of freedomResidual deviance: 1.9216 on 2 degrees of freedomAIC: 56.638

Number of Fisher Scoring iterations: 4

> 1-pchisq(1.9216,2) [1] 0.3825867

Model seems OK

Some hint cell 8 not well fitted

Page 23: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 23

Example: the Copenhagen housing data

• 317 apartment residents in Copenhagen were surveyed on their housing. 3 variables were measured:– sat: satisfaction with housing (Low,

medium,high)– cont: amount of contact with other residents

(Low,high)– infl: influence on management decisions– (Low, medium,high)

Page 24: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 24

Copenhagen housing data

sat infl cont count Low Low Low 61 Medium Low Low 23 High Low Low 17 Low Medium Low 43 Medium Medium Low 35 High Medium Low 40 Low High Low 26 Medium High Low 18 High High Low 549 more lines…

Page 25: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 25

Copenhagen housing data

    cont

    Low High

  Low 61 78

sat Medium 23 46

  High 17 43

    cont

    Low High

  Low 43 48

sat Medium 35 45

  High 40 86

    cont

    Low High

  Low 26 15

sat Medium 18 25

  High 54 62

infl = Low infl = Med

infl = High

Page 26: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 26

The analysis > housing.glm<-glm(count~sat*infl*cont, family=poisson, data=housing.df)> anova(housing.glm, test]”Chisq”)Df Deviance Resid. Df Resid. Dev P(>|Chi|)NULL 17 166.757 sat 2 26.191 15 140.566 2.054e-06infl 2 20.040 13 120.526 4.451e-05cont 1 22.544 12 97.983 2.054e-06sat:infl 4 75.577 8 22.406 1.504e-15sat:cont 2 7.745 6 14.661 0.021infl:cont 2 11.986 4 2.675 0.002sat:infl:cont 4 2.675 0 9.546e-15 0.614

This time, only the 3-factor interaction is insignificant.

This is the “homogeneous association model”

Page 27: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 27

Homogeneous association model

• Association between two factors measured by sets of odds ratios

ji

ij

ijOR

11

11

Page 28: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 28

Copenhagen housing OR’s

    cont

    Low High

  Low * *

sat Medium * 1.56

  High * 1.97

    cont

    Low High

  Low * *

sat Medium * 1.15

  High * 1.92

    cont

    Low High

  Low * *

sat Medium * 2.40

  High * 1.99

infl = Low infl = Med

infl = High26 15

18 25

54 62

26*25/(18*15)

26*62/(54*15)

Page 29: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 29

Homogeneous association model (2)

• For the homogeneous association model, the conditional odds ratios for A and B (ie using the conditional distributions of A and B given C=k) do not depend on k. That is, the pattern of association between A and B is the same for all levels of C.

• Common value of the conditional AB Log OR’s are estimated by the AB interactions

Page 30: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 30

Estimating conditional OR for housing data

• Estimated Sat-cont conditional log ORs are estimated with Sat-cont interactions in homogeneous association model

> homogen.glm<-glm(count~sat*infl*cont-sat:infl:cont, family=poisson, data=housing.df)> summary(homogen.glm)Coefficients: Estimate Std. Error z value Pr(>|z|) satMedium:contHigh 0.4157 0.1948 2.134 0.032818 * satHigh:contHigh 0.6496 0.1823 3.563 0.000367 ***

Page 31: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 31

Estimating conditional OR for housing data (2)

• For med/High, est for log OR is 0.4157, std error is 0.1948• CI for OR is exp(0.4157 +/- 1.96* 0.1 0.1948)

i.e. (1.034, 2.220)• Estimated OR for high/high is exp(0.6496) = 1.1914

> 0.4157+c(-1,1)*1.96*0.1948 [1] 0.033892 0.797508> exp(0.4157+c(-1,1)*1.96*0.1948) [1] 1.034473 2.220002> exp(0.4157)[1] 1.515431> exp(0.6496)[1] 1.914775

Page 32: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 32

4 dimensional tables

• Similar results apply for 4-dimensional tables

• For example, models for 4 factors A, B, C and D– A, B, C and D all independent: A + B + C +D – A, B independent of C and D: A*B + C*D– D conditionally independent of C, given A and

B: A*B*C + A*B*D

Page 33: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 33

Hierarchical models

• We will assume that all models are hierarchical: if the model includes an interaction with factors A1, … Ak, then it includes all main effects and interactions that can be formed from A1, … Ak

• We can represent hierarchical models by listing these “maximal interactions”

Page 34: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 34

Examples

• 2 factor model A + B + A:B is hierarchical– Hierarchical notation: [AB]

• 3 factor model A + B + C + A:B is hierarchical– Hierarchical notation: [AB][C]

• 3 factor model A + B + C + A:B + A:C is hierarchical– Hierarchical notation: [AB][AC]

Page 35: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 35

Graphical ModelsA way of visualising independence patterns:• A subset of hierarchical models• Each factor represented by the vertex of an

“association” graph• Two vertices connected by edges if they have a

non-zero interaction• Then

– A vertex not connected to any other vertex is independent of the other vertices

– two vertices not directly connected are conditionally independent, given the connecting vertices

Page 36: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 36

Examples• 2 factor model A + B + A:B or [AB]

• 3 factor model A + B + C +AB or [AB][C] C independent of A and B

• 3 factor model A + B + C + A:B + A:C +B:C or [AB][AC][BC]

A B

A

B C

A

B C

Page 37: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 37

More Examples• 3 factor model

A + B + C + AB + AC

[AB][AC]

• 4 factor model

A + B + C + D + A:B + A:C +B:C

[AB][AC][BC][D]

A

B

D

A

B C

C

Page 38: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 38

Another Example4 factor model

A + B + C + D + A:B + B:C + A:D

[AB][BC][AD]

C and D are conditionally independent given A and B

A

B

D

C

Page 39: © Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28

© Department of Statistics 2012 STATS 330 Lecture 28: Slide 39

Another Example4 factor model

A + B + C + D + A:B:C + A:B:D

[ABC][ABD]

C and D are conditionally independent given A and B

A

B

D

C