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==pk=ap1 = p2 = \cdots = pk = a, where 'a' is the probability value to test, and 'k' is the number of categories.
    • HA: At least one pipi is not equal to its specified value.
  • Case II: Specified proportions or preference from another known population
    • H0: p1=a1,p2=a2,=pk=akp1 = a1, p2 = a2, \cdots = pk = ak, where a1,a2,,aka1, a2, \cdots , ak are the probability values or relative preferences of each category.
    • HA: At least one pipi is not equal to its specified value.
Step 2: Decision Zone and Type of Test
  • χ2\chi^2 is the test statistic (Chi-square).
  • Right-tailed test (0<χ2<0 < \chi^2 < \infty).
  • Reject H0 if χ2>χ2<em>cv\chi^2 > \chi^2<em>{cv}, where χ2</em>cv\chi^2</em>{cv} is the critical value from the chi-square distribution with (k1)(k - 1) degrees of freedom.
Step 3 and 4: Observed and Expected Frequencies
  • Observed Frequencies: Obs(o<em>i)Obs(o<em>i). Property: </em>i=1koi=n\sum</em>{i=1}^{k} o_i = n
  • Expected Frequencies: Exp(e<em>i)=np</em>iExp(e<em>i) = np</em>i. Property: <em>i=1ko</em>i=<em>i=1ke</em>i=n\sum<em>{i=1}^{k} o</em>i = \sum<em>{i=1}^{k} e</em>i = n, where pip_i are the probabilities of categories specified in H0.
Step 5: Test Statistic
  • χ2=<em>i=1k(o</em>ie<em>i)2e</em>i\chi^2 = \sum<em>{i=1}^{k} \frac{(o</em>i - e<em>i)^2}{e</em>i}
Step 6: Make a Decision (Critical Value Approach)
  • Reject H0 if the test statistic (χ2\chi^2) is in the critical region.
  • Fail to reject H0 if the test statistic (χ2\chi^2) is not in the critical region.
  • Rejection Region: Reject H0 if χ2>χcv2\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(χ2>χ02)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 (e<em>ie<em>i) in each cell/category should be at least 5. If not, collapse adjacent cells meaningfully until e</em>i5e</em>i \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==pk=17p1 = p2 = \cdots = pk = \frac{1}{7}
    • HA: At least one pip_i is not equal to 17\frac{1}{7}.
  • Step 2: Decision Zone and Critical Value
    • χ2<em>α,k1=χ2</em>.05,6=12.5916\chi^2<em>{\alpha,k-1} = \chi^2</em>{.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.15p1 = 0.45, p2 = 0.40, p3 = 0.15
    • HA: At least one pip_i is not equal to its specified value.
  • Step 2: Decision Zone and Critical Value
    • χ2<em>α,k1=χ2</em>.05,2=5.99147\chi^2<em>{\alpha,k-1} = \chi^2</em>{.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 xˉ=31.56,s=0.7977\bar{x} = 31.56, s = 0.7977. So, for example, P(X<30.0)=P(XxˉS<30xˉs)=P(Z<30.031.560.7977)=P(Z<1.96).0256P(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=k1m=512=2df = k - 1 - m = 5 - 1 - 2 = 2
    • Decision: Do NOT reject H0 since χ2=0.30102<χ2=.05,df=2=5.99147\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: (o<em>ie</em>i)ei\frac{(o<em>i - e</em>i)}{\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×cr \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:
    • χ2\chi^2 is the lower-case Greek letter Chi.
    • Right-tailed Test (0<χ2<0 < \chi^2 < \infty).
    • Reject H0 if χ2>χ2<em>cv\chi^2 > \chi^2<em>{cv} where χ2</em>cv\chi^2</em>{cv} is the critical value from chi-square distribution with (r1)(c1)(r − 1)(c − 1) degrees of freedom.
  • Step 3 and 4: Observed and Expected Frequencies
    • Observed Frequencies: Obs(o<em>ij)Obs(o<em>{ij}) (Property: </em>i=1r<em>j=1co</em>ij=n\sum</em>{i=1}^{r} \sum<em>{j=1}^{c} o</em>{ij} = n)
    • Expected Frequencies: Exp(eij)=ithrow total ×jthcolumn totalgrand total or sample sizeExp(e_{ij}) = \frac{i^{th} \text{row total } \times j^{th} \text{column total}}{\text{grand total or sample size}}
    • Property: <em>i=1r</em>j=1co<em>ij=</em>i=1r<em>j=1ce</em>ij=n\sum<em>{i=1}^{r} \sum</em>{j=1}^{c} o<em>{ij} = \sum</em>{i=1}^{r} \sum<em>{j=1}^{c} e</em>{ij} = n
    • e<em>ij=np</em>ij=n×p<em>i×p</em>je<em>{ij} = n p</em>{ij} = n \times p<em>i \times p</em>j
  • Step 5: Test Statistic
    • χ2=<em>i=1r</em>j=1c(o<em>ije</em>ij)2eij\chi^2 = \sum<em>{i=1}^{r} \sum</em>{j=1}^{c} \frac{(o<em>{ij} - e</em>{ij})^2}{e_{ij}}
  • Step 6: Make a Decision (Critical Value Approach)
    • If test statistic (χ2\chi^2) is located in the critical region, the null hypothesis is rejected.
    • If the test statistic (χ2\chi^2) is not located in the critical region, the researcher fails to reject the null hypothesis.
    • Rejection Region: Reject H0 if χ2>χcv2\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(χ2>χ02)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<em>ije<em>{ij}) in each cell or category should be at least 5. If the expected frequencies (e</em>ije</em>{ij}) are less than 5, adjacent cells need to be meaningfully collapsed until benchmark (eij5e_{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.
  • 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.