lecture 16 - chi-square and contingency squares Flashcards
Chi-squared and contingency tables
mainly used when have 2 nominal variables
- Contingency tables - independence of two nominal variables
- Can also use chi-square in the “Goodness-of-fit Test” (but not on the current course)
- difference between categories of a single nominal variable
A two-by-two contingency table
Two lecturers (Jones & Brown) each offered two courses in one year. If the popularity of the lecturers is independent of the popularity of the courses then:
A - any difference in the popularity of the courses should be the same for both lecturers, i.e. J1 - J2 = B1 - B2.
B - any difference in the popularity of the lecturers should be the same for both courses, i.e. J1 – B1 = J2 - B2
1st nominal variable is the lecturer
2nd nominal variable is the course
we are asking if the variables are indepednet so what happens on one variable doesnt affect what happens on the other 50. if there is a difference in popularity of courses that difference is the same for both lecturers = independent
examples of no contingency between two nominal variables
1 - no matter what course jones is more popular - but variables are independent as level of popularity is same for both courses
2 - jones and brown are some popularity
course 2 more popular than course 1
variables - if dependent as difference is same for both
examples of a contingency between two nominal variables - not independent
1 - the popularity of the course reverses as you swap between lecturers eg each lecture has a speciality in each course and have same popularity
A two-by-two contingency table
are these variables independent of each other
Two lecturers (Jones & Brown) each offered two courses in one year. The numbers of students signing up to the two courses seemed to be neither a function of the popularity of Jones or Brown, nor the content of the course, but which course Jones and Brown taught
100 on course 1
200 on course 2
measure their popularity by asking how many people sign up to go to each lecture as a function of each course assuming every student can only sign up to one course
Does the popularity of Jones and Brown
depend on which course they teach?
course 2 - jones and brown are equally popular
course 1 - brown has more people than jones
variables are not entirely independent. the difference in the popularity of the lectures is not exactly the same for both courses
we need to know what would have happened by chance
Observed frequencies and generating expected frequencies
H0 - attendance does not depend on who gives the course - null hypothesis
jones
course 1 - 20
2 - 100
total - 120
brown
1 - 80
2 - 100
total - 180
row totals
1 - 100 (1/3 of total)
2 - 200 (2/3 of total)
total - 300 (total)
if H0 is true
1/3 of Jones’ total students should attend course 1
2/3 of Jones’ total students should attend course 2
1/3 of Brown’s total students should attend course 1
2/3 of Brown’s total students should attend course 2
expected frequencies
jones
1 - 1/3 x 120 = 40
2 - 2/3 x 120 = 80
total = 120
brown
1 - 1/3 x 180 = 60
2 - 2/3 x 180 = 120
total = 180
row totals
1 - 100 1/3
2 - 200 2/3
totals - 300 total
if Jones and brown popularity is independent of corse one and of course two popularity
what we expected by chance if null hypothesis was true
chi-squared
Clearly observed & expected differ. Evaluate this as (O – E). But, squaring (O – E) gives “sensible” measure of departure.
Otherwise S (O – E) = 0 in all cases.
But “importance” of (O – E) depends on how large it is relative to E. So, also need to scale (O – E)2 by size of expected frequency. more informative than the absolute difference
increase sample
1003 students
differences go away so we need to scale our measure of difference from chance as a function of how big the things we expect overall are.
the chi-square c^2 statistic
X^2 = ∑ (0-E)^2/ E
0 has to be a whole number
E expected value for that cell doesnt have to be a whole number
- O = Observed frequency
- E = Expected frequency
- (O – E)
- Measures departure of O from E.
- (O – E)2
- Prevents departures above & below cancelling out.
- Dividing by E
Scales the degree of departure between O – E.
how to compute Is in notes
Testing significance
- Degrees-of-freedom
(No. of rows – 1) ´ (No. of columns – 1)
df = (2 - 1) ´ (2 – 1) = 1 - Critical value = 3.84
“Lecturer popularity depends on the course they teach
(c2(1) = 25, p < .05).”
the bigger the difference from chance the bigger chi-squared will be
if null hypothesis is true we would expect a small value of chi-squared
we see if the chi-squared value Is larger than critical value
if it is we reject null hypothesis
if null hypothesis is true you expect the difference in one variable to be the same as the difference in the other variable
Assumptions of the x^2 test - health warning
- Each observation must be independent of the others.
- E.g. one observation each from a number of subjects OR a number of observations from a single subject.
- Data must be frequencies (i.e. counts of observations) NOT percentages or proportions.
- Expected frequencies should be 5 or more.
- Not a hard-and-fast rule. But tables of critical values inaccurate when expected frequencies low - especially when total number of observations low (less than 20) and/or df = 1. the lower your expected values are the less accurate your P value is.
- Best to be careful when such conditions are met and consider an alternative test (or larger sample).
You may see references to “Yates Correction” for when df =1. It is covered in the text, but don’t worry too much (it just makes the test a little more conservative) it doesnt correct the problem
General rule for expected frequencies
- Expected frequencies for each cell is given by:
E = Row Total ´ Column Total / Overall Total
Note: can have as many categories per factor as you like.
works for nay table
row total for row cell is in and column total for column cell is in - picture in notes