33
Conditional Test Statistics

Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Embed Size (px)

Citation preview

Page 1: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Conditional Test Statistics

Page 2: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

• Suppose that we are considering two Log-linear models and that Model 2 is a special case of Model 1.

• That is the parameters of Model 2 are a subset of the parameters of Model 1.

• Also assume that Model 1 has been shown to adequately fit the data.

Page 3: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

In this case one is interested in testing if the differences in the expected frequencies between Model 1 and Model 2 is simply due to random variation] The likelihood ratio chi-square statistic that achieves this goal is:

2 2 22 1 2 1G G G

1

2

2Expected

ObservedExpected

2 1df df df

Page 4: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Example

Table 1: Cross-Classification of a Sample of 1008 consumers according to: (1) The Softness of the Laundry Used (2) The Previous Use of Detergent Brand M (3) The Temperature of the Laundry Water Used (4) The preference of Detergent Brand X over Brand M in a Consumer Blind Trial. Previous user of M Previous nonuser of M

Water Softness

Brand Preference

High Temperature

Low Temperature

High Temperature

Low Temperature

Soft X 19 57 29 63 M 29 49 27 53 Medium X 23 47 33 66 M 47 55 23 50 Hard X 24 37 42 68 M 43 52 30 42

Page 5: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Model d.f. G2 p - valueAll k-factor models

[1][2][3][4] 18 42.9 0.00083 G2(1)

[12][13][14][23][24][34] 9 9.9 0.35864 G2(2)

[123][124][134][234] 2 0.7 0.70469 G2(3)

[1234] 0 0.0 G2(4)

Goodness of Fit test for the all k-factor models

Model d.f. G2 p - value

two-factor interactions 9 33.0 0.00013 G2(1|2)= G2(1)-G2(2)

three-factor interactions 7 9.2 0.23861 G2(2|3)= G2(2)-G2(3)

four-factor interaction 2 0.7 0.70469 G2(3|4)= G2(3)-G2(4)

Conditional tests for zero k-factor interactions

Page 6: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Conclusions

1. The four factor interaction is not significant G2(3|4) = 0.7 (p = 0.705)

2. The all three factor model provides a significant fit G2(3) = 0.7 (p = 0.705)

3. All the three factor interactions are not significantly different from 0, G2(2|3) = 9.2 (p = 0.239).

4. The all two factor model provides a significant fit G2(2) = 9.9 (p = 0.359)

5. There are significant 2 factor interactions G2(1|2) = 33.0 (p = 0.00083.

Conclude that the model should contain main effects and some two-factor interactions

Page 7: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

There also be a natural sequence of progressively complicated models that one might want to identify.

In the laundry detergent example the variables are:

1. Softness of Laundry Used

2. Previous use of Brand M

3. Temperature of laundry water used

4. Preference of brand X over brand M

Page 8: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

A natural order for increasingly complex models which should be considered might be:

1. [1][2][3][4]

2. [1][3][24]

3. [1][34][24]

4. [13][34][24]

5. [13][234]

6. [134][234]

The all-Main effects model Independence amongst all four variables

Since previous use of brand M may be highly related to preference for brand M][ add first the 2-4 interaction

Brand M is recommended for hot water add 2nd the 3-4 interactionbrand M is also recommended for Soft laundry add 3rd the 1-3 interaction

Add finally some possible 3-factor interactions

Page 9: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Models  d.f. G2

[1][3][24] 17 22.4

[1][24][34] 16 18

[13][24][34] 14 11.9

[13][23][24][34] 13 11.2

[12][13][23][24][34] 11 10.1

[1][234] 14 14.5

[134][24] 10 12.2

[13][234] 12 8.4

[24][34][123] 9 8.4

[123][234] 8 5.6

Likelihood Ratio G2 for various models

Page 10: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Table 2: A Partitioning of the Likelihood Ratio Chi-Square Statistic for Complete Independence (Model (a) = [1][2][3][4], Model (b) = [1][3][24], Model (c) = [1][24][34], Model (d) = [13][24][34], Model (e) = [13][234], Model (f) = [123][234]) Model d.f. G2 Model (a) 18 42.9* Difference between models (b) and (a) 1 20.5* Model (b) 17 22.4 Difference between models (c) and (b) 1 4.4* Model (c) 16 18.0 Difference between models (d) and (c) 2 6.1* Model (d) 14 11.9 Difference between models (e) and (d) 2 3.5 Model (e) 12 8.4 Difference between models (f) and (e) 4 2.8 Model (f) 8 5.6

Page 11: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Stepwise selection procedures

Forward Selection

Backward Elimination

Page 12: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Forward Selection:

Starting with a model that under fits the data, log-linear parameters that are not in the model are added step by step until a model that does fit is achieved.

At each step the log-linear parameter that is most significant is added to the model:

To determine the significance of a parameter added we use the statistic:

G2(2|1) = G2(2) – G2(1)

Model 1 contains the parameter.

Model 2 does not contain the parameter

Page 13: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Backward Selection:

Starting with a model that over fits the data, log-linear parameters that are in the model are deleted step by step until a model that continues to fit the model and has the smallest number of significant parameters is achieved.

At each step the log-linear parameter that is least significant is deleted from the model:

To determine the significance of a parameter deleted we use the statistic:

G2(2|1) = G2(2) – G2(1)

Model 1 contains the parameter.

Model 2 does not contain the parameter

Page 14: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Example: Fitting a Log-linear model – Forward Selection Table: Dyke -Patterson Data - N=1729 individuals classified according to five variables (1) Reading Newspapers (2) Listen to radio (3) Do "solid'" reading (4) Attend Lectures (5) Knowledge regarding cancer

Radio No Radio Solid

Reading No solid Reading

Solid Reading

No solid Reading

Good Poor Good Poor Good Poor Good Poor Newspaper Lectures 23 8 8 4 27 18 7 6 None 102 67 35 59 201 177 75 156 None Lectures 1 3 4 3 3 8 2 10 None 16 16 13 50 67 83 84 393

Page 15: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

MODEL D.F. CHI-SQUARE PROB CHI-SQUARE PROB ----- ---- ---------- ---- ---------- ---- K,L,N,S,R. 26 596.84 0.0000 751.31 0.0000 MODELS FORMED BY ADDING TERMS TO MODEL -- K,L,N,S,R. LIKELIHOOD-RATIO PEARSON MODEL D.F. CHI-SQUARE PROB CHI-SQUARE PROB ----- ---- ---------- ---- ---------- ---- KL,N,S,R. 25 579.68 0.0000 691.18 0.0000 DIFF. DUE TO ADDING KL. 1 17.16 0.0000 KN,L,S,R. 25 491.06 0.0000 533.89 0.0000 DIFF. DUE TO ADDING KN. 1 105.78 0.0000 KS,L,N,R. 25 446.39 0.0000 497.12 0.0000 DIFF. DUE TO ADDING KS. 1 150.45 0.0000 KR,L,N,S. 25 572.59 0.0000 674.61 0.0000 DIFF. DUE TO ADDING KR. 1 24.25 0.0000 K,LN,S,R. 25 575.24 0.0000 688.89 0.0000 DIFF. DUE TO ADDING LN. 1 21.60 0.0000 K,LS,N,R. 25 573.09 0.0000 692.25 0.0000 DIFF. DUE TO ADDING LS. 1 23.74 0.0000 K,LR,N,S. 25 577.89 0.0000 698.17 0.0000 DIFF. DUE TO ADDING LR. 1 18.95 0.0000 K,L,NS,R. 25 343.13 0.0000 383.90 0.0000 DIFF. DUE TO ADDING NS. 1 253.71 0.0000 K,L,NR,S. 25 522.61 0.0000 615.20 0.0000 DIFF. DUE TO ADDING NR. 1 74.23 0.0000 K,L,N,SR. 25 575.76 0.0000 680.88 0.0000 DIFF. DUE TO ADDING SR. 1 21.08 0.0000 STEP 1. BEST MODEL FOUND IS -- K,L,NS,R.

K = knowledge

N = Newspaper

R = Radio

S = Reading

L = Lectures

Page 16: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

KL,NS,R. 24 325.97 0.0000 339.14 0.0000 DIFF. DUE TO ADDING KL. 1 17.16 0.0000 KN,L,NS,R. 24 237.35 0.0000 258.87 0.0000 DIFF. DUE TO ADDING KN. 1 105.78 0.0000 KS,L,NS,R. 24 192.68 0.0000 216.12 0.0000 DIFF. DUE TO ADDING KS. 1 150.45 0.0000 KR,L,NS. 24 318.88 0.0000 329.40 0.0000 DIFF. DUE TO ADDING KR. 1 24.25 0.0000 K,LN,NS,R. 24 321.53 0.0000 341.35 0.0000 DIFF. DUE TO ADDING LN. 1 21.60 0.0000 K,LS,NS,R. 24 319.39 0.0000 348.68 0.0000 DIFF. DUE TO ADDING LS. 1 23.75 0.0000 K,LR,NS. 24 324.18 0.0000 341.62 0.0000 DIFF. DUE TO ADDING LR. 1 18.95 0.0000 K,L,NR,NS. 24 268.90 0.0000 280.86 0.0000 DIFF. DUE TO ADDING NR. 1 74.23 0.0000 K,L,SR,NS. 24 322.05 0.0000 347.33 0.0000 DIFF. DUE TO ADDING SR. 1 21.08 0.0000 STEP 2. BEST MODEL FOUND IS -- KS,L,NS,R.

Page 17: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

KL,KS,NS,R. 23 175.52 0.0000 182.86 0.0000 DIFF. DUE TO ADDING KL. 1 17.16 0.0000 KN,KS,L,NS,R. 23 152.96 0.0000 163.87 0.0000 DIFF. DUE TO ADDING KN. 1 39.72 0.0000 KR,KS,L,NS. 23 168.43 0.0000 173.32 0.0000 DIFF. DUE TO ADDING KR. 1 24.25 0.0000 KS,LN,NS,R. 23 171.08 0.0000 184.56 0.0000 DIFF. DUE TO ADDING LN. 1 21.60 0.0000 LS,KS,NS,R. 23 168.93 0.0000 202.28 0.0000 DIFF. DUE TO ADDING LS. 1 23.74 0.0000 KS,LR,NS. 23 173.73 0.0000 178.08 0.0000 DIFF. DUE TO ADDING LR. 1 18.95 0.0000 KS,L,NR,NS. 23 118.45 0.0000 128.83 0.0000 DIFF. DUE TO ADDING NR. 1 74.23 0.0000 SR,KS,L,NS. 23 171.60 0.0000 198.23 0.0000 DIFF. DUE TO ADDING SR. 1 21.08 0.0000 STEP 3. BEST MODEL FOUND IS -- KS,L,NR,NS.

Page 18: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

LN,KL,SR,KR,KN,LR,LS,KS,NR,NS. 16 19.56 0.2406 21.21 0.1706 DIFF. DUE TO ADDING SR. 1 0.42 0.5147 KLN,KR,LR,LS,KS,NR,NS. 16 18.86 0.2762 21.53 0.1589 DIFF. DUE TO ADDING KLN. 1 1.13 0.2878 LN,KLS,KR,KN,LR,NR,NS. 16 15.99 0.4538 15.63 0.4794 DIFF. DUE TO ADDING KLS. 1 4.00 0.0456 LN,KLR,KN,LS,KS,NR,NS. 16 19.28 0.2543 20.81 0.1860 DIFF. DUE TO ADDING KLR. 1 0.70 0.4015 LN,KL,KR,KNS,LR,LS,NR. 16 16.78 0.4000 18.74 0.2821 DIFF. DUE TO ADDING KNS. 1 3.21 0.0733 LN,KL,KNR,LR,LS,KS,NS. 16 19.90 0.2247 21.27 0.1682 DIFF. DUE TO ADDING KNR. 1 0.09 0.7704 LNS,KL,KR,KN,LR,KS,NR. 16 19.58 0.2397 20.98 0.1794 DIFF. DUE TO ADDING LNS. 1 0.41 0.5239 LNR,KL,KR,KN,LS,KS,NS. 16 18.11 0.3176 18.80 0.2790 DIFF. DUE TO ADDING LNR. 1 1.88 0.1706 STEP 10. BEST MODEL FOUND IS -- LN,KLS,KR,KN,LR,NR,NS.

Continuing after 10 steps

Page 19: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

LN,SR,KLS,KR,KN,LR,NR,NS. 15 15.55 0.4127 15.15 0.4406 DIFF. DUE TO ADDING SR. 1 0.44 0.5072 KLN,KLS,KR,LR,NR,NS. 15 12.98 0.6041 13.84 0.5379 DIFF. DUE TO ADDING KLN. 1 3.01 0.0827 LN,KLR,KLS,KN,NR,NS. 15 15.10 0.4446 15.06 0.4471 DIFF. DUE TO ADDING KLR. 1 0.89 0.3446 LN,KNS,KLS,KR,LR,NR. 15 13.21 0.5861 13.19 0.5878 DIFF. DUE TO ADDING KNS. 1 2.78 0.0955 LN,KLS,KNR,LR,NS. 15 15.93 0.3870 15.48 0.4173 DIFF. DUE TO ADDING KNR. 1 0.06 0.8034 LNS,KLS,KR,KN,LR,NR. 15 15.87 0.3905 15.60 0.4089 DIFF. DUE TO ADDING LNS. 1 0.12 0.7343 LNR,KLS,KR,KN,NS. 15 14.23 0.5085 13.75 0.5446 DIFF. DUE TO ADDING LNR. 1 1.76 0.1842 STEP 11. BEST MODEL FOUND IS -- KLN,KLS,KR,LR,NR,NS.

The final step

Page 20: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

The best model was found a the previous step

• [LN][KLS][KR][KN][LR][NR][NS]

Page 21: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Logit Models

To date we have not worried whether any of the variables were dependent of independent variables.

The logit model is used when we have a single binary dependent variable.

Page 22: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Example: Logit Models Table: The Effect of planting depth on mortality of Pine seedlings Longleaf Seedlings Slash Seedlings

Depth of Planting Dead Alive Totals Dead Alive Totals Too High 41 59 100 12 88 100 Too Low 11 89 100 5 95 100

Totals 52 148 200 17 183 200 Table: Loglinear Models Fit to Data in Above Table and their Goodness of Fit Statistics Model 2 G2 df [12][13][23] 1.37 1.28 1 [13][23] 26.54 27.79 2 [12][13] 24.03 25.03 2 [13][2] 54.70 50.10 3

Page 23: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

The variables

1. Type of seedling (T)a. Longleaf seedlingb. Slash seedling

2. Depth of planting (D)a. Too low.b. Too high

3. Mortality (M) (the dependent variable)a. Deadb. Alive

Page 24: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

The Log-linear Model

Note: ij1 = # dead when T = i and D = j.

ln ijk T i D j M ku u u u

, , , , ,TD i j TM i k DM j k TDM i j ku u u u

ij2 = # alive when T = i and D = j.

1

2

ij

ij

dead

alive

= mortality ratio when T = i and D = j.

Page 25: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Hence

1T i D j Mu u u u

, ,1 ,1 , ,1TD i j TM i DM j TDM i ju u u u

11 2

2

ln ln ln log-mortality ratioijij ij

ij

since

2T i D j Mu u u u

, ,2 ,2 , ,2TD i j TM i DM j TDM i ju u u u

1 ,1 ,1 , ,12 2 2 2M TM i DM j TDM i ju u u u

2 1 ,2 ,1, ,M M TM i TM iu u u u

,2 ,1 , ,2 , ,1,DM j DM j TDM i j TDM i ju u u u

Page 26: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

The logit model:1

1 22

ln ln ln log-mortality ratioijij ij

ij

where

,T i D j TD i jv v v v

1 ,1 ,12 , 2 , 2 , andM T i TM i D j DM jv u v u v u

, , ,12TD i j TDM i jv u

Page 27: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Thus corresponding to a loglinear model there is logit model predicting log ratio of expected frequencies of the two categories of the independent variable.

Also k +1 factor interactions with the dependent variable in the loglinear model determine k factor interactions in the logit model

k + 1 = 1 constant term in logit model

k + 1 = 2, main effects in logit model

Page 28: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Example: Logit Models Table: The Effect of planting depth on mortality of Pine seedlings Longleaf Seedlings Slash Seedlings

Depth of Planting Dead Alive Totals Dead Alive Totals Too High 41 59 100 12 88 100 Too Low 11 89 100 5 95 100

Totals 52 148 200 17 183 200 Table: Loglinear Models Fit to Data in Above Table and their Goodness of Fit Statistics Model 2 G2 df [12][13][23] 1.37 1.28 1 [13][23] 26.54 27.79 2 [12][13] 24.03 25.03 2 [13][2] 54.70 50.10 3

1 = Depth, 2 = Mort, 3 = Type

Page 29: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Log-Linear parameters for Model: [TM][TD][DM]Main Effects: Mort Mort ------ Dead Alive ------------------- -0.946 0.946 Type Type ------ Lleaf Slash ------------------- 0.240 -0.240 Depth Depth ------ low high ------------------- 0.257 -0.257

Two-Factor Interactions: Type-Mort Type Mort ------ ------ Dead Alive --------------------------- Lleaf 0.354 -0.354 Slash -0.354 0.354

Depth-Mort Depth Mort ------ ------ Dead Alive --------------------------- low 0.376 -0.376 high -0.376 0.376 Mort -Type Depth Type ------ ------ Lleaf Slash --------------------------- low -0.063 0.063 high 0.063 -0.063

Page 30: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Logit Model for predicting the Mortality

ln D i T kMR v v v

D i T kv vvdeadMR e e e

alive or

Log-Linear Logit Mult

const -0.946 -1.892 0.151Depth- High 0.354 0.708 2.030

Low -0.354 -0.708 0.493Type-Long 0.376 0.752 2.121

Slash -0.376 -0.752 0.471

Page 31: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

Example: Fitting a Log-linear model – Forward Selection Table: Dyke -Patterson Data - N=1729 individuals classified according to five variables (1) Reading Newspapers (2) Listen to radio (3) Do "solid'" reading (4) Attend Lectures (5) Knowledge regarding cancer

Radio No Radio Solid

Reading No solid Reading

Solid Reading

No solid Reading

Good Poor Good Poor Good Poor Good Poor Newspaper Lectures 23 8 8 4 27 18 7 6 None 102 67 35 59 201 177 75 156 None Lectures 1 3 4 3 3 8 2 10 None 16 16 13 50 67 83 84 393

Page 32: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

The best model was found by forward selection was

[LN][KLS][KR][KN][LR][NR][NS]

To fit a logit model to predict K (Knowledge) we need to fit a loglinear model with important interactions with K (knowledge), namely

[LNRS][KLS][KR][KN]

The logit model will contain

Main effects for L (Lectures), N (Newspapers), R (Radio), and S (Reading)

Two factor interaction effect for L and S

Page 33: Conditional Test Statistics. Suppose that we are considering two Log- linear models and that Model 2 is a special case of Model 1. That is the parameters

The Logit Parameters for the Model : LNSR, KLS, KR, KN ( Multiplicative effects are given in brackets, Logit Parameters = 2 Loglinear parameters)The Constant term:

-0.226 (0.798)The Main effects on Knowledge:Lectures Lect 0.268 (1.307)

None -0.268 (0.765)Newspaper News 0.324 (1.383)

None -0.324 (0.723)Reading Solid 0.340 (1.405)

Not -0.340 (0.712)Radio Radio 0.150 (1.162)

None -0.150 (0.861)

The Two-factor interaction Effect of Reading and Lectures on Knowledge

Reading Lectures Solid Not

Lect -0.180 (0.835) 0.180 (1.197) None 0.180 (1.197) -0.180 (0.835)

ratiogood

Kpoor