Chi-Square Test of Independence and Post Hoc Analysis
Chi-Square Test of Independence
In this analysis, I conducted a Chi-Square Test of Independence to examine the relationship between two categorical variables with more than two levels. Here's a step-by-step overview, including the syntax used and the results obtained.
Assume we have a dataset with the following categorical variables:
Variable A: 3 levels (e.g., Group 1, Group 2, Group 3)
Variable B: 2 levels (e.g., Outcome 1, Outcome 2)
Syntax for Chi-Square Test of Independence
Python Syntax (using scipy):
The Chi-Square Test of Independence produced a chi-square statistic of 25.066 with a p-value of approximately 1.34e-05. Since the p-value is significantly less than the typical alpha level of 0.05, we reject the null hypothesis and conclude that there is a significant association between Variable A and Variable B.
Given that the Chi-Square Test indicates a significant association, we need to perform a post hoc analysis to determine which specific group pairs contribute to the observed significant association.
Post Hoc Analysis (Adjusted Residuals):
To identify which cells contribute significantly to the Chi-Square statistic, compute the standardized residuals.
Python Syntax for Residuals:
Interpreted Residuals: Significant residuals indicate which cells in the contingency table contribute most to the chi-square statistic. For instance, if the standardized residual for Group 3 and Outcome 2 is notably high, it suggests an unexpected high frequency in that cell compared to what was expected under the null hypothesis.