<sub>2025-04-09 Wednesday</sub> <sub>#biostatistics </sub> <sup>[[maps-of-content]] </sup> # Hypothesis Testing for Categorical Outcomes > [!success]- Concept Sketch: [[]] > ![[]] > [!abstract]- Quick Review > > **Core Essence**: Statistical analysis of binary (yes/no) and categorical data focuses on proportions rather than means, using contingency tables, chi-squared tests, and odds ratios to determine whether outcomes are associated with group membership. > > **Key Concepts**: > > - Proportions replace means when analyzing binary outcomes (0/1 data) > - Chi-squared test compares observed vs expected frequencies to detect associations > - Odds ratios quantify the strength of association between exposure and outcome > > **Must Remember**: > > - Sample proportion (p̂) = number with outcome (m) / sample size (n) > - Chi-squared null hypothesis: outcome is independent of group (p₁ = p₂) > - Odds ratio of 1 indicates no association between groups > > **Critical Relationships**: > > - Rejecting chi-squared null hypothesis ⟷ odds ratio confidence interval excludes 1 > - Larger chi-squared values ⟷ smaller p-values ⟷ stronger evidence of association > - Multiple comparisons require Bonferroni correction (α/number of tests) ## Introduction to Binary Outcomes & Proportions When dealing with categorical data—especially binary outcomes like disease/no disease or success/failure—our statistical approach shifts from analyzing means to analyzing proportions. This fundamental change reflects the discrete nature of categorical variables. ### Binary Data Fundamentals Binary data has just two possible values, typically coded as: - 1 = event occurred (positive outcome, success, disease present) - 0 = event did not occur (negative outcome, failure, disease absent) **The population parameter of interest** becomes the population proportion (p), which represents the probability of the event occurring in the entire population. > [!note] While means are used for continuous outcomes, proportions are the focus for binary outcomes. However, mathematically, a proportion can be viewed as the mean of 0s and 1s in the data. ### Estimating Population Proportions The **sample proportion (p̂)** serves as our estimate of the unknown population proportion: p̂ = m/n Where: - m = number of individuals with the outcome of interest - n = total sample size The standard error for this estimate is calculated as: SE(p̂) = √[p̂(1-p̂)/n] This standard error measures the precision of our sample proportion as an estimate of the population proportion. ### Confidence Intervals for a Single Proportion Similar to continuous data, we can construct a confidence interval for a proportion: 95% Confidence Interval = p̂ ± 1.96 × SE(p̂) This interval provides a range of plausible values for the true population proportion with 95% confidence. ```mermaid graph LR A["Sample Data"] --> B["Calculate p̂ = m/n"] B --> C["Calculate SE = √(p̂(1-p̂)/n)"] C --> D["Construct CI: p̂ ± 1.96×SE"] D --> E["Interpret Confidence Interval"] ``` ## Comparing Proportions with Contingency Tables When comparing outcomes between two or more groups, we organize the data in contingency tables. ### 2×2 Contingency Table Structure For two groups and a binary outcome: | | Outcome Present | Outcome Absent | Total | | ----------- | --------------- | -------------- | ----- | | **Group 1** | a | b | n₁ | | **Group 2** | c | d | n₂ | | **Total** | m₁ | m₂ | n | Where: - a, b, c, d = observed frequencies in each cell - n₁, n₂ = row totals (group sizes) - m₁, m₂ = column totals (outcome totals) - n = grand total (total sample size) The sample proportions for each group are: - p̂₁ = a/n₁ - p̂₂ = c/n₂ ## Chi-squared Test of Association The chi-squared test evaluates whether an association exists between group membership and the outcome. ### Hypothesis Framework **Null Hypothesis (H₀)**: The outcome is independent of group membership. - If true: p₁ = p₂ = ... = p𝑘 (same proportion across all groups) **Alternative Hypothesis (H₁)**: The outcome is associated with group membership. - If true: At least one proportion differs from the others ### Expected Frequencies Calculation The key to the chi-squared test is comparing **observed frequencies** with **expected frequencies** (what we would expect if H₀ were true). For each cell in the contingency table, the expected frequency is: Expected = (Row Total × Column Total) / Grand Total For a 2×2 table: - E₁₁ = (n₁ × m₁) / n - E₁₂ = (n₁ × m₂) / n - E₂₁ = (n₂ × m₁) / n - E₂₂ = (n₂ × m₂) / n ### Chi-squared Test Statistic The chi-squared statistic measures the discrepancy between observed and expected frequencies: χ² = Σ [(O - E)² / E] Where: - O = observed frequency in each cell - E = expected frequency in each cell - Σ = sum over all cells in the table Larger values of χ² indicate greater discrepancy, suggesting the null hypothesis is less likely to be true. ```mermaid flowchart TD A["Organize data in contingency table"] --> B["Calculate expected frequencies"] B --> C["Calculate χ² = Σ (O-E)²/E"] C --> D["Determine degrees of freedom\ndf = (rows-1)×(columns-1)"] D --> E["Find p-value"] E --> F{"p < α?"} F -->|Yes| G["Reject H₀:\nAssociation exists"] F -->|No| H["Fail to reject H₀:\nNo evidence of association"] ``` ### Interpreting the Chi-squared Test The test statistic follows a chi-squared distribution with degrees of freedom: df = (number of rows - 1) × (number of columns - 1) For a 2×2 table, df = 1. The p-value represents the probability of observing a test statistic as extreme as, or more extreme than, the one calculated, assuming H₀ is true. **Decision rule**: If p-value < α (typically 0.05), reject H₀ and conclude there is a statistically significant association. > [!warning] The chi-squared test requires sufficiently large expected frequencies (typically ≥5 in each cell). For smaller samples, Fisher's exact test is preferred ## Multiple Group Comparisons The chi-squared test extends naturally to more than two groups by using larger contingency tables. ### Multiple Testing and Bonferroni Correction When performing multiple chi-squared tests (e.g., comparing each group to a reference group), we must adjust for multiple comparisons to control the family-wise error rate. The **Bonferroni correction** adjusts the significance level: α_adjusted = α / k Where: - α = original significance level (typically 0.05) - k = number of comparisons For example, with 3 comparisons, the adjusted threshold becomes 0.05/3 = 0.017. > [!note] Without this correction, performing multiple tests increases the chance of falsely rejecting the null hypothesis (Type I error). ## Odds Ratios: Quantifying Associations While the chi-squared test tells us whether an association exists, odds ratios quantify the strength and direction of the association. ### Understanding Odds vs. Probabilities **Probability (p)**: The chance of an event occurring (0≤p≤1) **Odds**: The ratio of probability of occurrence to probability of non-occurrence Odds = p/(1-p) For example: - If p = 0.5, odds = 0.5/0.5 = 1 (even odds) - If p = 0.75, odds = 0.75/0.25 = 3 (3:1 odds) - If p = 0.25, odds = 0.25/0.75 = 0.33 (1:3 odds) ### Calculating the Odds Ratio The odds ratio compares the odds of the outcome between two groups: OR = (Odds in Group 1) / (Odds in Group 2) From a 2×2 contingency table: OR = (a/b) / (c/d) = (a×d) / (b×c) ### Interpreting Odds Ratios - OR = 1: No association (equal odds in both groups) - OR > 1: Increased odds in Group 1 compared to Group 2 - OR < 1: Decreased odds in Group 1 compared to Group 2 For example, OR = 2.5 means the odds of the outcome in Group 1 are 2.5 times higher than in Group 2. > [!tip] The reciprocal of an odds ratio reverses the reference group. If OR(Group 1 vs. Group 2) = 0.4, then OR(Group 2 vs. Group 1) = 1/0.4 = 2.5. ### Confidence Intervals for Odds Ratios A 95% confidence interval for the odds ratio provides a range of plausible values for the true odds ratio. If this interval excludes 1, we have evidence of a statistically significant association. This aligns with the chi-squared test: rejecting H₀ in the chi-squared test corresponds to a confidence interval for the odds ratio that excludes 1. ```mermaid graph LR A["Calculate OR = (a×d)/(b×c)"] --> B["Compute 95% CI for OR"] B --> C{"Does CI contain 1?"} C -->|Yes| D["Not statistically significant"] C -->|No| E["Statistically significant association"] E -->|OR > 1| F["Group 1 has higher odds"] E -->|OR < 1| G["Group 1 has lower odds"] ``` > [!case]- Case Application: Caries Prevention Intervention > > Researchers studied whether an intervention reduced dental caries in infants. They randomly assigned 104 infants to either an intervention or control group and measured caries development after two years. > > **Contingency Table**: > > > ||Caries|No Caries|Total| > |---|---|---|---| > |**Intervention**|5|47|52| > |**Control**|15|37|52| > |**Total**|20|84|104| > > **Proportion with caries**: > > - Intervention: p̂₁ = 5/52 = 0.096 (9.6%) > - Control: p̂₂ = 15/52 = 0.288 (28.8%) > > **Expected frequencies** (if no association): > > - E₁₁ = (52 × 20)/104 = 10 > - E₁₂ = (52 × 84)/104 = 42 > - E₂₁ = (52 × 20)/104 = 10 > - E₂₂ = (52 × 84)/104 = 42 > > **Chi-squared statistic**: χ² = (5-10)²/10 + (47-42)²/42 + (15-10)²/10 + (37-42)²/42 = 6.7 > > With df = 1, p-value = 0.009 > > Since p < 0.05, we reject H₀ and conclude there is a significant association between the intervention and caries development. > > **Odds ratio**: OR = (5×37)/(47×15) = 0.26 > > The odds of developing caries in the intervention group are 0.26 times the odds in the control group (74% lower). > > **95% CI for OR**: (0.08, 0.78) > > Since this interval excludes 1, we have statistically significant evidence that the intervention reduces the odds of developing caries. ## Summary: Key Connections 1. **Binary data analysis** centers on proportions rather than means, with sample proportions serving as estimates of population proportions. 2. **Chi-squared tests** determine whether categorical outcomes are associated with group membership by comparing observed frequencies with those expected under independence. 3. **Odds ratios** quantify the strength and direction of associations, with values above 1 indicating increased odds and values below 1 indicating decreased odds in the first group compared to the second. 4. **Statistical significance** in categorical analysis can be determined either through the p-value from a chi-squared test or by checking whether a confidence interval for the odds ratio includes 1. 5. **Multiple group comparisons** require careful consideration of type I error inflation, with Bonferroni correction providing a straightforward adjustment to the significance level. All these methods share a common goal: determining whether outcomes differ between groups beyond what would be expected by random chance. They enable researchers to make evidence-based conclusions about associations between categorical variables in their data. ## The Single Most Important Takeaway > [!important] Categorical data analysis revolves around a fundamental question: > Is the outcome associated with group membership? Whether using chi-squared tests to detect associations or odds ratios to quantify them, the essence remains the same—determining if the pattern of outcomes across groups reflects a meaningful relationship rather than random variation. -- Reference: