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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With