Chi-Square Tests Notes
Chapter 16: Inference for Counts (Chi-Square Tests)
16.1 Goodness-of-Fit Tests
- Deals with count data at the nominal or ordinal level.
- Examines counts of items in different categories.
- Asks if the actual distribution differs from a predicted model due to random error or a poor model fit.
- Example: Analyzing "up" days in the stock market and comparing it to a population distribution.
16.1 Logic of Goodness-of-Fit Tests
- Individuals are classified and counted into categories.
- Observed frequencies are tabulated for each category.
- Each individual is counted in only one category.
- Expected frequencies are constructed based on the null hypothesis (H0).
- Expected frequency: The frequency predicted by H0 and the sample size, representing an idealized distribution.
- Compares observed frequencies from sample data with expected frequencies predicted by H0.
- Uses the Chi-Square distribution to represent values for all possible random samples when H0 is true.
16.2 Interpreting Chi-Square Values
Chi-Square Distribution
- Positively skewed distribution.
- A family of distributions, each determined by degrees of freedom (df).
- Each df value results in a slightly different shape.
16.2 Hypothesis Tests: Chi-Square Goodness-of-Fit
Step 1: Hypotheses
- Case I: No preference (equal proportions) among categories
- H0: p1 = p2 = \cdots = pk = a, where 'a' is the probability value to test, and 'k' is the number of categories.
- HA: At least one pi is not equal to its specified value.
- Case II: Specified proportions or preference from another known population
- H0: p1 = a1, p2 = a2, \cdots = pk = ak, where a1, a2, \cdots , ak are the probability values or relative preferences of each category.
- HA: At least one pi is not equal to its specified value.
Step 2: Decision Zone and Type of Test
- \chi^2 is the test statistic (Chi-square).
- Right-tailed test (0 < \chi^2 < \infty).
- Reject H0 if \chi^2 > \chi^2{cv}, where \chi^2{cv} is the critical value from the chi-square distribution with (k - 1) degrees of freedom.
Step 3 and 4: Observed and Expected Frequencies
- Observed Frequencies: Obs(oi). Property: \sum{i=1}^{k} o_i = n
- Expected Frequencies: Exp(ei) = npi. Property: \sum{i=1}^{k} oi = \sum{i=1}^{k} ei = n, where p_i are the probabilities of categories specified in H0.
Step 5: Test Statistic
- \chi^2 = \sum{i=1}^{k} \frac{(oi - ei)^2}{ei}
Step 6: Make a Decision (Critical Value Approach)
- Reject H0 if the test statistic (\chi^2) is in the critical region.
- Fail to reject H0 if the test statistic (\chi^2) is not in the critical region.
- Rejection Region: Reject H0 if \chi^2 > \chi^2_{cv} (Right-tailed Test).
Step 6: Make a Decision (p-value Approach)
- p-value: Probability of seeing the observed data (or more extreme) given H0 is true.
- Calculation of p-value: P(\chi^2 > \chi^2_0) (Right-tailed Test).
- Decision Rule:
- If p-value < \alpha, reject H0.
- If p-value \geq \alpha, do not reject H0.
Assumptions and Conditions
- Counted Data Condition: Data must be counts for categories of a categorical variable.
- Independence Assumption: Counts should be independent of each other.
- Randomization Condition: Counted individuals should be a random sample of the population.
- Sample Size Assumption: Enough data for the methods to work.
- Expected Cell Frequency Condition: Expected cell frequency (ei) in each cell/category should be at least 5. If not, collapse adjacent cells meaningfully until ei \geq 5 and adjust df accordingly.
Example 1: Case I (No Preference or Equal Proportion)
- Problem: Are technical support calls equal across all days of the week (uniform distribution)?
- Sample data: Technical support calls for 10 days per day of week.
- Step 1: Hypotheses
- H0: p1 = p2 = \cdots = pk = \frac{1}{7}
- HA: At least one p_i is not equal to \frac{1}{7}.
- Step 2: Decision Zone and Critical Value
- \chi^2{\alpha,k-1} = \chi^2{.05,6} = 12.5916
- Steps 3 and 4: Observed and Expected Frequencies
- Assumptions and Conditions checked
- Steps 5 and 6: Test Statistic and Make a Decision (CV and p-value Approach)
- Decision: Reject H0. The distribution of technical support calls is not uniform across the days of the week.
Example 2: Case II (Specified Preference or Proportion)
- Problem: Market share analysis of fabric softener companies A and B after advertising campaigns.
- Before campaigns: Company A (45%), Company B (40%), Others (15%).
- Sample: 200 customers; A (102), B (82), Others (16).
- Question: Have customer preferences changed at a 5% significance level?
- Step 1: Hypotheses
- H0: p1 = 0.45, p2 = 0.40, p3 = 0.15
- HA: At least one p_i is not equal to its specified value.
- Step 2: Decision Zone and Critical Value
- \chi^2{\alpha,k-1} = \chi^2{.05,2} = 5.99147
- Steps 3 - 5: Observed, Expected Frequencies, and Test Statistic
- Assumptions and Conditions checked
- Step 6: Make a Decision (CV and p-value Approach)
- Decision: Reject H0. Market preferences have changed since the advertising campaigns.
Goodness-of-Fit Test for Normal Distribution: Case II (Specified Preference or Proportion)
- Used to check the validity of the assumption of a normal distribution used in many statistical methods.
- Can use frequency distributions, stem-and-leaf displays, histograms, and normal plots.
- Alternatively can conduct a chi-square goodness-of-fit test.
Example 3: Case II (Specified Preference or Proportion)
- Test of Normality: Histogram of 50 gasoline mileages is symmetrical and bell-shaped.
- Sample selected from a normally distributed population.
- Uses chi-square goodness-of-fit test to check normality.
- Step 1: Hypotheses
- H0: The population of all mileages is normally distributed
- HA: The population of all mileages is NOT normally distributed.
- Steps 3 - 4: Observed and Expected Frequencies
- where \bar{x} = 31.56, s = 0.7977. So, for example, P(X < 30.0) = P(\frac{X-\bar{x}}{S} < \frac{30-\bar{x}}{s} ) = P(Z < \frac{30.0-31.56}{0.7977} ) = P(Z < -1.96) \approx .0256
- Assumptions and Conditions checked
- Steps 3 - 4: Observed and Expected Frequencies (Collapsed Categories)
- Step 6: Make a Decision
- Adjusted degrees of freedom for Chi-square is df = k - 1 - m = 5 - 1 - 2 = 2
- Decision: Do NOT reject H0 since \chi^2 = 0.30102 < \chi^2 = .05,df =2 = 5.99147.
- The population of mileages is normally distributed.
16.3 Examining the Residuals
- Used when the null hypothesis is rejected, to discover which values are extraordinary or contribute most to the aggregate chi-square value.
- Examine standardized residuals to compare cells with different counts: \frac{(oi - ei)}{\sqrt{e_i}}
- Standardized residuals from goodness-of-fit tests are z-scores.
Example: Standardized Residuals for Technical Support Data
- Largest value, Sunday, at −3.44, is impressive when viewed as a z-score.
16.4 The Chi-Square Test of Homogeneity or Independence (Contingency Table Analysis)
- Categorical data summarized in a contingency table (cross-tab or pivot table).
- Sample observations cross-classified according to two or more identifiable characteristics.
- Used to determine independence of characteristics of interest and to test for homogeneity.
- Testing for homogeneity is almost the same as testing for independence.
Contingency Table
- Classifies sample observations according to two or more identifiable characteristics.
- Also called a cross-tabulation or pivot table.
- Referred to by row (r) and column (c) dimension, r \times c.
16.4 Hypothesis Tests: Chi-Square Test of Homogeneity or Independence
- Step 1: Hypotheses
- Using the Word “Independence”:
- H0: Variable 1 is independent of Variable 2.
- HA: Variable 1 is NOT independent of Variable 2.
- Using the Word “Association”:
- H0: Variable 1 is NOT associated with Variable 2.
- HA: Variable 1 is associated with Variable 2.
- Step 2: Decision Zone and Type of Test:
- \chi^2 is the lower-case Greek letter Chi.
- Right-tailed Test (0 < \chi^2 < \infty).
- Reject H0 if \chi^2 > \chi^2{cv} where \chi^2{cv} is the critical value from chi-square distribution with (r − 1)(c − 1) degrees of freedom.
- Step 3 and 4: Observed and Expected Frequencies
- Observed Frequencies: Obs(o{ij}) (Property: \sum{i=1}^{r} \sum{j=1}^{c} o{ij} = n)
- Expected Frequencies: Exp(e_{ij}) = \frac{i^{th} \text{row total } \times j^{th} \text{column total}}{\text{grand total or sample size}}
- Property: \sum{i=1}^{r} \sum{j=1}^{c} o{ij} = \sum{i=1}^{r} \sum{j=1}^{c} e{ij} = n
- e{ij} = n p{ij} = n \times pi \times pj
- Step 5: Test Statistic
- \chi^2 = \sum{i=1}^{r} \sum{j=1}^{c} \frac{(o{ij} - e{ij})^2}{e_{ij}}
- Step 6: Make a Decision (Critical Value Approach)
- If test statistic (\chi^2) is located in the critical region, the null hypothesis is rejected.
- If the test statistic (\chi^2) is not located in the critical region, the researcher fails to reject the null hypothesis.
- Rejection Region: Reject H0 if \chi^2 > \chi^2_{cv} (Right-tailed Test).
- Step 6: Make a Decision (p-value Approach)
- p-value: The p-value is the probability of seeing the observed data (or more extreme) given the null hypothesis is true.
- Calculation of p-value: P(\chi^2 > \chi^2_0) (Right-tailed Test).
- Decision Rule:
- If p-value < \alpha, reject H0.
- If p-value \geq \alpha, do not reject H0.
- Assumptions and Conditions:
- Counted Data Condition: The data must be counts for the categories of a categorical variable.
- Independence Assumption: The counts should be independent of each other. Think about whether this is reasonable.
- Randomization Condition: The counted individuals should be a random sample of the population. Guard against auto-correlated samples.
- Sample Size Assumption: We must have enough data for the methods to work.
- Expected Cell Frequency Condition: Expected cell frequency (e{ij}) in each cell or category should be at least 5. If the expected frequencies (e{ij}) are less than 5, adjacent cells need to be meaningfully collapsed until benchmark (e_{ij} \geq 5) is achieved and df should be adjusted accordingly.
Example 1:
- Problem: Is sex of yearbook editor independent of college’s funding source?
- Step 1: Hypotheses
- Using the Word “Independence”:
- H0: Sex of yearbook editor is independent of the college’s funding source.
- HA: Sex of yearbook editor is NOT independent of college’s funding source.
- Using the Word “Association”:
- H0: Sex of yearbook editor is NOT associated with college’s funding source.
- HA: Sex of yearbook editor is associated with college’s funding source.
- Using the Word “Independence”:
- Steps 3 and 4: Observed and Expected Frequencies
- Assumptions and Conditions
- Steps 5 and 6: Test Statistic and Make a Decision (CV Approach)
- Step 6: Make a Decision (p-value Approach)
- Decision: Since p-value < 0.005 < α = .05, we may reject the null hypothesis based on sample evidence and conclude that the sex and source of funding are not independent.