0:00 / 0:00

Types of Chi Square Tests



Chi-square tests are used for statistical inference on categorical data.

Examples of categorical variables
  • Choice of major (English, Business, Biology... )
  • Brand name (Toyota, BMW, Tesla... )
  • Country (USA, Colombia, Philippines... )
  • Flight status (On time, delayed, cancelled... )
  • Day of the week (Monday, Tuesday, Wednesday... )
PAGE BREAK

Chi-Square: Goodness of Fit

Use the Goodness of Fit test when you want to see if the population with an unknown distribution "fits" a known distribution. In this case, we are dealing with a single outcome of an experiment from a single population. Here, we are typically testing to see if the population is uniform (all outcomes occur with equal frequency).

Examples
  • Do employees call in "sick" more often on certain days of the week?
  • Do hotel guests use the middle door more often than the other doors at the entrance?
  • Do people use certain fingers to press the elevator button more often than other fingers?

Illustration:






Hypotheses:

Ho:H_o: The population fits the given distribution.
Ha:H_a: The population does not fit the given distribution.

PAGE BREAK

Chi-Square: Test of Independence

Use the Test of Independence when you want to see if two categorical variables are independent (has no association) or dependent (has an association). In this case, we are dealing with two qualitative survey questions or experiments, which will entail a contingency table (minimum 2x2).

Examples
  • Is there an association between an actor's ethnicity and the roles they play on television?
  • Is there an association between a student's gender and what program they major in?
  • Do certain brands appeal more to younger consumers while other brands appeal more to older consumers?


Illustration:







Hypotheses:

Ho:H_o: The two categorical variables are independent. (There is no association.)
Ha:H_a: The two categorical variables are not independent. (There is an association.)

0:00 / 0:00

Chi-Square Test for "Goodness of Fit"


A Chi-square X2X^2 Goodness of Fit Test compares the observed frequencies for a categorical variable and the expected frequencies to see if there are any discrepancies between them. If there is little or no discrepancy, then we conclude that the expected frequencies “fit” the observed frequencies; hence, “goodness of fit”.
Example

I toss the die 60 times.

Observed results:

Is this a fair die?

Of course, it is. It is 100% fair. If we toss the die 60 times, we expect to get each number 10 times:
What we observe above is exactly that.

PAGE BREAK

In real life, we don’t get results that perfect; there will be some discrepancy. If there is little discrepancy, then we can still conclude that the die is fair. If the discrepancy is statistically significant discrepancy – that is, the difference is not due to chance – then we conclude that the die is not fair. How do we formally test this?

X2=(obsExp)2ExpX^2=\sum_{ }^{ }\frac{\left(obs-Exp\right)^2}{Exp}
where we take the sum of all the cells in the table.
df=k1df=k-1
k=k= # of possible outcomes or groups within a category

PAGE BREAK

Hypotheses:

Ho=p1=p2=p3=.....=pn=1nH_o=p_1=p_2=p_3=.....=p_n=\frac{1}{n}

Ha=at least one p1 is not 1nH_a=at\ least\ one\ p_1\ is\ not\ \frac{1}{n}



PAGE BREAK

0:00 / 0:00

Example: Chi-Square Test for "Goodness of Fit"


Suppose we toss a die 60 times. This time, the result is this:


At the 5% significance level, is this a fair die?

Ho=p1=p2=p3=p4=p5=p6=16H_o=p_1=p_2=p_3=p_4=p_5=p_6=\frac{1}{6} “The die is fair.”
(The observed sample frequencies do not differ significantly from expected frequencies.)

Ha=at least one pi is not 16H_a=at\ least\ one\ p_i\ is\ not\ \frac{1}{6} “The die is not fair.”
(The observed sample frequencies differ significantly from expected frequencies.)

(a) Calculate the Chi-square test statistic.

X2=(ObsExp)2ExpX^2=\sum_{ }^{ }\frac{\left(Obs-Exp\right)^2}{Exp}

=(810)210+(1210)210+(710)210+(1110)210+(910)210+(1310)210=\frac{\left(8-10\right)^2}{10}+\frac{\left(12-10\right)^2}{10}+\frac{\left(7-10\right)^2}{10}+\frac{\left(11-10\right)^2}{10}+\frac{\left(9-10\right)^2}{10}+\frac{\left(13-10\right)^2}{10}

=0.4+0.4+0.9+0.1+0.1+0.9=0.4+0.4+0.9+0.1+0.1+0.9

=2.8=2.8

(b) What is the degrees of freedom?
df=n1=61=5df=n-1=6-1=5

PAGE BREAK
(c) At the 5% significance level, what is the critical value for the Chi-square test? [Use the Chi-square table]

Critical value CV(0.05,5) =11.071=11.071 (using Chi-square table)
To reject Ho, the Chi-square test statistic must be greater than the CV (11.071).


PAGE BREAK
Illustration:



(d) How do you conclude?

Since the test-statistic (2.8) is less than the critical value (11.071), we fail to reject HoH_oand conclude that there is no evidence that this die is not fair.

Alternatively, for X2=2.8X^2=2.8, the p-value is between 0.10 and 0.90, which is greater than 0.10 (using the Chi-square table).

[Using software, the exact p-value is 0.731.]

Since the p-value is greater than α=0.05\alpha=0.05, we fail to reject HoH_o and conclude that there is no evidence that this die is not fair. This is the same conclusion as above.

PAGE BREAK

Suppose we toss a coin 100 times. Tails showed up more times than expected and heads showed up few time than expected.




(i) What is the Chi-square test statistic? [Provide answer with 2 decimal places.]
0:00 / 0:00

Chi-Square Test of Independence

A Chi-square X2X^2 Test of Independence are used to determine if there is a significant association between two categorical variables from a single population.

Examples
  • Critters Bookstore is wondering if women more inclined to buy fantasy novels, whereas men are more inclined to buy non-fiction.
  • Is area of study independent of gender?
  • Are people in the South more inclined to vote Republican?
  • Do people in Brazil have more positive views of plastic surgery than people in Norway?

PAGE BREAK

Limitation of Chi-Square Test of Independence

1. The Chi-square test is only meant to test the independence of a distribution of data.
  • It will not tell you anything about the relationship between the variables.
  • For example, the Chi-square test will tell you that region is associated with party affiliation but it will not tell you how much more likely someone from the South will vote Republican than someone from the West.
  • The Chi-square test statistic is always positive so the test statistic itself does not tell you if there is a negative association between two variables.

2. Both categories must be categorical data.
  • You cannot use quantitative data.
  • Suppose you want to test for independence between age and political party. Age is a quantitative variable so you cannot use that to perform Chi-square.
  • However, you could convert age from quantitate to categorical: [young adult, middle age adult, senior]. Of course, your results vary based on where you cut off between the groups.

3. The variables you use must be mutually exclusive.
  • There cannot be participation in more than one category.
  • The data from all the cells must add up to the total count, and no item should be double-counted.
  • For example, “birthplace” – one cannot be born in multiple countries.

PAGE BREAK
To determine if there is a significant difference between two variables, we must calculate the expected frequencies and the observed frequencies in one or more categories.
Hypotheses:

Ho:H_o:There is no relationship (association) between the variables. (They are independent.)
Ha:H_a:There is a relationship (association) between the variables. (They are not independent.)


Wize Tip
The hypotheses in Chi-square tests are only words and, like all hypotheses, are statements about the population.

Test-statistic:

X2=(ObsExp)2Exp=(OijEij)2Eij\displaystyle\boxed{{X^2=\sum_{ }^{ }\frac{\left(Obs-Exp\right)^2}{Exp}=\sum_{ }^{ }\frac{\left(O_{ij}-E_{ij}\right)^2}{E_{ij}}}}


Watch Out!
Warning: Do not take the square root of χ2\chi ^2.

The degrees of freedom df=(r1)(c1)df=(r-1)(c-1)

rr = # of rows
cc = # of columns
PAGE BREAK
This is how you calculate the expected frequency, Ei:E_i:

Eij=(ith Row Total)(jth Column Total)(Overall Total)\displaystyle\boxed{{E_{ij}=\frac{\left(i^{th\ }Row\ Total\right)\left(j^{th\ }Column\ Total\right)}{\left(Overall\ Total\right)}}}

Example


A: (20)(10)50=4A:\ \frac{\left(20\right)\left(10\right)}{50}=4

B:(20)(40)50=16B:\frac{\left(20\right)\left(40\right)}{50}=16

C: (30)(10)50=6C:\ \frac{\left(30\right)\left(10\right)}{50}=6

D: (30)(40)50=24D:\ \frac{\left(30\right)\left(40\right)}{50}=24

0:00 / 0:00

Example: Chi-Square Test for Independence


A research company wishes to see if men and women are drawn to certain types of wine. They randomly select 50 men and 50 women for a blind taste test. Each subject was offered 3 types of wine: Pinot Noir, Merlot, and Shiraz. They were then asked to pick the one they like most. Results:



Ho:H_o: There is no relationship (association) between gender and wine preference.
Ha:H_a: There is a relationship (association) between gender and wine preference.

(a) Calculate the expected cells:




PAGE BREAK
(b) Find the Chi-square test statistic and its p-value (using Chi-square table).

X2=(ObsExp)2Exp=(OiEi)2Ei\displaystyle{X^2=\sum_{ }^{ }\frac{\left(Obs-Exp\right)^2}{Exp}=\sum_{ }^{ }\frac{\left(O_i-E_i\right)^2}{E_i}}


X2=(915)215+(1415)215+(2720)220+(2115)215+(1615)215+(1320)220X^2=\frac{\left(9-15\right)^2}{15}+\frac{\left(14-15\right)^2}{15}+\frac{\left(27-20\right)^2}{20}+\frac{\left(21-15\right)^2}{15}+\frac{\left(16-15\right)^2}{15}+\frac{\left(13-20\right)^2}{20}

=2.4+0.067+2.45+2.4+0.067+2.45=2.4+0.067+2.45+2.4+0.067+2.45

=9.83=9.83

df=(r1)(c1)=(21)(31)=2df=\left(r-1\right)\left(c-1\right)=\left(2-1\right)\left(3-1\right)=2

We have X2=9.83X^2=9.83 and df=2df=2. Looking at the Chi Square Table, we see that our p-value is less than 0.01. [Using software, the exact p-value is 0.0073.]


PAGE BREAK

(c) Draw your conclusion.

We reject/fail to reject Ho;H_o;there is/is no evidence of an association between gender and wine preference.

Reject; there is an association

Pick Meow is a shelter for cats in California. At the 1% significance level, is there a relationship between the ages of cats and whether they get adopted or not? Here are the results based on 100 randomly selected cats:


(a) Which of the following is the correct alternative hypothesis HaH_a? (Check all that applies.)
0:00 / 0:00

More on Chi-Square Tests

Expected values should not be too small

Small expected values could lead to misleading results.

Example

J. Kidding sells her romance novels online and at Chapters. She wishes to see if there is an association between gender and method of purchase of her books. She randomly samples 20 men and 200 women.

Results:

We calculate the expected values:

Notice that one cell in the expected value table is very small: {Men, Buy from Store} = 3.64.

See what happens to the X2:X^2:

X2=(1216.36)216.36+(83.64)23.64+(168152.73)2152.73+(3236.36)236.36\displaystyle{X^2=\frac{\left(12-16.36\right)^2}{16.36}+\frac{\left(8-3.64\right)^2}{3.64}+\frac{\left(168-152.73\right)^2}{152.73}+\frac{\left(32-36.36\right)^2}{36.36}}

=1.162+5.222+1.527+0.523=1.162+5.222+1.527+0.523

=8.434=8.434

  • As you can see, the {Men, Buy from Store} cell contributes to almost two-third of the X2X^2 score!
  • This is because its expected value cell is very small. Small cells in the expected frequency table contribute to a disproportionately large amount to the test statistic.
  • This could increase the probability of committing a Type I error!
PAGE BREAK

The Chi-square test works best when each of the expected cell frequencies are at least 5


Ei5E_i\ge5

How can we try to fix small expected frequency cells?

1) Increase the sample size and hope that all the expected frequency cells become larger than 5. Note: the sample must still be randomly drawn - you cannot "cherry pick" to target small expected frequency cells.

2) Combine categories... only if it makes sense. For example, it would make little sense to combine wombats and humans into one category (but it depends on the study). Also, if your row or column variables only have 2 categories, then combining them into one would make the degrees of freedom equal to 0, which wouldn't make your Chi-square test work.

Suppose that we have 4 categories A, B, C and D and while calculating the expected frequencies we have:

Category Expected Frequency
A 4
B 3
C 7
D 8

Cells with expected frequencies below 5 could be merged together (collapsed) for the chi-square test to be valid.

In this case we would use 3 instead of 4 categories as follows:

Category Expected Frequency
A,B 7
C 7
D 8


You then proceed as usual with new degrees of freedom df=31=2df=3 - 1 = 2