categorical data analysis for survey data

46
Categorical Data Analysis for Survey Data Professor Ron Fricker Naval Postgraduate School Monterey, California 1

Upload: others

Post on 25-Dec-2021

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Categorical Data Analysis for Survey Data

Categorical Data Analysis for Survey Data

Professor Ron FrickerNaval Postgraduate School

Monterey, California

1

Page 2: Categorical Data Analysis for Survey Data

Goals for this Lecture

• Under SRS, be able to conduct tests for discrete contingency table data– One-way chi-squared goodness-of-fit tests– Two-way chi-squared tests of

independence• Understand how complex survey

designs affect chi-squared tests– Discuss some ways to correct

2

Page 3: Categorical Data Analysis for Survey Data

Classical Statistical Assumptions…

• …apply for SRS with large population:– Very large (infinite) population– Sample is small fraction of population– Sample is drawn from population via SRS

• …but not with complex sampling• Hence, standard statistical software

generally works for SRS survey designs, but not for complex designs

Page 4: Categorical Data Analysis for Survey Data

One-Way Classifications

• Each respondent gives one of k responses (or put in one of k categories)– Denote counts as x1, x2, …, xk

with x1+ x2 + … + xk = n

Population

Random sample of size n

Response kCell frequency xk

Survey Response / Category

Response 1Cell frequency x1

Response 2Cell frequency x2

4

Page 5: Categorical Data Analysis for Survey Data

One-Way Goodness-of-Fit Test

• Have counts for k categories, x1, x2, …, xk, with x1+ x2 + … + xk = n

• (Unknown) population cell probabilities denoted p1, p2, …, pk with p1+ p2 +…+ pk = 1

• Estimate each cell probability from the observed counts:

• The hypotheses to be tested areˆ / , 1, 2,...,i ip x n i k= =

* * *0 1 1 2 2

*

: , ,...,

: at least one k k

a i i

H p p p p p p

H p p

= = =

≠5

Page 6: Categorical Data Analysis for Survey Data

One-Way Goodness-of-Fit Test for Homogeneity

• Null hypothesis is the probability of each category is equally likely:– I.e., the distribution of category characteristics is

homogeneous in the population• If the null is true, in each cell (in a perfect

world) we would expect to observecounts

• To do a statistical test, must assess how “far away” the ei expected counts are from the xi observed counts

* 1/ , 1, 2,...,ip k i k= =

*i ie np=

6

Page 7: Categorical Data Analysis for Survey Data

Chi-squared Test

• Idea: Look at how far off table counts are from what is expected under the null

• Pearson chi-square test statistic:2

2

1

2

1

(observed expected)expected

( / )/

k

i

ki

i

- X

x - n kn k

=

=

=

=

7

Page 8: Categorical Data Analysis for Survey Data

Alternate Test Statistics

8

• Likelihood ratio test statistic:

• Pearson and likelihood ratio test statistics asymptotically equivalent

• For either statistic, reject if too large– Assess “too large” using chi-squared dist’n

2

1

1

observed2 observed lnexpected

2 ln/

k

i

ki

ii

G

xxn k

=

=

⎛ ⎞= × ⎜ ⎟

⎝ ⎠⎛ ⎞= × ⎜ ⎟⎝ ⎠

Page 9: Categorical Data Analysis for Survey Data

Conducting the Statistical Test

• First calculate X2 or G2 statistic• Then calculate the p-value; e.g.,

• is the chi-squared distribution with k-1 degrees of freedom

• Reject null if p-value < α, for some pre-determined significance level α

21kχ −

2 21-value Pr( )kp Xχ −= ≥

9

Page 10: Categorical Data Analysis for Survey Data

p-value Calculation for Chi-square Goodness-of-Fit Tests

Page 11: Categorical Data Analysis for Survey Data

Simple Example

• Respondents were equally likely to choose any answer on a 5-point Likert scale question

– Survey results:– Expected

under the null:– Pearson

test statistic:

– p-value:

Strongly Agree Agree Neutral Disagree

Strongly Disagree

21 15 19 20 17 n=92

Strongly Agree Agree Neutral Disagree

Strongly Disagree

18.4 18.4 18.4 18.4 18.4

252

1

( 18.4) 1.2618.4

i

i

x - X=

= =∑2

4Pr( 1.26) 0.87νχ = ≥ =

Page 12: Categorical Data Analysis for Survey Data

Goodness-of-Fit Tests for Other Distributions

• Homogeneity is just a special case• Can test whether the s are anything so

long as

• Might have some theory that says what the distribution should be, for example

• Remember, don’t look at that data first and then specify the probabilities…

*ip

*

11

k

ii

p=

=∑

12

Page 13: Categorical Data Analysis for Survey Data

Simple Example

• Theoretical response distribution for question:

– Survey results:– Expected

under the null:– Pearson

test statistic:

– p-value:

Strongly Agree Agree Neutral Disagree

Strongly Disagree

0.05 0.2 0.5 0.2 0.05

Strongly Agree Agree Neutral Disagree

Strongly Disagree

20 60 132 47 17 n=276

Strongly Agree Agree Neutral Disagree

Strongly Disagree

13.8 55.2 138 55.2 13.8

252

1

( ) 5.42i i

i i

x - eXe=

= =∑2

4Pr( 5.42) 0.25νχ = ≥ =

Page 14: Categorical Data Analysis for Survey Data

Doing the Test in JMP and Excel

• Analyze > Distribution– Put nominal variable in “Y, Columns” > OK– Red triangle > “Test Probabilities” > fill in

probabilities to test• Note that if you look in the JMP help, you will

find “goodness of fit” tests– Different test for regression – don’t use

• Chi-square tests also easy to do in Excel– CHIDIST function useful for calculating p-values

14

Page 15: Categorical Data Analysis for Survey Data

A Couple of Notes

• Likelihood ratio and Pearson test statistics usually very close – I tend to focus on Pearson – JMP gives both as output

• Note that Pearson test depends on all cells having sufficiently large expected counts:– If not, collapse across some categories

* 5i ie np= ≥

15

Page 16: Categorical Data Analysis for Survey Data

Chi-square Test of Independence

• Survey of 500 households– Two of the questions:

• Do you own at least one personal computer?• Do you subscribe to cable television

Computer?Yes No

Yes 119 188 307No 88 105 193

207 293 500

Cable?

Page 17: Categorical Data Analysis for Survey Data

Some Notation for Two-Way Contingency Tables

• Table has r rows and c columns• Observed cell counts are xij, with

• Denote row sums:

• Denote column sums:1

, 1,...,r

j iji

x x j c+=

= =∑1

, 1,...,c

i ijj

x x i r+=

= =∑1 1

r c

iji j

x n= =

=∑∑

17

Page 18: Categorical Data Analysis for Survey Data

The Hypotheses

18

• Independence means, for all cells in the table, where– is the probability of having row i

characteristic – is the probability of having column j

characteristic• The hypotheses to be tested are

0 : , 1, 2,..., ; 1, 2,...,

: , for some and ij i j

a ij i j

H p p p i r j c

H p p p i j+ +

+ +

= = =

ij i jp p p+ +=

ip +

jp+

Page 19: Categorical Data Analysis for Survey Data

Pearson Chi-square Test Statistic

• Test statistic:

• Under the null, the expected count is calculated as

22

1 1

( )r cij ij

i j ij

x - eX

e= =

= ∑∑

ˆ ˆ ˆ jiij ij i

j

j

i

xxe np np px x

nn n

n

+++ +

+ +

= = =

×=

19

Page 20: Categorical Data Analysis for Survey Data

Back to the Example

• Assuming independence, we haveComputer?

Yes NoYes 119 188 307No 88 105 193

207 293 500

Cable?

Observed counts:

ExampleYes,

Yes,+307ˆ 0.614500

xp

n+= = =

+,No+,No

293ˆ 0.586500

xp

n= = =

Expected counts:

Computer?

Yes NoYes 127.1 179.9 307No 79.9 113.1 193

207 293 500

Cable?

=Yes, =No Yes, ,Noˆ ˆ

500 0.614 0.586179.9

i je np p+ +=

= × ×=

Page 21: Categorical Data Analysis for Survey Data

Doing the Calculations

• Proceed as with the goodness-of-fit test– Except degrees of freedom are

• Large values of the chi-squared statistic are evidence that the null is false

• JMP does the p-value calculation (as do all stat software packages– Reject null if p-value < α, for some pre-

determined significance level α

( 1)( 1)r cν = − −

21

Page 22: Categorical Data Analysis for Survey Data

Conducting the Test in JMP

• Ensure variables coded as nominal• JMP > Analyze > Fit Y by X, put:

– One variable in as X – Other variable in as Y

p-values

22

Page 23: Categorical Data Analysis for Survey Data

Complex Surveys: What’s the Problem?

• Chi-square distribution of test statistic results from SRS assumption

• Complex survey designs result in incorrect p-values– E.g., Clustered sample designs can result

in incorrectly low p-values• With high intra-class correlation (ICC)

it’s as if the sample size has been artificially inflated

23

Page 24: Categorical Data Analysis for Survey Data

Revisiting Computer/Cable Example

• What if interviewed two individuals in each house and got same answers?

Computer?

Yes NoYes 119 188 307

Cable?No 88 105 193

207 293 500

New data: Computer?

Yes NoYes 238 376 614

Cable?No 176 210 386

414 586 1000

2 4.562X =-value 0.03p =

Original data:2 2.281X =

-value 0.13p =

24

Page 25: Categorical Data Analysis for Survey Data

The Issue

• In complex surveys table counts unlikely to reflect relative frequencies of the categories in the population – Unless sample is self-weighting

• I.e., can’t just plug counts into X2 or G2

calculations:2

2

Allcells

(observed expected)expected

- X =∑

25

Page 26: Categorical Data Analysis for Survey Data

Effects of Stratified Sampling Design on Hypothesis Tests and CIs (1)

• If rows in contingency table correspond to strata, usual chi-square test of homogeneity fine– But may want to test association between

other (non-strata) factors• In general, stratification increases

precision of estimates– E.g., stratified sample of size n gives same

precision for estimating pij as a SRS of size n / dij, where dij is the design effect

26

Page 27: Categorical Data Analysis for Survey Data

Effects of Stratified Sampling Design on Hypothesis Tests and CIs (2)

• Thus p-values for chi-square tests with stratification are conservative– E.g., actual p-value will be smaller than

calculated p-value– Means if null rejected, it is appropriate

• However, if don’t reject but close, how to tell if null should be rejected?

27

Page 28: Categorical Data Analysis for Survey Data

Effects of Clustered Sampling Design on Hypothesis Tests and CIs

• Opposite effect from stratification: p-values artificially low– Means if fail to reject null, it is appropriate

• However, if do reject null, how to tell if null really should be rejected?

• Clustering unaccounted for (in surveys or other data collection) can result in spurious “significant” results

28

Page 29: Categorical Data Analysis for Survey Data

Corrections to Chi-square Tests

• There are a number of ways to fix:– Wald tests– Bonferroni tests– Matching moments– Model-based methods

• See Lohr for the last two – we won’t cover here

29

Page 30: Categorical Data Analysis for Survey Data

Think of Problem in Terms of Cell Probabilities (1)

• Use sampling weights to estimate population quantity

where

• Thus

ˆk kij

k Sij

kk S

w yp

w∈

=∑∑

1 if observation unit is in cell ( , )0 otherwise kij

k i jy

⎧= ⎨⎩

sum of weights for observation units in cell ( , )ˆsum of weights for all observation units in sampleij

i jp =30

Page 31: Categorical Data Analysis for Survey Data

Think of Problem in Terms of Cell Probabilities (2)

• So, using the , construct the table

• Can express thetest statistics as

ˆ ijp

2 222

All All Allcells cells cells

ˆ ˆ( ) ( )(observed expected)expected

ij ij ij ij

ij ij

np - np p - p - X nnp p

= = =∑ ∑ ∑

2

All Allcells cells

ˆobserved ˆ2 observed ln 2 lnexpected

ijij

ij

pG n p

p⎛ ⎞⎛ ⎞

= × = ⎜ ⎟⎜ ⎟ ⎜ ⎟⎝ ⎠ ⎝ ⎠∑ ∑

31

Page 32: Categorical Data Analysis for Survey Data

Wald Tests (1)

• For a 2x2 table, null hypothesis of independence is

• This is equivalent to testing

• Let

, 1 , 2ij i jp p p i j+ += ≤ ≤

0 11 22 12 21

11 22 12 21

: 0: 0a

H p p p pH p p p p

− =− ≠

11 22 12 21ˆ ˆ ˆ ˆ ˆp p p pθ = −

32

Page 33: Categorical Data Analysis for Survey Data

Wald Tests (2)

• Then for large samples, under the null

follows an approximately standard normal distribution

• Equivalently, follows a chi-square distribution with 1 degree of freedom

• Must estimate the variance appropriately

( )ˆ ˆV̂θ θ

( )2ˆ ˆV̂θ θ

( )ˆV θ

33

Page 34: Categorical Data Analysis for Survey Data

Example: Survey of Youth in Custody (1)

• Is there an association between:– “Was anyone in your family ever incarcerated?”– “Have you ever been put on probation or sent to a

correctional institution for a violent offense?”• Sample size: n=2,588 youths• Table with sum of weights:

34

Page 35: Categorical Data Analysis for Survey Data

Example: Survey of Youth in Custody (2)

• Results in the following estimated proportions:

• Test statistic:• How to estimate the variance?

11 22 12 21ˆ ˆ ˆ ˆ ˆ 0.0053p p p pθ = − =

35

Page 36: Categorical Data Analysis for Survey Data

Example: Survey of Youth in Custody (3)

• Use resampling method:• Thus, the standard error

of is• So the test statistic is

• p-value:• Result: No evidence of association

0.0158 7 0.006=θ̂

( )ˆ 0.0053 0.89

0.0060ˆV̂t θ

θ= = =

6Pr( ) 2 Pr( 0.89) 0.41T t Tν => = × > =

36

Page 37: Categorical Data Analysis for Survey Data

Wald Tests for Larger Tables

• Let• Hypotheses are

• Wald test statistic is where is the estimated covariance matrix

• Problem is, need a large number of PSUs to estimate covariance matrix– E.g., 4x4 table results in 9x9 covariance matrix that

requires estimation of 45 variance/covariances37

11 12 ( 1)( 1), ,...,T

r cθ θ θ − −⎡ ⎤= ⎣ ⎦θ

0 :: for one or more cellsa

HH

=≠

θ 0θ 0

2 1ˆ ˆ ˆV̂( )TWX −= θ θ θ ˆV̂( )θ

Page 38: Categorical Data Analysis for Survey Data

Bonferroni Tests (1)

• Alternative to Wald test• Idea is to separately (and conservatively)

test each • Test each of m=(r-1)(c-1) tests separately

at α/m significance level• Reject null that variables are

independent if any of the m separate tests reject

, 1 1, 1 1ij i r j cθ ≤ ≤ − ≤ ≤ −

38

Page 39: Categorical Data Analysis for Survey Data

Bonferroni Tests (2)

• Specifically, reject if

for any i and j, where κ is the appropriate degrees of freedom– Resampling: #resample groups – 1– Another method: #PSUs – #strata

• Lohr says method works well in practice

( ) / 2 ,ˆ ˆV̂ij ij mtα κθ θ >

0 :H =θ 0

39

Page 40: Categorical Data Analysis for Survey Data

Example: Survey of Youth in Custody (1)

• Is there a relationship between age and whether a youth was sent to an institution for a violent offense?

40

Page 41: Categorical Data Analysis for Survey Data

Example: Survey of Youth in Custody (2)

• Hypotheses are

• What happens if clustering ignored?– With n=2,621, we have

which gives an (incorrect) p-value of ~0• Compare to a Bonferroni test…

0 11 11 1 1

12 12 1 2

: 00

H p p pp p p

θθ

+ +

+ +

= − == − =

22 32

1 1

ˆ ˆ ˆ( )34

ˆ ˆij i j

i j i j

p - p pX n

p p+ +

= = + +

= =∑∑

41

Page 42: Categorical Data Analysis for Survey Data

Example: Survey of Youth in Custody (3)

• For these data, and• Using resampling,

we get the table:• And from this,

• Thus

11ˆ 0.013θ = 12

ˆ 0.0119θ =

( )11ˆs.e. 0.0074,θ =

( )12ˆs.e. 0.0035θ =

( ) ( )11 12

11 12

ˆ ˆ1.8, 3.4

ˆ ˆs.e. s.e.

θ θ

θ θ= = 0.05/ 2 2, 6 2.97t ν× = =and

Reject null (more appropriately) 42

Page 43: Categorical Data Analysis for Survey Data

Using SAS to Conduct the Tests

• SAS v8 has some procedures for complex survey analysis (PROC SURVEYMEANSPROC SURVEYREG), but no PROCs for categorical data analysis– PROC FREQ and PROC CATMOD would

incorrectly estimate standard errors• SAS v9.1 has PROC SURVEYFREQ for

categorical data analysis– Can specify various Wald and Rao-Scott tests

• See http://support.sas.com/onlinedoc/913/docMainpage.jsp

43

Page 44: Categorical Data Analysis for Survey Data

Using Stata to Conduct the Tests

• Stata 9: SVY procedures support both one-way and two-way tables– svy:tabulate oneway– svy:tabulate twoway

• Need to order manuals to see which methods used

• See www.stata.com/stata9/svy.html for more detail

44

Page 45: Categorical Data Analysis for Survey Data

Other Software…

• …designed for complex survey analysis include SUDAAN and WestVar– Don’t know if they can do these

calculations or not– See their documentation

• JMP: Cannot do appropriate calculations

45

Page 46: Categorical Data Analysis for Survey Data

What We Have Just Learned

• Tests for contingency table data– For one variable, goodness-of-fit tests– For two variables, tests of independence

• Gained some insight into – What to do about categorical data analysis for

complex designs– How complex designs affect chi-square

hypothesis tests• Learned about some methods to correct for

the sampling design in chi-square tests

46