1 Contingency Tables, Slides of Descriptive statistics

A contingency table is a place where a joint distribution of two categorical variables, say X and Y , where X has I levels and Y has J levels, can be summarized ...

Typology: Slides

2022/2023

Uploaded on 03/01/2023

tomseller
tomseller 🇺🇸

4.6

(16)

271 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 Contingency Tables
1.1 Basics
A contingency table is a place where a joint distribution of two categorical variables, say Xand Y,
where Xhas Ilevels and Yhas Jlevels, can be summarized. It is usual to consider an Xvariable
to be an explanatory variable, and a Yvariable a response variable. Both marginal distributions
and conditional distributions can be of interest. Data that is used can either be offered in raw form
(Format 1) or in summarized form (Format 2) in SPSS.
Example 1
The file HockeyGenderRaw contains two variables. The response variable WatY (Yes-1, No-2) records
whether or not an individual watches hockey and appears in column 1 and the explanatory variable
GenX (Male -1, Female-2) records gender and appears in column 2.
The file WatchHockeyGenderSummarized summarizes the counts of observations for the (GenX,
WatY) pairs (1,1), (1,2), (2,1) and (2,2).
Format 1
WatY GenX
1 1
1 1
.
.
..
.
.
1 2
1 2
.
.
..
.
.
2 1
2 1
.
.
..
.
.
2 2
2 2
.
.
..
.
.
Format 2
WatY GenX Count
1 1 33
1 2 9
2 1 11
2 2 36
When working with raw data with columns of categorical variables, one should create a summary
cross-tab table that counts the groupings. Here are the SPSS commands and output to do so for the
hockey watching and gender raw data.
1. Analyze>Descriptive Statistics>Crosstabs
2. Row(s): GenX
3. Column(s): WatY
4. OK
1
pf3
pf4
pf5

Partial preview of the text

Download 1 Contingency Tables and more Slides Descriptive statistics in PDF only on Docsity!

1 Contingency Tables

1.1 Basics

A contingency table is a place where a joint distribution of two categorical variables, say X and Y , where X has I levels and Y has J levels, can be summarized. It is usual to consider an X variable to be an explanatory variable, and a Y variable a response variable. Both marginal distributions and conditional distributions can be of interest. Data that is used can either be offered in raw form (Format 1) or in summarized form (Format 2) in SPSS.

Example 1 The file HockeyGenderRaw contains two variables. The response variable WatY (Yes-1, No-2) records whether or not an individual watches hockey and appears in column 1 and the explanatory variable GenX (Male -1, Female-2) records gender and appears in column 2. The file WatchHockeyGenderSummarized summarizes the counts of observations for the (GenX, WatY) pairs (1,1), (1,2), (2,1) and (2,2).

Format 1 WatY GenX 1 1 1 1 .. .

Format 2 WatY GenX Count 1 1 33 1 2 9 2 1 11 2 2 36

When working with raw data with columns of categorical variables, one should create a summary cross-tab table that counts the groupings. Here are the SPSS commands and output to do so for the hockey watching and gender raw data.

  1. Analyze>Descriptive Statistics>Crosstabs
  2. Row(s): GenX
  3. Column(s): WatY
  4. OK

1.2 Comparing two categorical variables(each with 2 levels)

It is usual to have X in the row, and Y in the column in a contingency table. Here nij represents the count of observations in the ij-th cell, i = 1, 2 and j = 1, 2, while ni+ is the count in row i, n+j is the count in column j, and n is the total number of observations.

Y

1 2 Total X 1 n 11 n 12 n1+ 2 n 21 n 22 n2+ Total n+1 n+2 n

Conditional Probabilities: P (Y = 1|X = 1) = π 1 with ˆπ 1 = p 1 = n 11 /n1+ P (Y = 1|X = 2) = π 2 with ˆπ 2 = p 2 = n 21 /n2+

ˆ Difference in probabilities π 1 and π 2 :

Wald (1 − α) × 100% confidence interval for π 1 − π 2 : (p 1 − p 2 ) ± zα/ 2

Ê

p 1 (1 − p 1 ) n 1

p 2 (1 − p 2 ) n 2

ˆ Relative Risk rr = π 1 /π 2 , ˆrr = p 1 /p 2 :

(1 − α) × 100% confidence interval for ln(rr): ln(p 1 /p 2 ) ± zα/ 2

Ê

1 − p 1 n 1 p 1

1 − p 1 n 1 p 1 Convert (exponentiate) the endpoints to find a CI for rr.

ˆ Odds Ratio Odds of success(=1) in row i = πi/(1 − πi) Odds Ratio= ϑ = odds 1 /odds 2 MLE for ϑ is ϑˆ = n 11 n 22 /n 12 n 21

(1 − α) × 100% confidence interval for ln(ϑ): ln( ϑˆ) ± zα/ 2

Ê

n 11

n 12

n 21

n 22 Convert (exponentiate) the endpoints to find a CI for odds ratio.

Example 2 From class PCR Relapse Count 1 1 30 1 2 45 2 1 8 2 2 95 PCR can be considered to the explanatory variable, and Relapse the response

SPSS commands and output:

[from output). With 95% confidence we find that the probability of a relapse is between 2.5 and 10. times higher for children with a positive PCR than a negative PCR. Note that 1 is not in the 95% CI, we have sufficient evidence that the probability of a relapse is significantly higher for PCR positive children.

Estimated odds ratio = ϑˆ = n 11 n 22 /n 12 n 21 = (30x95)/(8x45) = 7. 95% CI for odds ratio of a relapse for PCR positive versus PCR negative children falls between (3.361, 18.648) [from output]. With 95% confidence we find that the odds of a relapse is between 3.4 and 18.6 times higher for children with a positive PCR than a negative PCR. Note that 1 is not in the 95% CI, we have significant evidence that a relapse is associated with PCR. The odds of a relapse is 3.361 to 18.648 times higher for the PCR+ group than for the PCR- group.

Mantel-Haenzel Odds Ratio Test SPSS commands and output:

  1. Analysis>Descriptive Statistics>Crosstabs Row(s): PCR Column(s): Relapse Statistics popup: check Cochran’s and Mantel-Haenszel statistics check Test common odds ratio equals: 1 OK Cells popup: Counts: check Observed Percentages: check Row OK OK
  2. H 0 : ϑ = 1 versus Ha : ϑ 6 = 1, α = 0. 05
  3. Random sample (ok), large enough sample (each cell has at least count 5)
  4. z 0 = 2. 069 /.437 = 4. 73
  5. P-value<0.
  6. P-value< α = 0.05, reject H 0
  7. At significance level of 5% the data provide sufficient evidence that the odds ratio of a relapse for PCR positive and negative children is different from 1, indicating a relationship between PCR outcome and relapse.