Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3-way Chi-Squared Test in R

I have categorical data as follows:

gender age_group diagnosis
male     young    x
female   child    y
female   adult    x
male     old      z

gender, age_group and diagnosis have 2, 4 and 3 levels respectively. 

I want to conduct a Chi-Squared Test to see the relationship between two categories. How could I do that in R

like image 543
Günal Avatar asked Sep 26 '22 16:09

Günal


1 Answers

The appropriate test for three dimensional contigency tables is the Cochran-Mantel-Haenszel test I believe. In order to use it, you will need to convert your data into a three dimensional array, and make sure that each possible stratum in your resulting contigency table has a frequency > 1.

# convert data to contigency table
df <- table(data)

# run test
mantelhaen.test(df)
like image 88
mtoto Avatar answered Sep 28 '22 05:09

mtoto