5 Chi-Square Tests F26
Table of contents
- Outline
- Hardy Weinberg Equilibrium
- Kaplan-Meier Survival Analysis
- Up Next…
1. Outline
1.1 Today's topics
- Today's topics include Chi-Square Tests, such as Goodness of Fit, Test of Independence, McNemar’s Test, Stuart-Maxwell Test, One-Sample Variance Test, and Multisample Median Test.
- Special cases covered are Hardy-Weinberg Equilibrium and Kaplan-Meier Survival Analysis 2.
1.2 Chi-Square Tests: General Information
- Chi-Square tests are used with nominal independent and dependent data, typically summarized in contingency tables.
- A contingency table has
rrows representing categories of one variable andccolumns representing categories of a second variable 3.
📝 The Test of Independence assesses whether two variables are related across their categories 4.
1.3 Chi-Square Goodness of Fit Test
- The Goodness of Fit test determines if a sample follows a particular distribution, assessing if one variable exhibits a predicted frequency pattern across its categories 4.
- This test requires counts of categories as actual frequencies, not percentages or proportions.
- It assumes independent samples and requires at least 5 values for each observation category, though it is robust to this assumption for uniform distributions.
- The degrees of freedom (df) are calculated as (number of categories – 1) 5.
- The calculated χ2 value is obtained by summing (O–E)2/E for each category, where O is the observed count and E is the expected count.
- This calculated value is then compared to a critical χ2 value for a specific alpha level and df 6.
- If the null hypothesis (H0) is rejected, the largest (O–E)2/E residual value can indicate which category differs from expectations, potentially leading to additional chi-square tests 7.
1.4 Chi-Square Test of Independence
- The Test of Independence assesses whether two variables are related across their categories 4.
- It uses counts of categories for two variables as actual frequencies.
- The test assumes random samples and requires at least 5 values for each observation category, with robustness for uniform distributions.
- Degrees of freedom (df) are calculated as (r–1)∗(c–1), where
ris the number of categories for one variable andcis for the second 8. - The expected count (E) for each cell is calculated as (row total × column total)/n 9.
📝 For a 2x2 table with cell counts a, b, c, and d, the Odds Ratio is calculated as b×ca×d 11.
1.5 Continuity Correction
- For a degrees of freedom of 1 in Chi-Square tests, a continuity correction is applied as an approximation of the Fisher Exact Test 10.
1.6 Chi-Square Effect Size
- Effect size measures quantify the magnitude of the observed effect in Chi-Square tests 11.
| Measure | Formula | Notes |
|---|---|---|
| Fei (for goodness of fit) | N×∑E(O−E)2 | N = total number of observations |
| Cramer’s V (for test of independence) | N×(k−1)χ2 | N = total number of observations, k = min(number of rows, number of columns) |
| Odds Ratio (for 2x2 tables) | b×ca×d | Where a, b, c, d are cell counts in a 2x2 table. |
1.7 McNemar’s Test
- McNemar’s Test compares the proportions of two groups of paired samples, most commonly used for before/after or positive/negative sampling designs.
- The test focuses on discordant pairs (where the outcome differs between the paired observations) 12.
- Degrees of freedom (df) are calculated as (r–1)∗(c–1).
- A continuity correction is applied if b+c<25, where
bandcrepresent the counts in the off-diagonal cells of the contingency table 13.
| — | After + | After – | Row Totals |
|---|---|---|---|
| Before + | a | b | a + b |
| Before – | c | d | c + d |
| Column Totals | a + c | b + d | n |
1.8 Stuart-Maxwell Test
- The Stuart-Maxwell Test compares the proportions of two or more groups of paired samples.
- This test is computationally complex and often revisited using statistical software.
- Cramer’s V is used for effect size calculation with this test 14.
1.9 One Sample Variance Test
- This test compares the sample variance to an expected population variance.
- The formula involves the expected population variance (σE2) and degrees of freedom (df) calculated as n–1 15.
1.10 Multisample Median Test
- The Multisample Median Test checks if all medians are the same across multiple samples.
- If all medians are equal, each sample should have an equal number of observations above and below the grand median (the median of all combined samples).
- This test utilizes the framework of the Test of Independence.
- Observed counts of values above and below the grand median are tallied for each sample.
- Expected counts are calculated using the standard formula: (Row Total × Column Total)/n 16.
| — | Sample 1 | Sample 2 | Sample 3 | Total |
|---|---|---|---|---|
| Above Grand Median | R1 | R2 | R3 | C1 |
| Below Grand Median | R4 | R5 | R6 | C2 |
| Total | C1 | C2 | C3 | n |
2. Hardy Weinberg Equilibrium
2.1 Hardy-Weinberg Equilibrium
The Hardy-Weinberg Equilibrium specifies the relationship between allele and genotype frequencies in populations that are not evolving. In such populations, allele frequencies remain constant over generations.
This equilibrium serves as a special case of the chi-square test, where the degrees of freedom (df) are calculated as the number of genotypes minus the number of alleles 17.
2.2 Hardy-Weinberg Formula 18
A formula can be used to predict genotype frequencies in the next generation, assuming the population is not evolving. This formula, p2+2pq+q2, is applicable only to diploid, sexually reproducing populations with two alleles 18.
| Genotype | Frequency |
|---|---|
| Homozygous dominant (AA) | p2 |
| Heterozygous (Aa) | 2pq |
| Homozygous recessive (aa) | q2 |
3. Kaplan-Meier Survival Analysis
3.1 Introduction to Survival Analysis
Survival analysis is a statistical method used to assess the likelihood of an event occurring over time. This approach is particularly useful in fields like medicine and engineering where understanding the time until an event (such as death, failure, or recovery) is crucial.
Key aspects include creating survival curves and handling censored data.
- Survival curves: These graphically represent the probability of an event occurring at specific time points.
- Censored data: This refers to data where the event of interest has not occurred by the end of the study period, or the individual is lost to follow-up, or dies from an unrelated cause. It is indicated by a '0' in the dataset, while an event is indicated by a '1' 19.
3.2 Organizing Survival Data
To perform survival analysis, data must be organized into individual records, each containing the time of the event or censoring and an indicator for whether the event occurred.
- Individual: A unique identifier for each subject in the study.
- Time: The duration from the start of the study until the event occurred or the subject was censored.
- Event: A binary indicator, where '1' signifies that the event of interest occurred, and '0' signifies censoring 20.
3.3 Calculating Summary Statistics
Calculating summary statistics involves determining the proportion of individuals surviving at each time interval. This is done by tracking the number of events and the total number of individuals alive at the beginning of each period.
- dt: The number of events that occurred within a specific time period.
- nt: The total number of individuals who were alive at the start of that time period.
- Proportion surviving in a time period: Calculated as 1−ntdt.
- Cumulative survival probability S(t): The proportion of individuals surviving from time 0 up to time t. It is calculated by multiplying the survival probability of the previous period by the proportion surviving in the current period: S(t)=S(t−1)×(1−ntdt) 21.
The following table illustrates the calculation of summary statistics for survival data:
- Ind.: Time, Event, t, d, c, n, 1-d/n, S(t)
- 1: 2, 1, 0, 5, 1, 1, 0, 5
- 2: 3, 0, 1, 4, 0, 5, 0.8, 0.8
- 3: 6, 1, 2, 3, 1, 4, 0.75, 0.6
- 4: 7, 1, 3, 2, 1, 3, 0.66, 0.4
- 5: 9, 1, 4, 1, 0, 3, 0.66, 0.264 22 23.
3.4 Conducting a Log-rank Test of Independence
The log-rank test is a non-parametric statistical test used to compare the survival distributions of two or more independent groups. It assesses whether there is a significant difference in survival experience between these groups.
- Expected events (Et): For each treatment group and each time point t, the expected number of events is calculated based on the overall event rate at that time. This is determined by the number of individuals alive (n) and the number of deaths (d) observed across all groups at that time.
- Total expected events (E): The sum of expected events for a specific treatment group across all time points.
- Chi-Square Value: Calculated by summing the squared difference between observed (O) and expected (E) events, divided by the expected events, for each treatment group: ∑E(O−E)2.
- Degrees of freedom (df): Determined by the number of treatment groups minus one (df=#treatments−1) 24 25.
📝 Consider two treatment groups, A and B. At time t=5, group A has 10 individuals alive and 2 deaths observed (OA=2), while group B has 12 individuals alive and 1 death observed (OB=1). If the overall expected deaths at t=5 across both groups are EA=1.5 for group A and EB=1.5 for group B, the contribution to the Chi-Square statistic for group A would be 1.5(2−1.5)2 and for group B would be 1.5(1−1.5)2. These contributions are summed across all time points and groups to yield the final Chi-Square value 25.
4. Up Next…
4.1 Analysis of variance
This section previews the upcoming topic: Analysis of Variance (ANOVA). ANOVA is a statistical method used to compare the means of two or more groups.
It helps determine if there are statistically significant differences between these group means 26.
📝 The next topic will cover Analysis of Variance, a statistical technique for comparing the means of multiple groups 26.
© 2026 Maeve. All rights reserved. This content is protected by copyright.