我有如下分类数据:
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.
我想进行一个卡方检验
来查看两个类别之间的关系。我怎么能在 R 中做到这一点
最佳答案
三维列联表的适当测试是 Cochran-Mantel-Haenszel test我相信。为了使用它,您需要将数据转换为三维数组,并确保生成的列联表中每个可能的 stratum
的频率 > 1。
# convert data to contigency table
df <- table(data)
# run test
mantelhaen.test(df)
关于r - R 中的三向卡方检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34750987/