## Contingency Table | Cross Classification: Introduction

A bivariate relationship is defined by the joint distribution of the two associated random variables.

Contingency Tables

Let $X$ and $Y$ are two categorical response variables. Let variable $X$ have $I$ levels and variable $Y$ have $J$ levels. The possible combinations of classifications for both variables are $I\times J$. The response $(X, Y)$ of a subject randomly chosen from some population has a probability distribution, which can be shown in a rectangular table having $I$ rows (for categories of $X$) and $J$ columns (for categories of $Y$). The cells of this rectangular table represent the $IJ$ possible outcomes. Their probability (say $\pi_{ij}$) denotes the probability that ($X, Y$) falls in the cell in row $i$ and column $j$. When these cells contain frequency counts of outcomes, the table is called contingency or cross-classification table and it is referred to as an $I$ by $J$ ($I \times J$) table.

The probability distribution {$\pi_{ij}$} is the joint distribution of $X$ and $Y$. The marginal distributions are the rows and columns totals obtained by summing the joint probabilities. For the row variable ($X$) the marginal probability is denoted by $\pi_{i+}$ and for column variable ($Y$) it is denoted by $\pi_{+j}$, where the subscript “+” denotes the sum over the index it replaces; that is, $\pi_{i+}=\sum_j \pi_{ij}$ and $\pi_{+j}=\sum_i \pi_{ij}$ satisfying

$\sum_{i} \pi_{i+} =\sum_{j} \pi_{+j} = \sum_i \sum_j \pi_{ij}=1$

Note that the marginal distributions are single-variable information, and do not pertain to association linkages between the variables.

In (many) contingency tables, one variable (say, $Y$) is a response and the other $X$) is an explanatory variable. When $X$ is fixed rather than random, the notation of a joint distribution for $X$ and $Y$ is no longer meaningful. However, for a fixed level of $X$, the variable $Y$ has a probability distribution. It is germane to study how this probability distribution of $Y$ changes as the level of $X$ changes.

## Chi-Square Test of Independence

Chi-square test is a non-parametric test. The assumption of normal distribution in the population is not required for this test. The statistical technique chi-square can be used to find the association (dependencies) between sets of two or more categorical variables by comparing how close the observed frequencies are to the expected frequencies. In other words, a chi square ($\chi^2$) statistic is used to investigate whether the distributions of categorical variables different from one another. Note that the response of categorical variables should be independent from each other. We use the chi-square test for relationship between two nominal scaled variables.

Chi-square test of independence is used as tests of goodness of fit and as tests of independence. In test of goodness of fit, we check whether or not observed frequency distribution is different from the theoretical distribution, while in test of independence we assess, whether paired observations on two variables are independent from each other (from contingency table).

Example: A social scientist sampled 140 people and classified them according to income level and whether or not they played a state lottery in the last month. The sample information is reported below. Is it reasonable to conclude that playing the lottery is related to income level? Use the 0.05 significance level.

 Income Low Middle High Total Played 46 28 21 95 Did not play 14 12 19 45 Total 60 40 40 140

Step by step procedure of testing of hypothesis about association between these two variable is described, below.

Step1:
$H_0$: There is no relationship between income and whether the person played the lottery.
$H_1$: There is relationship between income and whether the person played the lottery.

Step2: Level of Significance 0.05

Step 3: Test statistics (calculations)

 Observed Frequencies ($f_o$) Expected Frequencies ($f_e$) $\frac{(f_o - f_e)^2}{f_e}$ 46 95*60/140= 40.71 $\frac{(46-40.71)^2}{40.71}$ 28 95*40/140= 27.14 $\frac{(28-27.14)^2}{27.14}$ 21 95*40/140= 27.14 $\frac{(21-27.14)^2}{27.14}$ 14 45*60/140= 19.29 $\frac{(14-19.29)^2}{19.29}$ 12 45*40/140= 12.86 $\frac{(12-12.6)^2}{12.86}$ 19 45*40/140= 12.86 $\frac{(19-12.86)^2}{12.86}$ $\chi^2=\sum[\frac{(f_0-f_e)^2}{f_e}]=$ 6.544

Step 4: Critical Region:
Tabular Chi-Square value at 0.05 level of significance and $(r-1) \times (c-1)=(2-1)\times(3-1)=2$ is 5.991.

Step 5: Decision
As calculated Chi-Square value is greater than tabular Chi-Square value, we reject $H_0$, which means that there is relationship between income level and playing the lottery.

Note that there are several types of chi-square test (such as Yates, Likelihood ratio, Portmanteau test in time series) available which depends on the way data was collected and also the hypothesis being tested.