The chi-square test of independence is used to analyze the frequency table (i.e. contengency table) formed by two categorical variables. The chi-square test evaluates whether there is a significant association between the categories of the two variables
Chi-square test examines whether rows and columns of a contingency table are statistically significantly associated.
Null hypothesis (H0): the row and the column variables of the contingency table are independent. Alternative hypothesis (H1): row and column variables are dependent
Example 1
Determine whether passing rate is independent from gender
# create a matrix of past/fail tally by gender (malefemal)dt <-matrix(c(45,5,15,15), nrow=2, byrow=T)rownames(dt) <-c("female", "male") # add row namescolnames(dt) <-c("pass", "fail") # add column namesdt # display matrix values
pass fail
female 45 5
male 15 15
chisq <-chisq.test(dt) # run chi-square testchisq$p.value # check p.value if significant
[1] 0.0001889622
Example 2
Determine whether the roles of husbands and wives are independent of household chores