Hubbry Logo
Contingency tableContingency tableMain
Open search
Contingency table
Community hub
Contingency table
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Contingency table
Contingency table
from Wikipedia

In statistics, a contingency table (also known as a cross tabulation or crosstab) is a type of table in a matrix format that displays the multivariate frequency distribution of the variables. They are heavily used in survey research, business intelligence, engineering, and scientific research. They provide a basic picture of the interrelation between two variables and can help find interactions between them. The term contingency table was first used by Karl Pearson in "On the Theory of Contingency and Its Relation to Association and Normal Correlation",[1] part of the Drapers' Company Research Memoirs Biometric Series I published in 1904.

A crucial problem of multivariate statistics is finding the (direct-)dependence structure underlying the variables contained in high-dimensional contingency tables. If some of the conditional independences are revealed, then even the storage of the data can be done in a smarter way (see Lauritzen (2002)). In order to do this one can use information theory concepts, which gain the information only from the distribution of probability, which can be expressed easily from the contingency table by the relative frequencies.

A pivot table is a way to create contingency tables using spreadsheet software.

Example

[edit]

Suppose there are two variables, sex (male or female) and handedness (right- or left-handed). Further suppose that 100 individuals are randomly sampled from a very large population as part of a study of sex differences in handedness. A contingency table can be created to display the numbers of individuals who are male right-handed and left-handed, female right-handed and left-handed. Such a contingency table is shown below.

Handed-
ness
Sex
Right-handed Left-handed Total
Male 43 9 52
Female 44 4 48
Total 87 13 100

The numbers of the males, females, and right- and left-handed individuals are called marginal totals. The grand total (the total number of individuals represented in the contingency table) is the number in the bottom right corner.

The table allows users to see at a glance that the proportion of men who are right-handed is about the same as the proportion of women who are right-handed although the proportions are not identical. The strength of the association can be measured by the odds ratio, and the population odds ratio estimated by the sample odds ratio. The significance of the difference between the two proportions can be assessed with a variety of statistical tests including Pearson's chi-squared test, the G-test, Fisher's exact test, Boschloo's test, and Barnard's test, provided the entries in the table represent individuals randomly sampled from the population about which conclusions are to be drawn. If the proportions of individuals in the different columns vary significantly between rows (or vice versa), it is said that there is a contingency between the two variables. In other words, the two variables are not independent. If there is no contingency, it is said that the two variables are independent.

The example above is the simplest kind of contingency table, a table in which each variable has only two levels; this is called a 2 × 2 contingency table. In principle, any number of rows and columns may be used. There may also be more than two variables, but higher order contingency tables are difficult to represent visually. The relation between ordinal variables, or between ordinal and categorical variables, may also be represented in contingency tables, although such a practice is rare. For more on the use of a contingency table for the relation between two ordinal variables, see Goodman and Kruskal's gamma.

Standard contents of a contingency table

[edit]
  • Multiple columns (historically, they were designed to use up all the white space of a printed page). Where each row refers to a specific sub-group in the population (in this case men or women), the columns are sometimes referred to as banner points or cuts (and the rows are sometimes referred to as stubs).
  • Significance tests. Typically, either column comparisons, which test for differences between columns and display these results using letters, or, cell comparisons, which use color or arrows to identify a cell in a table that stands out in some way.
  • Nets or netts which are sub-totals.
  • One or more of: percentages, row percentages, column percentages, indexes or averages.
  • Unweighted sample sizes (counts).

Measures of association

[edit]

The degree of association between the two variables can be assessed by a number of coefficients. The following subsections describe a few of them. For a more complete discussion of their uses, see the main articles linked under each subsection heading.

Odds ratio

[edit]

The simplest measure of association for a 2 × 2 contingency table is the odds ratio. Given two events, A and B, the odds ratio is defined as the ratio of the odds of A in the presence of B and the odds of A in the absence of B, or equivalently (due to symmetry), the ratio of the odds of B in the presence of A and the odds of B in the absence of A. Two events are independent if and only if the odds ratio is 1; if the odds ratio is greater than 1, the events are positively associated; if the odds ratio is less than 1, the events are negatively associated.

The odds ratio has a simple expression in terms of probabilities; given the joint probability distribution:

the odds ratio is:

Phi coefficient

[edit]

A simple measure, applicable only to the case of 2 × 2 contingency tables, is the phi coefficient (φ) defined by

where χ2 is computed as in Pearson's chi-squared test, and N is the grand total of observations. φ varies from 0 (corresponding to no association between the variables) to 1 or −1 (complete association or complete inverse association), provided it is based on frequency data represented in 2 × 2 tables. Then its sign equals the sign of the product of the main diagonal elements of the table minus the product of the off–diagonal elements. φ takes on the minimum value −1.0 or the maximum value of +1.0 if and only if every marginal proportion is equal to 0.5 (and two diagonal cells are empty).[2]

Cramér's V and the contingency coefficient C

[edit]

Two alternatives are the contingency coefficient C, and Cramér's V.

The formulae for the C and V coefficients are:

and

k being the number of rows or the number of columns, whichever is less.

C suffers from the disadvantage that it does not reach a maximum of 1.0, notably the highest it can reach in a 2 × 2 table is 0.707 . It can reach values closer to 1.0 in contingency tables with more categories; for example, it can reach a maximum of 0.870 in a 4 × 4 table. It should, therefore, not be used to compare associations in different tables if they have different numbers of categories.[3]

C can be adjusted so it reaches a maximum of 1.0 when there is complete association in a table of any number of rows and columns by dividing C by where k is the number of rows or columns, when the table is square [citation needed], or by where r is the number of rows and c is the number of columns.[4]

Tetrachoric correlation coefficient

[edit]

Another choice is the tetrachoric correlation coefficient but it is only applicable to 2 × 2 tables. Polychoric correlation is an extension of the tetrachoric correlation to tables involving variables with more than two levels.

Tetrachoric correlation assumes that the variable underlying each dichotomous measure is normally distributed.[5] The coefficient provides "a convenient measure of [the Pearson product-moment] correlation when graduated measurements have been reduced to two categories."[6]

The tetrachoric correlation coefficient should not be confused with the Pearson correlation coefficient computed by assigning, say, values 0.0 and 1.0 to represent the two levels of each variable (which is mathematically equivalent to the φ coefficient).

Lambda coefficient

[edit]

The lambda coefficient is a measure of the strength of association of the cross tabulations when the variables are measured at the nominal level. Values range from 0.0 (no association) to 1.0 (the maximum possible association).

Asymmetric lambda measures the percentage improvement in predicting the dependent variable. Symmetric lambda measures the percentage improvement when prediction is done in both directions.

Uncertainty coefficient

[edit]

The uncertainty coefficient, or Theil's U, is another measure for variables at the nominal level. Its values range from −1.0 (100% negative association, or perfect inversion) to +1.0 (100% positive association, or perfect agreement). A value of 0.0 indicates the absence of association.

Also, the uncertainty coefficient is conditional and an asymmetrical measure of association, which can be expressed as

.

This asymmetrical property can lead to insights not as evident in symmetrical measures of association.[7]

Others

[edit]

Gamma, Tau-b and Tau-c are used when the categories or levels of both variables have a natural order.

See also

[edit]
  • Confusion matrix
  • Pivot table, in spreadsheet software, cross-tabulates sampling data with counts (contingency table) and/or sums.
  • TPL Tables is a tool for generating and printing crosstabs.
  • The iterative proportional fitting procedure essentially manipulates contingency tables to match altered joint distributions or marginal sums.
  • The multivariate statistics in special multivariate discrete probability distributions. Some procedures used in this context can be used in dealing with contingency tables.
  • OLAP cube, a modern multidimensional computing form of contingency tables
  • Panel data, multidimensional data over time

References

[edit]

Further reading

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
A contingency table, also known as a cross-tabulation or crosstab, is a matrix that displays the distribution of two or more categorical variables, with rows and columns representing the categories of each variable and cell entries showing the joint counts or frequencies of their combinations. These tables are fundamental in for summarizing multivariate categorical data and facilitating the examination of potential associations or dependencies between variables. The structure of a contingency table typically includes marginal totals for rows and columns, which represent the univariate distributions of the individual variables, while the inner cells capture the joint frequencies from which conditional distributions can be derived. For a two-way table with r rows and c columns, the degrees of freedom for associated statistical tests are (r-1)(c-1), enabling assessments of independence under the null hypothesis that the variables are unrelated. Tables can extend to higher dimensions for three or more variables, though two-way tables remain the most common for initial exploratory analysis. They are widely applied in fields such as social sciences, , and to test hypotheses about relationships—for instance, using tests of such as the —while measures quantify the strength of associations. Modern extensions include log-linear models for multi-way interactions and continuity corrections, such as Yates' correction, to improve test accuracy in sparse tables.

Fundamentals

Definition and Purpose

A contingency table, also known as a cross-tabulation or two-way table, is a matrix that presents the multivariate distribution of two or more categorical variables, with rows and columns representing the categories of each variable and cell entries showing the observed . These tables provide a structured way to summarize joint occurrences of categories across variables, enabling researchers to visualize how observations are distributed across combinations without requiring numerical or continuous data. The primary purpose of contingency tables is to explore potential associations between categorical variables, test hypotheses regarding their independence, and facilitate the computation of conditional probabilities from the data. For instance, they are widely applied in epidemiology to assess relationships between risk factors and outcomes, such as exposure status and disease incidence. In the social sciences, they help analyze patterns in survey responses or demographic data, while in market research, they reveal dependencies between consumer preferences and demographics to inform segmentation strategies. Unlike parametric models, contingency tables allow for model-free visualization of dependencies, making them versatile for initial exploratory analysis across disciplines. Contingency tables are typically structured as r × c matrices, where r denotes the number of row categories and c the number of column categories, and they often incorporate fixed marginal totals for conducting conditional analyses that focus on distributions within subsets of the data. This empirical focus on observed frequencies distinguishes them from logical constructs like truth tables, which enumerate all possible outcomes rather than summarizing real-world data counts. A common application involves using such tables to detect deviations from , as in the .

Historical Development

The roots of contingency tables trace back to early 19th-century efforts in vital statistics and demography, where scholars employed multi-way tables to explore associations between variables such as age, sex, and criminality, emphasizing marginal distributions over independence testing. Precursors included Pierre-Simon Laplace and Siméon Denis Poisson's probabilistic analyses of 2×2 tables for comparing proportions in the early 1800s, and Félix Gavarret's 1840 application of these methods to medical data like sex ratios in births. By the late 19th century, figures such as Charles Sanders Peirce (1884) developed measures of association for 2×2 tables, applying them to predictive problems like tornado forecasting, while Francis Galton (1892) used expected frequencies in 3×3 fingerprint classification tables to assess independence. The modern statistical foundation of contingency tables was established in 1900 by , who introduced the as a measure of goodness-of-fit and , applicable to tables assessing associations between categorical variables. Pearson's seminal paper, "On the Criterion that a Given System of Deviations from the Probable in the Case of a Correlated System of Variables is Such that it Can Be Reasonably Supposed to Have Been Caused by Random Sampling," provided a criterion for evaluating whether observed frequencies deviated significantly from expectations under random sampling, marking the shift toward rigorous hypothesis testing in contingency analysis. Collaborating closely, George Udny Yule extended these ideas in the same year, developing association measures like Yule's coefficient of colligation for 2×2 tables, which quantified dependence in binary outcomes such as disease incidence by exposure. Pearson later coined the term "contingency table" in his 1904 work, "On the Theory of Contingency and Its Relation to Association and Normal Correlation," formalizing the framework for multivariate categorical data. In the 1920s and 1930s, Ronald A. Fisher advanced the methodology for small-sample contingency tables, critiquing the chi-squared approximation's limitations and developing exact procedures. In his 1922 paper, "On the Application of the χ² Method to Association and Contingency Tables," Fisher outlined applications of chi-squared to multi-way tables while highlighting issues with low expected frequencies. By , Fisher formalized in Statistical Methods for Research Workers, using the to compute precise p-values for 2×2 tables under fixed margins, illustrated famously by the "" experiment, which addressed small-sample without relying on asymptotic approximations. These contributions emphasized exact conditional , influencing tests for sparse . The mid-20th century saw expansion to multi-way contingency tables, facilitated by computational advancements that enabled handling larger, more complex datasets beyond manual calculations. Early theoretical work, such as Maurice S. Bartlett's 1935 exploration of interactions in multi-dimensional tables, paved the way, but practical implementation accelerated post-World War II with electronic computers allowing iterative estimation for higher-order analyses. By the 1970s, Leo A. Goodman integrated log-linear models into contingency table analysis, treating cell frequencies as Poisson or multinomial outcomes and using iterative proportional fitting to model interactions hierarchically. Goodman's series of papers, starting with "The Multivariate Analysis of Qualitative Data: Interactions among Multiple Classifications" in 1970, provided stepwise procedures and direct estimation for building models that captured main effects and higher-order associations in multi-way tables. This approach, further developed by Stephen E. Fienberg and others, revolutionized the field by enabling sophisticated inference on complex categorical structures.

Construction and Interpretation

Standard Format

A contingency table is typically arranged as a rectangular array that cross-classifies observations from two categorical variables, with rows representing the levels of one variable (say, with rr categories) and columns representing the levels of the other (with cc categories). The cells of this r×cr \times c table contain the observed frequencies, denoted as nijn_{ij}, which count the number of observations falling into the ii-th row category and jj-th column category. This layout facilitates the visualization of the joint distribution of the two variables. Standard notation employs double subscripts for cell entries, such as OijO_{ij} or nijn_{ij} for observed counts, where uppercase OO is sometimes used to distinguish from expected values in statistical analyses. Certain cells may contain structural zeros, indicated where combinations of categories are impossible or precluded by design, rendering those probabilities inherently zero and the table incomplete. While the two-way table serves as the standard format, extensions to multi-way tables incorporate additional dimensions, such as a three-dimensional r×c×kr \times c \times k array for three variables, though these are analyzed by slicing or modeling the higher-order interactions. Contingency tables are generally symmetric in the sense that the variables are interchangeable, but asymmetric variants exist where the ordering of rows and columns matters, as in confusion matrices that distinguish predicted from actual outcomes in classification tasks. In interpretation, the row totals (margins) summarize the distribution across columns for each row category, and column totals do likewise for rows; these margins enable the computation of conditional proportions, often expressed as percentages within rows or columns to assess relative frequencies.

Illustrative Example

Consider a hypothetical survey of 200 individuals assessing the relationship between and for a particular product (yes or no response). The data can be organized into a 2x2 contingency table, with as the row variable (male, female) and as the column variable (yes, no). The observed frequencies in each cell represent the count of respondents falling into each category combination. The resulting table is as follows:
GenderYesNo
Male3070
Female4060
To construct this table, first define the categorical variables: assign one to rows (e.g., with two levels: and ) and the other to columns (e.g., preference with two levels: yes and no). Then, tally the raw frequencies from the survey data into the appropriate cells based on respondents' answers, ensuring each individual contributes to exactly one cell. Simple percentages can highlight row-specific proportions for initial interpretation. For example, among males, 30 out of 100 (30%) expressed a yes , compared to 40 out of 100 (40%) among females. These percentages are calculated by dividing each cell by the row total and multiplying by 100. Visually inspecting the table reveals patterns, such as a higher proportion of females expressing yes relative to males, indicating an apparent difference in preferences across groups that may warrant further .

Marginal Totals and Expected Frequencies

In a contingency table, marginal totals are computed by summing the observed frequencies along the rows and columns, providing summaries of the univariate distributions of the respective categorical variables. The row marginal total for row ii, denoted ni.n_{i.}, is the sum of frequencies across all columns in that row: ni.=jnijn_{i.} = \sum_j n_{ij}, where nijn_{ij} is the observed frequency in cell (i,j)(i,j). Similarly, the column marginal total for column jj, denoted n.jn_{.j}, is n.j=inijn_{.j} = \sum_i n_{ij}. The grand total, n..n_{..}, is the sum of all cell frequencies or equivalently the sum of all row or column marginals: n..=ini.=jn.jn_{..} = \sum_i n_{i.} = \sum_j n_{.j}. Under the assumption of between the row and column variables, expected frequencies for each cell serve as a baseline for what would be anticipated if no association exists. The expected frequency EijE_{ij} for cell (i,j)(i,j) is calculated as the product of the corresponding row and column marginal totals divided by the grand total: Eij=ni.n.jn...E_{ij} = \frac{n_{i.} \cdot n_{.j}}{n_{..}}. This formula arises from the assumption, where the joint probability is the product of the marginal probabilities, scaled by the total sample size. Comparing observed frequencies nijn_{ij} to these expected frequencies EijE_{ij} reveals potential discrepancies that may indicate dependence between variables; substantial deviations suggest the data do not align with the independence model. For valid use in approximate statistical tests, such as the , the expected frequencies should generally be at least 5 in at least 80% of the cells, with no expected frequency less than 1, to ensure the reliability of the normal approximation underlying the test. If these conditions are violated (e.g., more than 20% of cells have expected frequencies below 5), alternative exact methods may be required.

Tests of Association and Independence

Chi-Squared Test of Independence

The chi-squared test of independence is a statistical procedure used to determine whether there is a significant association between two categorical variables in a contingency table, by comparing observed cell frequencies to those expected under the assumption of independence. The test was originally developed by in 1900 as a method to assess deviations from expected frequencies in multivariate . It is particularly applicable to large samples where the approximation to the holds reliably. The (H0H_0) states that the two variables are independent, meaning the observed frequencies should align closely with expected frequencies derived from the marginal totals. The (HaH_a) posits that the variables are associated, implying a significant deviation in the observed frequencies. The is calculated as χ2=i=1rj=1c(OijEij)2Eij,\chi^2 = \sum_{i=1}^r \sum_{j=1}^c \frac{(O_{ij} - E_{ij})^2}{E_{ij}}, where OijO_{ij} is the observed frequency in row ii and column jj, EijE_{ij} is the corresponding expected frequency, rr is the number of rows, and cc is the number of columns. Under the , this statistic follows a with (r1)(c1)(r-1)(c-1) . The is obtained by comparing the computed χ2\chi^2 to the critical value from the table for the given and significance level (e.g., α=0.05\alpha = 0.05), or more commonly, by using statistical software to derive it directly. Key assumptions include that the data consist of frequencies from a random sample, the observations are independent, and the expected frequencies are sufficiently large—typically at least 5 in at least 80% of the cells, with no expected frequency less than 1—to ensure the validity of the chi-squared approximation. Violations of these assumptions, particularly small expected frequencies, can lead to inflated Type I error rates. For 2×2 contingency tables, Yates' continuity correction is often applied to improve the approximation by adjusting the : subtract 0.5 from the OijEij|O_{ij} - E_{ij}| in each term of the summation, an adjustment introduced by Frank Yates in 1934 to account for the discrete nature of the data. This correction is particularly recommended when sample sizes are moderate but expected frequencies are borderline. To perform the test, first compute the expected frequencies for each cell as Eij=(rowi total)×(columnj total)grand totalE_{ij} = \frac{(row_i\ total) \times (column_j\ total)}{grand\ total}, then calculate the χ2\chi^2 statistic (with or without Yates' correction as appropriate), determine the degrees of freedom, and evaluate the p-value. If the p-value is less than the chosen significance level, the null hypothesis is rejected, indicating evidence of an association between the variables. Modern statistical software, such as R or SAS, automates these computations and provides options for corrections and exact alternatives when assumptions are not met.

Fisher's Exact Test

Fisher's exact test is a statistical procedure used to assess whether there is a significant association between two categorical variables in a 2×2 contingency table, particularly when sample sizes are small and the assumptions of asymptotic approximations may not hold. The test conditions on the observed marginal totals (row and column sums) and evaluates the exact probability of obtaining the observed table or one more extreme under the of , assuming the margins are fixed. This conditional approach leads to a for the cell frequencies, providing an exact rather than approximate . Under the , the distribution of the table entries follows a because the fixed margins imply that the allocation of observations to cells is like sampling without replacement from a finite . For a table with cell counts aa, bb, cc, dd, row totals n1.n_{1.} and n2.n_{2.}, column totals n.1n_{.1} and n.2n_{.2}, and grand total n..n_{..}, the exact probability of the observed table is given by: P=n1.!n2.!n.1!n.2!n..!a!b!c!d!P = \frac{ n_{1.}! \, n_{2.}! \, n_{.1}! \, n_{.2}! }{ n_{..}! \, a! \, b! \, c! \, d! } To compute the p-value, all possible 2×2 tables with the same fixed marginal totals are enumerated, each assigned its hypergeometric probability, and the sum of probabilities for tables as extreme as or more extreme than the observed one (in terms of deviation from independence) is calculated. This one- or two-tailed summation ensures the test's exactness, avoiding reliance on large-sample approximations like the chi-squared test, which is suitable for larger samples. The primary advantage of Fisher's exact test is its provision of precise p-values without approximation errors, making it ideal for small samples where expected frequencies may be low (e.g., less than 5). However, it becomes computationally intensive for large sample sizes due to the need to enumerate numerous tables, and for tables larger than , an extension known as the Freeman-Halton test can be applied, though it is used sparingly owing to even greater computational demands.

Likelihood-Ratio Test

The for assessing in contingency tables compares the maximum likelihood under the , which estimates a separate for each cell and thus fits the observed data perfectly, to the maximum likelihood under the restricted independence model, which assumes cell probabilities are the product of row and column marginal probabilities and typically employs a multinomial or Poisson likelihood for the cell counts. This comparison evaluates whether the independence assumption adequately explains the observed frequencies. The was originally developed by Wilks in 1935 as a method for hypothesis testing in contingency tables. The test statistic, known as the deviance or G², is given by G2=2i=1rj=1cOijln(OijEij),G^2 = 2 \sum_{i=1}^r \sum_{j=1}^c O_{ij} \ln \left( \frac{O_{ij}}{E_{ij}} \right), where OijO_{ij} denotes the observed frequency in row ii and column jj, and EijE_{ij} is the expected frequency under independence, computed as the product of the row and column marginal totals divided by the grand total. Under the null hypothesis of no association between the row and column variables, G2G^2 follows an asymptotic chi-squared distribution with (r1)(c1)(r-1)(c-1) degrees of freedom, where rr and cc are the numbers of rows and columns. To conduct the test, one computes G2G^2 and compares it to the critical value from the chi-squared distribution at the desired significance level; rejection of the null occurs if G2G^2 exceeds this value or if the associated p-value is below the threshold, providing evidence of dependence. Relative to the Pearson chi-squared test, the exhibits superior performance in scenarios with sparse data or small expected cell frequencies, offering greater statistical power and a more reliable asymptotic without the strict requirement that all expected values exceed 5. Additionally, its foundation in likelihood principles makes it especially suitable for evaluating hierarchical models in , where the additivity of G2G^2 across nested sub-models facilitates sequential model comparisons and goodness-of-fit assessments. While the two tests have comparable power in large samples, the likelihood-ratio approach is often preferred for its theoretical robustness in complex categorical data structures.

Measures of Strength of Association

Odds Ratio

In a 2×2 contingency table, the odds ratio (OR) quantifies the association between two binary variables, such as exposure and disease outcome, as the ratio of the odds of the outcome occurring in one group relative to the other. It is calculated as OR=a/db/c=adbc,\text{OR} = \frac{a/d}{b/c} = \frac{ad}{bc}, where aa, bb, cc, and dd denote the cell counts in the table, with aa and bb representing the exposed group and cc and dd the unexposed group. An OR greater than 1 suggests a positive association, indicating higher of the outcome in the exposed group; an OR of 1 implies no association; and an OR less than 1 indicates a negative association. In , the OR serves as a key measure in case-control studies to estimate the strength of exposure-outcome relationships, and when the outcome is rare (prevalence ≤10%), it approximates the . The 95% confidence interval for the OR is typically computed using Woolf's logit method, where the interval for ln(OR)\ln(\text{OR}) is ln(OR)±1.96×SE\ln(\text{OR}) \pm 1.96 \times \text{SE}, with SE=1/a+1/b+1/c+1/d\text{SE} = \sqrt{1/a + 1/b + 1/c + 1/d}
Add your contribution
Related Hubs
User Avatar
No comments yet.