Corey
by Corey
1 min read

Categories

  • articles

Tags

  • Bioinformatics
  • R

The medical statistical data can be divided into numerical and categorical types. When there is a need to find out the association between numerical variables (age, weight), the t-test is fine. When we need to determine the association between categorical variables, like whether the gender is correlated with smoking status (example data in the contingency table below), we could use Chi-Squared test if the data is fit in with the prerequisite. Otherwise, we should use Fisher’s Exact Test.

Gender Smoker Non-Smoker
Male 20 3
Female 8 22

The test statistic for the Chi-Square Test of independence is denoted as , and is computed as:

where is the observed cell count in the row and column of the table is the expected cell count in the row and column of the table, computed as

The condition is based on the N and :

  1. N ≥ 40 and ≥ 5. Use the Chi-Squared Test.
  2. N ≥ 40 and 1 ≤ ≤ 5. Use the Chi-Squared Test with correction (chisq.test with parameter correct=TRUE).
  3. N < 40 or < 1 or p-value close to 0.05. Can not use the Chi-Squared Test, should use the Fisher’s Exact Test.

To our smoking problem, we first check the total sample size N, N = 20 + 3 + 8 + 22 = 53 > 40. Second, we check each , each cell of is described in the table and > 5. Therefore, we could use Chi-Squared Test and find out the gender is correlated with the smoking status based on our data (p-value = 4.501e-05 « 0.05).

Smoker Non-Smoker
Male 12.15 10.85
Female 15.85 14.15
############input############
dat <- c(20,8,3,22)
chisq.test(matrix(dat,nrow=2,ncol=2))

############output############
	Pearson's Chi-squared test with Yates' continuity correction

data:  matrix(dat, nrow = 2, ncol = 2)
X-squared = 16.647, df = 1, p-value = 4.501e-05

References

  1. CHI-SQUARE TEST OF INDEPENDENCE