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

Slides:



Advertisements
Similar presentations
© Department of Statistics 2012 STATS 330 Lecture 32: Slide 1 Stats 330: Lecture 32.
Advertisements

The Analysis of Categorical Data. Categorical variables When both predictor and response variables are categorical: Presence or absence Color, etc. The.
1 SSS II Lecture 1: Correlation and Regression Graduate School 2008/2009 Social Science Statistics II Gwilym Pryce
1 Contingency Tables: Tests for independence and homogeneity (§10.5) How to test hypotheses of independence (association) and homogeneity (similarity)
Chap 9: Testing Hypotheses & Assessing Goodness of Fit Section 9.1: INTRODUCTION In section 8.2, we fitted a Poisson dist’n to counts. This chapter will.
Copyright ©2011 Brooks/Cole, Cengage Learning More about Inference for Categorical Variables Chapter 15 1.
The Multiple Regression Model Prepared by Vera Tabakova, East Carolina University.
Making Inferences for Associations Between Categorical Variables: Chi Square Chapter 12 Reading Assignment pp ; 485.
Final Review Session.
Chi-square Test of Independence
Lecture 16 – Thurs, Oct. 30 Inference for Regression (Sections ): –Hypothesis Tests and Confidence Intervals for Intercept and Slope –Confidence.
Copyright (c) 2004 Brooks/Cole, a division of Thomson Learning, Inc. Chapter 14 Goodness-of-Fit Tests and Categorical Data Analysis.
Aaker, Kumar, Day Seventh Edition Instructor’s Presentation Slides
Inferences About Process Quality
1 1 Slide © 2003 South-Western/Thomson Learning™ Slides Prepared by JOHN S. LOUCKS St. Edward’s University.
5-3 Inference on the Means of Two Populations, Variances Unknown
Review for Exam 2 Some important themes from Chapters 6-9 Chap. 6. Significance Tests Chap. 7: Comparing Two Groups Chap. 8: Contingency Tables (Categorical.
1 1 Slide © 2008 Thomson South-Western. All Rights Reserved Slides by JOHN LOUCKS & Updated by SPIROS VELIANITIS.
Presentation 12 Chi-Square test.
AS 737 Categorical Data Analysis For Multivariate
Aaker, Kumar, Day Ninth Edition Instructor’s Presentation Slides
Chapter 13: Inference in Regression
© Department of Statistics 2012 STATS 330 Lecture 28: Slide 1 Stats 330: Lecture 28.
© Department of Statistics 2012 STATS 330 Lecture 26: Slide 1 Stats 330: Lecture 26.
BPS - 3rd Ed. Chapter 211 Inference for Regression.
6.1 - One Sample One Sample  Mean μ, Variance σ 2, Proportion π Two Samples Two Samples  Means, Variances, Proportions μ 1 vs. μ 2.
Chi-square Test of Independence Hypotheses Neha Jain Lecturer School of Biotechnology Devi Ahilya University, Indore.
Chapter 11 Chi-Square Procedures 11.3 Chi-Square Test for Independence; Homogeneity of Proportions.
+ Chapter 12: Inference for Regression Inference for Linear Regression.
Chapter 9: Non-parametric Tests n Parametric vs Non-parametric n Chi-Square –1 way –2 way.
Multinomial Distribution
Maximum Likelihood Estimator of Proportion Let {s 1,s 2,…,s n } be a set of independent outcomes from a Bernoulli experiment with unknown probability.
1 Lecture 4 Main Tasks Today 1. Review of Lecture 3 2. Accuracy of the LS estimators 3. Significance Tests of the Parameters 4. Confidence Interval 5.
April 4 Logistic Regression –Lee Chapter 9 –Cody and Smith 9:F.
+ Chapter 12: More About Regression Section 12.1 Inference for Linear Regression.
© Department of Statistics 2012 STATS 330 Lecture 31: Slide 1 Stats 330: Lecture 31.
EMIS 7300 SYSTEMS ANALYSIS METHODS FALL 2005 Dr. John Lipp Copyright © Dr. John Lipp.
Copyright © 2013, 2009, and 2007, Pearson Education, Inc. Chapter 13 Multiple Regression Section 13.3 Using Multiple Regression to Make Inferences.
Interval Estimation and Hypothesis Testing Prepared by Vera Tabakova, East Carolina University.
© Department of Statistics 2012 STATS 330 Lecture 20: Slide 1 Stats 330: Lecture 20.
CHI SQUARE TESTS.
STA 286 week 131 Inference for the Regression Coefficient Recall, b 0 and b 1 are the estimates of the slope β 1 and intercept β 0 of population regression.
Copyright © 2010 Pearson Education, Inc. Slide
Lecture 3: Statistics Review I Date: 9/3/02  Distributions  Likelihood  Hypothesis tests.
Multiple Regression. Simple Regression in detail Y i = β o + β 1 x i + ε i Where Y => Dependent variable X => Independent variable β o => Model parameter.
Chapter Outline Goodness of Fit test Test of Independence.
© Department of Statistics 2012 STATS 330 Lecture 30: Slide 1 Stats 330: Lecture 30.
N318b Winter 2002 Nursing Statistics Specific statistical tests Chi-square (  2 ) Lecture 7.
1 1 Slide © 2011 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole.
Copyright © Cengage Learning. All rights reserved. Chi-Square and F Distributions 10.
© Department of Statistics 2012 STATS 330 Lecture 22: Slide 1 Stats 330: Lecture 22.
Section 12.2: Tests for Homogeneity and Independence in a Two-Way Table.
Making Comparisons All hypothesis testing follows a common logic of comparison Null hypothesis and alternative hypothesis – mutually exclusive – exhaustive.
Chapter 15 The Chi-Square Statistic: Tests for Goodness of Fit and Independence PowerPoint Lecture Slides Essentials of Statistics for the Behavioral.
The Practice of Statistics, 5th Edition Starnes, Tabor, Yates, Moore Bedford Freeman Worth Publishers CHAPTER 12 More About Regression 12.1 Inference for.
© Department of Statistics 2012 STATS 330 Lecture 24: Slide 1 Stats 330: Lecture 24.
1 1 Slide © 2008 Thomson South-Western. All Rights Reserved Chapter 12 Tests of Goodness of Fit and Independence n Goodness of Fit Test: A Multinomial.
The p-value approach to Hypothesis Testing
BPS - 5th Ed. Chapter 231 Inference for Regression.
The Practice of Statistics, 5th Edition Starnes, Tabor, Yates, Moore Bedford Freeman Worth Publishers CHAPTER 12 More About Regression 12.1 Inference for.
Chapter 11: Categorical Data n Chi-square goodness of fit test allows us to examine a single distribution of a categorical variable in a population. n.
Copyright © Cengage Learning. All rights reserved. 14 Goodness-of-Fit Tests and Categorical Data Analysis.
CHAPTER 12 More About Regression
CHAPTER 12 More About Regression
Review for Exam 2 Some important themes from Chapters 6-9
Chapter 10 Analyzing the Association Between Categorical Variables
CHAPTER 12 More About Regression
CHAPTER 12 More About Regression
Modeling Ordinal Associations Bin Hu
Presentation transcript:

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

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 2 Plan of the day In today’s lecture we apply Poisson regression to the analysis of one and two- dimensional contingency tables. Topics –Contingency tables –Sampling models –Equivalence of Poisson and multinomial –Correspondence between interactions and independence

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 3 Contingency tables Contingency tables arise when we classify a number of individuals into categories using one or more criteria. Result is a cross-tabulation or contingency table –1 criterion gives a 1-dimensional table –2 criteria give a 2 dimensional table –… and so on.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 4 Example: one dimension Income distribution of New Zealanders census $5,000 or Less $5,001 - $10,000 $10,001 - $20,000 $20,001 - $30,000 $30,001 - $50,000 $50,001 or More Not Stated Total Personal Income 383, , , , , , ,892 3,160,371

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 5 Example 2: 2 dimensions New Zealanders 15+ by annual income and sex: 2006 census $10,000 and under $10,001- $20,000 20, ,000 $40,001- $70,000 $70,001 - $100,000 $100,001 or MoreNot Stated Total Personal Income Male232,620232,884407,466331,32090,17782,701144,4201,521,591 Female377,754383,097431,565212,13934,93822,821176,4721,638,783 Total610,374615,981839,031543,459125,115105,522320,8923,160,374

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 6 Censuses and samples Sometimes tables come from a census Sometimes the table comes from a random sample from a population –In this case we often want to draw inferences about the population on the basis of the sample e.g.is income independent of sex?

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 7 Example: death by falling The following is a random sample of 16,976 persons who met their deaths in fatal falls, selected from a larger population of deaths from this cause. The falls classified by month are Jan1688July1406 Feb1407Aug1446 Mar1370Sep1322 Apr1309Oct1363 May1341Nov1410 Jun1388Dec1526

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 8 The question Question: if we regard this as a random sample from several years, are the months in which death occurs equally likely? Or is one month more likely than the others? To answer this, we use the idea of maximum likelihood. First, we must detour into sampling theory in order to work out the likelihood

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 9 Sampling models There are two common models used for contingency tables The multinomial sampling model assumes that a fixed number of individuals from a random sample are classified with fixed probabilities of being assigned to the different “cells”. The Poisson sampling model assumes that the table entries have independent Poisson distributions

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 10 Multinomial sampling

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 11 Multinomial model Suppose a table has M “cells” n individuals classified independently (A.k.a. sampling with replacement) Each individual has probability  i of being in cell i Every individual is classified into exactly 1 cell, so  1 +   M = 1 Let Y i be the number in the ith cell, so Y 1 + Y Y M = n

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 12 Multinomial model (cont) Y 1,...,Y m have a multinomial distribution This is the maximal model, as in logistic regression, making no assumptions about the probabilities.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 13 Log-likelihood

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 14 MLE’s If there are no restrictions on the  ’s (except that they add to one) the log- likelihood is maximised when  i = y i /n These are the MLE’s for the maximal model Substitute these into the log-likelihood to get the maximum value of the maximal log-likelihood. Call this Log L max

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 15 Deviance Suppose we have some model for the probabilities: this will specify the form of the probabilities, perhaps as functions of other parameters. In our example, the model says that each probability is 1/12. Let log L mod be the maximum value of the log- likelihood, when the probabilities are given by the model. As for logistic regression, we define the deviance as D = 2log L max - 2 log L mod

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 16 Deviance:Testing adequacy of the model If n is large (all cells more than 5) and M is small, and if the model is true, the deviance will have (approximately) a chi-square distribution with M-k-1 df, where k is the number of unknown parameters in the model. Thus, we accept the model if the deviance p- value is more than This is almost the same as the situation in logistic regression with strongly grouped data. These tests are an alternative form of the chi- square tests used in stage 2.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 17 Example: death by falling Are deaths equally likely in all months? In statistical terms, is  i =1/12, i=1,2,…,12? Log L max is, up to a constant, Calculated in R by >y<-c(1688,1407,1370,1309,1341,1388, 1406,1446,1322,1363, 1410,1526) > sum(y*log(y/sum(y))) [1]

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 18 Example: death by falling Our model is  i =1/12, i=1,2,…,12. (all months equally likely). This completely specifies the probabilities, so k=0, M-k-1=11. Log L mod is, up to a constant, > sum(y*log(1/12)) [1] # now calculate deviance > D<-2*sum(y*log(y/sum(y)))-2*sum(y*log(1/12)) > D [1] > 1-pchisq(D,11) [1] e-13 Model is not plausible!

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 19 > Months<-c("Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec") > barplot(y/(sum(y),names.arg=Months)

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 20 Poisson model Assume that each cell is Poisson with a different mean: this is just a Poisson regression model, with a single explanatory variable “month” This is the maximal model The null model is the model with all means equal Null model deviance will give us a test that all months have the same mean

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 21 > months<-c("Jan","Feb","Mar","Apr","May", "Jun","Jul","Aug","Sep","Oct","Nov","Dec") > months.fac<-factor(months,levels=months) > falls.glm<-glm(y~months.fac,family=poisson) > summary(falls.glm) R-code for Poisson regression

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 22 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) < 2e-16 *** months.facFeb e-07 *** months.facMar e-09 *** months.facApr e-12 *** months.facMay e-10 *** months.facJun e-08 *** months.facJul e-07 *** months.facAug e-05 *** months.facSep e-11 *** months.facOct e-09 *** months.facNov e-07 *** months.facDec ** Null deviance: e+01 on 11 degrees of freedom Residual deviance: e-14 on 0 degrees of freedom > D [1] Same as before! Why????

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 23 General principle: To every Poisson model for the cell counts, there corresponds a multinomial model, obtained by conditioning on the table total. Suppose the Poisson means are  1, …  M.... The cell probabilities in the multinomial sampling model are related to the means in the Poisson sampling model by the relationship  i =  i /(  1 + … +  M ) We can estimate the parameters in the multinomial model by fitting the Poisson model and using the relationship above. We can test hypotheses about the multinomial model by testing the equivalent hypothesis in the Poisson regression model.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 24 Example: death by falling Poisson means are

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 25 Relationship between Poisson means and multinomial probs

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 26 Relationship between Poisson parameters and multinomial probs – alternative form

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 27 Testing all months equal Clearly, all months hav equal probabilities if and only if all the deltas are zero. Thus, testing for equal months in the multinomial model is the same as testing for deltas all zero in the Poisson model. This is done using the null model deviance, or, equivalently, the anova table. Recall: The null deviance was e+01 on 11 degrees of freedom, with a p-value of e-13, so months not equally likely

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 28 2x2 tables Relationship between Snoring and Nightmares: Data from a random sample, classified according to these 2 factors Nightmare = Frequently Nightmare = Occasionally Snorer = N 1182 Snorer = Y 1274

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 29 Parametrising the 2x2 table of Poisson means Nightmare = frequentlyNightmare = occasionally Snorer =N  1 = exp  Int   2 =exp  Int  Snorer =Y  3 =exp  Int  4 =exp  Int  Main effect of Nightmare Snoring/nightmare interaction Main effect of Snoring

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 30 Parameterising the 2x2 table of probabilities Nightmare = frequently Nightmare = occasionally All Snorer =N       Snorer =Y       All          Marginal distn of Snorer Marginal distn of Nightmare

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 31 Relationship between multinomial probabilities and Poisson parameters

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 32 Independence Events A and B are independent if the conditional probability that A occurs, given B occurs, is the same as the unconditional probability of A occuring. i.e. P(A|B)=P(A). Since P(A|B)=P(A and B)/P(B), this is equivalent to P(A and B) = P(A) P(B)

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 33 Independence in a 2 x2 table Independence of nightmares and snoring means P(Snoring and frequent nightmares)= P(Snoring) x P(frequent nightmares) (plus similar equations for the other 3 cells) Or,  1 =(  1 +  2 ) (  1 +  3 ) In fact, this equation implies the other 3 for a 2 x 2 table

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 34 Independence in a 2x2 table (cont) Three equivalent conditions for independence in the 2 x 2 table  1 =(  1 +  2 ) (  1 +  3 )  1  4 =  2  3  = 0 (ie zero interaction in Poisson model) Thus, we can test independence in the multinomial model by testing for zero interaction in the Poisson regression.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 35 Math stuff

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 36 More math stuff

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 37 Odds ratio Prob of not being a snorer for “frequent nightmares” population is        Prob of being a snorer for “frequent nightmares” population is        Odds of not being a snorer for “frequent nightmares” population is (              =     Similarly, the odds of not being a snorer for “occasional nightmares” population is    

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 38 Odds ratio (2) Odds ratio (OR) is the ratio of these 2 odds. Thus OR =                  OR = exp(  ), log(OR) =  OR =1 (i.e. log (OR) =0 ) if and only if snoring and nightmares are independent Acts like a “correlation coefficient” between factors, with 1 corresponding to no relationship Interchanging rows (or columns) changes OR to 1/OR

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 39 Odds ratio (3) Get a CI for the OR by –Getting a CI for  –“Exponentiating” CI for  is estimate +/ standard error Get estimate, standard error from Poisson regression summary

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 40 Example: snoring > y<-c(11,82,12,74) > nightmares<-factor(rep(c("F","O"),2)) > snore<-factor(rep(c("N","Y"),c(2,2))) > snoring.glm<-glm(y~nightmares*snore,family=poisson) > anova(snoring.glm, test="Chisq") Analysis of Deviance Table Model: poisson, link: log Response: y Df Deviance Resid. Df Resid. Dev P(>|Chi|) NULL nightmares <2e-16 *** snore nightmares:snore No evidence of association between nightmares and snoring.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 41 Odds ratio Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) e-15 *** nightmaresO e-10 *** snoreY nightmaresO:snoreY Estimate of  is , standard error is , so CI for  is / * , or ( , ,) CI for OR = exp(  ) is (exp( ), exp(0.6868) ) = ( , )

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 42 The general I x J table Example: In the 1996 general Social Survey, the National center for Opinion Research collected data on the following variables from 2726 respondents: –Education: Less than high school, High school, Bachelors or graduate –Religious belief: Fundamentalist, moderate or liberal. Cross-classification is

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 43 Education and Religious belief Religious belief EducationFundamentalistModerateLiberalTotal Less than high school High school or junior college Bachelor or graduate Total

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 44 Testing independence in the general 2-dimensional table We have a two-dimensional table, with the rows corresponding to Education, having I=3 levels, and the columns corresponding to Religious Belief, having J=3 levels. Under the Poisson sampling model, let  ij be the mean count for the i,j cell Split log  ij into overall level, main effects, interactions as usual

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 45 Testing independence in the general 2-dimensional table (ii) Under the corresponding multinomial sampling model, let  ij be the probability that a randomly chosen individual has level i of Education and level j of Religious belief, and so is classified into the i,j cell of the table. Then, as before

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 46 Testing independence (iii) Let  i+ =  i1 + … +  iJ be the marginal probabilities: the probability that Education=i. Let  + j be the same thing for Religious belief The factors are independent if  ij =  i+  +j This is equivalent to (  ) ij = 0 for all i,j.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 47 Testing independence (iv) Now we can state the principle: We can test independence in the multinomial sampling model by fitting a Poisson regression with interacting factors, and testing for zero interaction.

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 48 Doing it in R counts = c(178, 570, 138, 138, 648, 252, 108,442, 252) example.df = data.frame(y = counts, expand.grid(education = c("LessThanHighSchool", "HighSchool", "Bachelor"), religion = c("Fund", "Mod", "Lib"))) levels(example.df$education) = c("LessThanHighSchool", "HighSchool", "Bachelor") levels(example.df$religion) = c("Fund", "Mod", "Lib") example.glm = glm(y~education*religion, family=poisson, data=example.df) anova(example.glm, test="Chisq")

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 49 The data > example.df y education religion LessThanHighSchool Fund HighSchool Fund Bachelor Fund LessThanHighSchool Mod HighSchool Mod Bachelor Mod LessThanHighSchool Lib HighSchool Lib Bachelor Lib

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 50 The analysis > example.glm = glm(y~education*religion, family=poisson, data=example.df) > anova(example.glm, test="Chisq") Analysis of Deviance Table Model: poisson, link: log Response: y Terms added sequentially (first to last) Df Deviance Resid. Df Resid. Dev P(>|Chi|) NULL education e-198 religion e-07 education:religion e e-14 Degrees of freedom P-value Chisq Small p-value is evidence against independence

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 51 Odds ratios In a general I x J table, the relationship between the factors is described by a set of (I-1) x (J-1) odds ratios, defined by

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 52 Interpretation Consider sub-table of all individuals having levels 1 and i of education, and levels 1 and j of religious belief  11 1j1j … i1i1  ij Row i Column j

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 53 Interpretation (cont) Odds of being Education 1 at level 1 of Religious belief are  11 /  i1 Odds of being Education 1 at level j of Religious belief are  1j /  ij Odds ratio is (  11 /  i1 )/(  1j /  ij ) = (  ij  11 )/(  i1  1j )

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 54 Odds Ratio facts Main facts 1.A and B are independent iff all the odds ratios equal to 1 2.Log (OR ij ) = (  ) ij 3.Estimate OR ij by exponentiating the corresponding interaction in the Poisson summary 4.Get CI by exponentiating CI for interaction

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 55 Numerical example: odds ratios FundModLib Less than HS*** High school* 1.466= exp( ) 1.278= exp( ) Bachelor* 2.355= exp( ) 3.010= exp( ) Coefficients: Estimate Std. Error educationHighSchool:religionMod educationBachelor:religionMod educationHighSchool:religionLib educationBachelor:religionLib

© Department of Statistics 2012 STATS 330 Lecture 27: Slide 56 Confidence interval Estimate of log(OR Bach/Lib) is , standard error is , so CI is / * , or ( ) CI for OR is exp( , ) = , Odds for having a bachelor’s degree versus no high school are about 3 times higher for Liberals than fundamentalists