Categorical Data Analysis: Contingency Tables and Log-Linear Models
Analyze categorical data using contingency tables and log-linear models for Exam MAS-I.
Introduction to Contingency Tables
Contingency tables cross-classify observations by two or more categorical variables, displaying the frequency of each combination. A two-way table with r rows and c columns has r*c cells, each containing a count. The row and column totals (marginals) summarize the distribution of each variable separately. Contingency table analysis determines whether the two classification variables are independent or associated.
In actuarial work, contingency tables arise when analyzing the relationship between categorical risk factors. For example, you might cross-classify auto insurance policyholders by vehicle type (sedan, SUV, truck) and claim status (claim, no claim) to determine whether vehicle type is associated with claim frequency. Understanding this association informs risk classification and pricing decisions.
The Chi-Squared Test of Independence
The chi-squared test compares observed cell counts O_{ij} to expected counts under the null hypothesis of independence. Under independence, the expected count for cell (i,j) is E_{ij} = (row i total * column j total) / grand total. The test statistic is X^2 = sum over all cells of (O_{ij} - E_{ij})^2 / E_{ij}. Under H0, X^2 follows approximately a chi-squared distribution with (r-1)*(c-1) degrees of freedom.
Consider a 2x3 table of 300 policyholders classified by gender (M, F) and claim severity level (low, medium, high). Suppose males have counts (80, 40, 30) and females have (90, 35, 25). The row totals are 150 and 150, column totals are 170, 75, and 55, and the grand total is 300. The expected count for (Male, Low) is 150*170/300 = 85. Computing (O-E)^2/E for each of the 6 cells and summing gives the test statistic. With df = (2-1)*(3-1) = 2, compare to the chi-squared critical value at your chosen significance level.
Fisher's Exact Test and the Odds Ratio
Fisher's exact test is used for small samples where the chi-squared approximation may be unreliable (typically when any expected count falls below 5). It computes the exact probability of observing the given table, or one more extreme, under the null hypothesis of independence. The probability is based on the hypergeometric distribution, conditioning on both row and column totals.
For 2x2 tables, the odds ratio provides a measure of association strength. With cell counts n_{11}, n_{12}, n_{21}, n_{22}, the odds ratio is theta = (n_{11} * n_{22}) / (n_{12} * n_{21}). An odds ratio of 1 indicates independence. Values greater than 1 indicate positive association (the event is more likely in the first group), and values less than 1 indicate negative association. The natural logarithm of the odds ratio is approximately normally distributed with standard error sqrt(1/n_{11} + 1/n_{12} + 1/n_{21} + 1/n_{22}), enabling confidence interval construction.
Measures of Association
Beyond the odds ratio, several measures quantify the strength of association in contingency tables. Cramer's V = sqrt(X^2 / (n * min(r-1, c-1))) standardizes the chi-squared statistic to the range [0, 1], where 0 indicates independence and 1 indicates perfect association. It works for tables of any dimension, unlike the odds ratio which is specific to 2x2 tables.
The contingency coefficient C = sqrt(X^2 / (X^2 + n)) also ranges from 0 (independence) upward, but its maximum depends on the table dimensions and is always less than 1. For 2x2 tables, the phi coefficient phi = sqrt(X^2 / n) is equivalent to the Pearson correlation between the two binary variables. In actuarial applications, these measures help quantify how strongly risk factors are associated with claim outcomes.
Log-Linear Models for Multi-Way Tables
Log-linear models describe the expected cell counts in multi-way contingency tables using a linear model on the log scale. For a two-way table, the saturated model is ln(m_{ij}) = mu + lambda_i^A + lambda_j^B + lambda_{ij}^{AB}, where mu is the overall mean (on the log scale), lambda_i^A is the effect of row category i, lambda_j^B is the effect of column category j, and lambda_{ij}^{AB} is the interaction effect. The independence model omits the interaction term: ln(m_{ij}) = mu + lambda_i^A + lambda_j^B.
For three-way tables (variables A, B, C), several meaningful models exist. The mutual independence model includes only main effects. The joint independence model (AB, C) allows A and B to be associated but both independent of C. The conditional independence model (AC, BC) allows A and B each to be associated with C but independent of each other, given C. The homogeneous association model (AB, AC, BC) includes all two-way interactions but no three-way interaction.
Model Selection for Log-Linear Models
The likelihood ratio statistic G^2 = 2 * sum(O_{ijk} * ln(O_{ijk} / E_{ijk})) measures the discrepancy between observed and fitted counts. Under the null model, G^2 follows approximately a chi-squared distribution with degrees of freedom equal to the number of cells minus the number of parameters. To compare nested models, compute the difference in G^2 values; this difference follows a chi-squared distribution with degrees of freedom equal to the difference in the number of parameters.
AIC and BIC provide alternative model selection criteria that penalize complexity. AIC = G^2 - 2*df favors more complex models, while BIC = G^2 - ln(n)*df penalizes complexity more heavily. The model with the smallest AIC or BIC is preferred. In practice, the best model balances parsimony (fewer parameters) with adequate fit (small G^2 relative to degrees of freedom).
Common Pitfalls
A frequent error in the chi-squared test is computing expected counts incorrectly. Remember that E_{ij} = (row total for i) * (column total for j) / (grand total). Another mistake is applying the chi-squared test when expected counts are too small (below 5 in many cells). In such cases, combine categories or use Fisher's exact test.
With log-linear models, students sometimes confuse the different independence models for three-way tables. The notation (AB, C) means A and B are jointly treated as one factor that may interact, while C is independent. Practice writing out what each model implies about the relationships among the three variables.
Study Tips
Exam MAS-I tests contingency table analysis, odds ratio calculation and interpretation, and log-linear model fitting for multi-way tables. Practice computing expected counts and the chi-squared statistic by hand for small tables. Memorize the degrees of freedom formula (r-1)*(c-1) for two-way tables and know how to compute df for log-linear models. Be comfortable interpreting odds ratios, including constructing confidence intervals using the log odds ratio. For three-way tables, practice identifying which log-linear model corresponds to a given set of independence assumptions.